title: C#: finding path to PresentationCore.dll (and other assemblies) in the GAC
body: <p>I need to reference various assemblies in a <code>CSharpCodeProvider</code> via calling <code>ReferencedAssemblies.Add</code>.</p>
  <p>For some assemblies, it is sufficient to simply pass the assembly name - for example <code>ReferencedAssemblies.Add(&quot;System.dll&quot;)</code>.</p>
  <p>However, <code>PresentationCore.dll</code> is one of those where a full path to the assembly is required - which I may not necessarily know on the target machine.</p>
  <h2>Question:</h2>
  <blockquote>
  <p>How can I locate the definitive path to the (latest?) respective assembly - say, in the GAC?</p>
  <p>Ideally, the solution would not only work for <code>PresentationCore.dll</code>, but also other assemblies such as <code>PresentationFramework.dll</code>, <code>System.Xaml.dll</code> or <code>System.Windows.Forms</code>.</p>
  </blockquote>
  <h3>Sources that didn't yield the intended results:</h3>
  <ul>
  <li><a href="https://social.msdn.microsoft.com/Forums/vstudio/en-US/fbfdb3bb-e8fe-42af-94a0-9e51176a5b76/csharpcodeprovider-and-wpf?forum=wpf" rel="nofollow noreferrer">This solution</a> would involve hard-coding a specific path, but the solution should be dynamic</li>
  <li>Implementing <a href="https://docs.microsoft.com/en-us/dotnet/framework/unmanaged-api/fusion/iassemblycache-queryassemblyinfo-method" rel="nofollow noreferrer">this Windows API</a> may work; but I don't know how - or if it would even help solve the above</li>
  <li><a href="https://stackoverflow.com/questions/8891688/linking-to-presentationcore-dll-in-mixed-mode-dll">This</a> C++ question refers to where the GAC is found, but not how to get an actual file path</li>
  </ul>