title: Read a Registry Key
body: <p>I have a web application which is importing DLLs from the bin folder.</p>
  
  <pre><code>const string dllpath = "Utility.dll";
  
      [DllImport(dllpath)]
  </code></pre>
  
  <p>Now what I want to do is first import the DLLs from a folder not in the current project but at some different location.</p>
  
  <p>The path of that folder is stored in a registry key.</p>
  
  <p>How should I do this?</p>
  
  <p><strong>Edit</strong>:</p>
  
  <p>Why can't I work this out???</p>
  
  <pre><code>public partial class Reports1 : System.Web.UI.Page
  {
  
      RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(@"Software\xyz");
      string pathName = (string)registryKey.GetValue("BinDir");
  
      const string dllpath = pathName;
      [DllImport(dllpath)]
      public static extern bool GetErrorString(uint lookupCode, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder buf, uint bufSize);
  
      protected void Page_Load(object sender, EventArgs e)
      {
  </code></pre>
  
  <p><code>string pathName = (string)registryKey.GetValue("BinDir");</code> is not working here, but is working in the pageload event...</p>
  
  <p>But if I do this DLL import won't work...
  How can I fix this?</p>