I'm playing around with ConditionalWeakTable
for the first time, so I figured I'd run the example from the docs.
This doesn't compile out of the box... I had to change this:
else if (cwt.TryGetValue(wr2.Target, out data))
...to this:
else if (cwt.TryGetValue((ManagedClass)wr2.Target, out data))
Even then though, my console spits out Data created at 07/03/2023 12:56:02
... which is not what the docs say it should be doing:
// The example displays the following output:
// No strong reference to mc2 exists.
This is my project file (the only other file in the solution, a part from the example code):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>10.0</LangVersion>
<OutputType>Exe</OutputType>
</PropertyGroup>
</Project>
I did try targeting netcore 3.1 to see if that would make a difference but still no joy.
Am I missing something really basic here?