title: Copying embedded resource as file to disk in C#
body: <p>I have an INF file saved as an embedded resource in my C# project. I am trying to save this file to a local location on demand. I am using this method.</p>
  
  <pre><code>public static void SaveResourceToDisk(string ResourceName, string FileToExtractTo)
  {
      Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(ResourceName);
      FileStream resourceFile = new FileStream(FileToExtractTo, FileMode.Create);
  
      byte[] b = new byte[s.Length + 1];
      s.Read(b, 0, Convert.ToInt32(s.Length));
      resourceFile.Write(b, 0, Convert.ToInt32(b.Length - 1));
      resourceFile.Flush();
      resourceFile.Close();
  
      resourceFile = null;
  }
  </code></pre>
  
  <p>When I try to call this method (passing the resource name along with the namespace name), I get the error:</p>
  
  <blockquote>
    <p>Object reference not set to an instance of an object</p>
  </blockquote>
  
  <p>What am I doing wrong here?</p>