container icon indicating copy to clipboard operation
container copied to clipboard

ExternallyControlledLifetimeManager returns null instead of LifetimeManager.NoValue

Open ENikS opened this issue 6 years ago • 0 comments

Description

When object referenced by ExternallyControlledLifetimeManager goes out of scope and is collected by the Garbage Collector the manager returns null instead of LifetimeManager.NoValue.

To Reproduce

        [TestMethod]
        public void CollectedTest()
        {
            // Arrange
            var instance = new object();

            TestManager.SetValue(instance, LifetimeContainer);
            instance = TestManager.GetValue(LifetimeContainer);
            
            Assert.AreNotSame(LifetimeManager.NoValue, instance);


            // Act
            instance = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();


            // Validate
            var after = TestManager.GetValue(LifetimeContainer); <-- returns null
            Assert.AreSame(LifetimeManager.NoValue, after);
        }

ENikS avatar Jun 06 '20 01:06 ENikS