title: Why is my .NET framework app looking for the wrong version of the .NET core/standard platform extension assembly, and how do I fix it?
body: <p>From <a href="https://apisof.net/catalog/Microsoft.Win32.Registry" rel="noreferrer">the .NET APIs catalog</a>, I understand that the <code>Microsoft.Win32.Registry</code> class is declared in the <code>.NET Standard + Platform Extensions 2.0</code> package in an assembly <code>Microsoft.Win32.Registry, Version=4.1.1.0, PublicKeyToken=b03f5f7f11d50a3a</code>. </p>
  
  <p><a href="https://i.stack.imgur.com/66cIi.png" rel="noreferrer"><img src="https://i.stack.imgur.com/66cIi.png" alt="enter image description here"></a></p>
  
  <p>I've created a class library which targets .NET Standard 2.0, and here's a simple class:</p>
  
  <pre><code>public class NetStandardClass
  {
      public string GetHklmRegValue()
      {
          var lmKey = Microsoft.Win32.Registry.LocalMachine;
          var softwareKey = lmKey.OpenSubKey("Software"); 
          return "value";
      }
  }
  </code></pre>
  
  <p>I've created a .NET Framework 4.7.2 console application which references my above class library:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          string value = new ClassLibrary2.NetStandardClass().GetHklmRegValue();
      }
  }
  </code></pre>
  
  <p>When I run this on Windows, this throws a run-time exception:</p>
  
  <blockquote>
    <p>System.IO.FileNotFoundException: 'Could not load file or assembly
    'Microsoft.Win32.Registry, Version=<strong>4.1.3.0</strong>, Culture=neutral,
    PublicKeyToken=<strong>b03f5f7f11d50a3a</strong>' or one of its dependencies. The
    system cannot find the file specified.'</p>
  </blockquote>
  
  <p>Based on <a href="https://github.com/dotnet/standard/issues/481" rel="noreferrer">what I've read</a>, having assembly load issues in this scenario is somewhat of a known issue.  The prescribed work-around is to enable <a href="https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/how-to-enable-and-disable-automatic-binding-redirection" rel="noreferrer">automatic binding redirects</a> and make sure my .NET Framework application is using <code>PackageReference</code> rather than <code>Project.Config</code>.  I have done this with my projects from which I shared the above code, but I'm still getting the error.  What confuses me most, though, is that the error is indicating the <code>.NET Core</code> / <code>.NET Core + Platform Extensions</code> assembly (<strong>Version=4.1.3.0, PublicKeyToken=b03f5f7f11d50a3a</strong>) rather than the .NET Standard (<strong>Version=4.1.1.0, PublicKeyToken=b03f5f7f11d50a3a</strong>) or .NET Framework (<strong>Version=4.0.0.0, PublicKeyToken=b77a5c561934e089</strong>) versions from the APIs catalog:</p>
  
  <p><a href="https://i.stack.imgur.com/79c4c.png" rel="noreferrer"><img src="https://i.stack.imgur.com/79c4c.png" alt="enter image description here"></a></p>
  
  <p>This is further corroborated by the Microsoft.Win32.Registry.DLL that is in the output directory:</p>
  
  <p><a href="https://i.stack.imgur.com/ko6Oi.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ko6Oi.png" alt="enter image description here"></a></p>
  
  <p>Based on <a href="https://stackoverflow.com/questions/43837638/how-to-get-net-core-projects-to-copy-nuget-references-to-build-output">further reading</a>, I can make a little progress by doing either of the following:</p>
  
  <ul>
  <li>Add <code>&lt;CopyLocalLockFileAssemblies&gt;true&lt;/CopyLocalLockFileAssemblies&gt;</code> to the .NET Standard class library proj file</li>
  </ul>
  
  <p>-- or --</p>
  
  <ul>
  <li>Add the <code>Microsoft.Win32.Registry</code> NuGet package <em>directly</em> to my .NET Framework console application.</li>
  </ul>
  
  <p>Either of these results in loading <em>some version</em> of the assembly, but then I get some odd behavior: I get an NRE for the <code>LocalMachine</code> property, which shouldn't happen.</p>
  
  <p><a href="https://i.stack.imgur.com/98zDg.png" rel="noreferrer"><img src="https://i.stack.imgur.com/98zDg.png" alt="enter image description here"></a></p>
  
  <hr>
  
  <p>So here are the questions:</p>
  
  <p>1.) Since my project is a .NET Framework application, why is it not using the <code>Microsoft.Win32.Registry</code> class in the .NET Framework API, specifically the <code>mscorlib</code> assembly that the same APIs catalog refers to?</p>
  
  <p><a href="https://i.stack.imgur.com/Udnlk.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Udnlk.png" alt="enter image description here"></a></p>
  
  <p>2.) Why isn't the "work around" in the GitHub post not working for me?</p>
  
  <p>3.) Why is it seemingly looking for the .NET Core / ... extensions version of the assembly?</p>
  
  <p>4.) Why when I explicitly export the NuGet <code>Microsoft.Win32.Registry</code> assembly in the .NET Standard class library or directly reference the package in the .NET Framework console application does it result in the strange behavior where <code>Microsoft.Win32.Registry.LocalMachine</code> is null, which should never be the case on a Windows machine?</p>