Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. WeakReference broken in .NET5

WeakReference broken in .NET5

Scheduled Pinned Locked Moved The Lounge
csharpcomquestion
11 Posts 7 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Super Lloyd
    wrote on last edited by
    #1

    Back to home project after.. a long break! (hence my recent numerous programming posts) :omg: :-D Upgrading my utilities to .NET5, running the tests and then this test broke.... var wo = new WeakReference(new object()); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); Assert.False(wo.IsAlive); Wow really? Floored :~:confused: :omg: Work with .NET4.7.2, fails with .NET5 Out of curiosity tried .NET6 (preview). Work again in .NET6, phew.. :rose: :doh: EDIT After some reflection, it's most likely GC.Collect() that is broken in .NET5.... little harm done...

    A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

    R Richard DeemingR B L 4 Replies Last reply
    0
    • S Super Lloyd

      Back to home project after.. a long break! (hence my recent numerous programming posts) :omg: :-D Upgrading my utilities to .NET5, running the tests and then this test broke.... var wo = new WeakReference(new object()); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); Assert.False(wo.IsAlive); Wow really? Floored :~:confused: :omg: Work with .NET4.7.2, fails with .NET5 Out of curiosity tried .NET6 (preview). Work again in .NET6, phew.. :rose: :doh: EDIT After some reflection, it's most likely GC.Collect() that is broken in .NET5.... little harm done...

      A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

      R Offline
      R Offline
      RickZeeland
      wrote on last edited by
      #2

      That was to be expected, they are not called "weak" for nothing :-\

      S 1 Reply Last reply
      0
      • R RickZeeland

        That was to be expected, they are not called "weak" for nothing :-\

        S Offline
        S Offline
        Super Lloyd
        wrote on last edited by
        #3

        sick burn! :laugh:

        A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

        1 Reply Last reply
        0
        • S Super Lloyd

          Back to home project after.. a long break! (hence my recent numerous programming posts) :omg: :-D Upgrading my utilities to .NET5, running the tests and then this test broke.... var wo = new WeakReference(new object()); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); Assert.False(wo.IsAlive); Wow really? Floored :~:confused: :omg: Work with .NET4.7.2, fails with .NET5 Out of curiosity tried .NET6 (preview). Work again in .NET6, phew.. :rose: :doh: EDIT After some reflection, it's most likely GC.Collect() that is broken in .NET5.... little harm done...

          A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          Are you running this in a debug build? If so, try a release build instead. Using LINQPad 6, I can reproduce the behaviour you're setting in a debug build for .NET 5.10; toggling the "o+" switch at the bottom-right to switch to release mode returns the behaviour to normal.


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          H S 2 Replies Last reply
          0
          • Richard DeemingR Richard Deeming

            Are you running this in a debug build? If so, try a release build instead. Using LINQPad 6, I can reproduce the behaviour you're setting in a debug build for .NET 5.10; toggling the "o+" switch at the bottom-right to switch to release mode returns the behaviour to normal.


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            H Offline
            H Offline
            honey the codewitch
            wrote on last edited by
            #5

            Nice catch

            Real programmers use butterflies

            1 Reply Last reply
            0
            • Richard DeemingR Richard Deeming

              Are you running this in a debug build? If so, try a release build instead. Using LINQPad 6, I can reproduce the behaviour you're setting in a debug build for .NET 5.10; toggling the "o+" switch at the bottom-right to switch to release mode returns the behaviour to normal.


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              S Offline
              S Offline
              Super Lloyd
              wrote on last edited by
              #6

              You know what? It indeed work in Release build. First time I see something working significantly differently between build and release in C# for a while I reckon! :O

              A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

              L 1 Reply Last reply
              0
              • S Super Lloyd

                Back to home project after.. a long break! (hence my recent numerous programming posts) :omg: :-D Upgrading my utilities to .NET5, running the tests and then this test broke.... var wo = new WeakReference(new object()); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); Assert.False(wo.IsAlive); Wow really? Floored :~:confused: :omg: Work with .NET4.7.2, fails with .NET5 Out of curiosity tried .NET6 (preview). Work again in .NET6, phew.. :rose: :doh: EDIT After some reflection, it's most likely GC.Collect() that is broken in .NET5.... little harm done...

                A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                B Offline
                B Offline
                BillWoodruff
                wrote on last edited by
                #7

                Super Lloyd wrote:

                hence my recent numerous programming posts

                You auditioning for the role that Honey...Witch played until recently ? :omg: Go for it :-D

                «The mind is not a vessel to be filled but a fire to be kindled» Plutarch

                S 1 Reply Last reply
                0
                • B BillWoodruff

                  Super Lloyd wrote:

                  hence my recent numerous programming posts

                  You auditioning for the role that Honey...Witch played until recently ? :omg: Go for it :-D

                  «The mind is not a vessel to be filled but a fire to be kindled» Plutarch

                  S Offline
                  S Offline
                  Super Lloyd
                  wrote on last edited by
                  #8

                  competition is fierce! :D

                  A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                  1 Reply Last reply
                  0
                  • S Super Lloyd

                    You know what? It indeed work in Release build. First time I see something working significantly differently between build and release in C# for a while I reckon! :O

                    A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                    L Offline
                    L Offline
                    lmoelleb
                    wrote on last edited by
                    #9

                    For anyone wondering why... this is not because the release build is optimized - it is because extra IL is being injected into the debug build for debugging usability reasons. If you have:

                    {
                    var thing1 = new thing1();
                    // Do things to thing1
                    var thing2 = new thing2(thing1);
                    // Do things to thing2
                    // "Breakpoint here"
                    }

                    On the breakpoint, you would expect to be able to see thing1. But as the garbage collector no longer see any reference to thing1 it can be collected as soon as the constructor of thing2 is done with it (the constructor does not even have to return). To avoid this the compiler will inject IL to keep the variable "used" until he variable is out of scope seen from C# (or whatever language) - so the closing }. Not sure how much "optimization" is really done in release. Maybe it is really just a "stop bloating" option - at least when I had to look I found release IL is a lot easier to read than debug IL :)

                    1 Reply Last reply
                    0
                    • S Super Lloyd

                      Back to home project after.. a long break! (hence my recent numerous programming posts) :omg: :-D Upgrading my utilities to .NET5, running the tests and then this test broke.... var wo = new WeakReference(new object()); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); Assert.False(wo.IsAlive); Wow really? Floored :~:confused: :omg: Work with .NET4.7.2, fails with .NET5 Out of curiosity tried .NET6 (preview). Work again in .NET6, phew.. :rose: :doh: EDIT After some reflection, it's most likely GC.Collect() that is broken in .NET5.... little harm done...

                      A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                      L Offline
                      L Offline
                      Luca Leonardo Scorcia
                      wrote on last edited by
                      #10

                      There's so many bugs in .net5 that it's not funny anymore. This is the last one we found that affects us, in something as basic as Directory.GetFiles: .Net Core Directory.GetFiles() operates webDav path · Issue #46723 · dotnet/runtime · GitHub[^]. Still untriaged after eight months. "Move fast, break things" has its place. The basic runtime for a lot of business applications in the world is not that place.

                      Luca The Price of Freedom is Eternal Vigilance. -- Wing Commander IV En Það Besta Sem Guð Hefur Skapað, Er Nýr Dagur. (But the best thing God has created, is a New Day.) -- Sigur Ròs - Viðrar vel til loftárása

                      S 1 Reply Last reply
                      0
                      • L Luca Leonardo Scorcia

                        There's so many bugs in .net5 that it's not funny anymore. This is the last one we found that affects us, in something as basic as Directory.GetFiles: .Net Core Directory.GetFiles() operates webDav path · Issue #46723 · dotnet/runtime · GitHub[^]. Still untriaged after eight months. "Move fast, break things" has its place. The basic runtime for a lot of business applications in the world is not that place.

                        Luca The Price of Freedom is Eternal Vigilance. -- Wing Commander IV En Það Besta Sem Guð Hefur Skapað, Er Nýr Dagur. (But the best thing God has created, is a New Day.) -- Sigur Ròs - Viðrar vel til loftárása

                        S Offline
                        S Offline
                        Super Lloyd
                        wrote on last edited by
                        #11

                        Damn....

                        A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups