title: Runtime error loading certificate in Azure Functions
body: <p>I want to create an Azure function (C# API Generic HTTP) method that uploads a file to an Office365 Sharepoint document library.</p>
  
  <p>Because OneDrive API allows me to upload large files (using daemon process &amp; certificate authentication), I have succeeded in achieving the goal with a C# Console Application. </p>
  
  <p>The idea would be now to move the code into an Azure function. 
  However, I receive an error during runtime of the function on the loading of the pfx-certificate.</p>
  
  <pre><code>public static async Task&lt;bool&gt; Run(HttpRequestMessage req, TraceWriter log)
  {
     string certfile = System.IO.Path.Combine(Environment.ExpandEnvironmentVariable‌​s("%HOME%"), @"site\wwwroot\&lt;functionname&gt;\mykeyfile.pfx"); 
  
      X509Certificate2 cert = new X509Certificate2(certfile, "&lt;myinsanepwd&gt;");
  
      return true; //temporary 
  }
  </code></pre>
  
  <p>The line X509Certificate2 cert = new X509Certificate2(certfile, ""); throws an Exception
   System.Security.Cryptography.CryptographicException: The system cannot find the file specified. </p>
  
  <p>This is really strange because the file exists on the specified path (I checked using File.Exists() in the method :) )
  Could this error have something to do with support.microsoft.com/en-us/kb/948154 ?  How can I solve this?</p>
  
  <p>Best regards,
  Jens</p>