2

I am building an ASP.NET application which references some VMware unmanaged DLL's. The dependencies look something like this:

My Application
    |__VMware.VimAutomation.HorizonView.Interop.DLL (unmanaged DLL)
        |__VMware.VimAutomation.HorizonView.Impl.DLL (unmanaged DLL)

When I run my test code in a console app, everything works fine.

However when I run my ASP.NET version of the app, I receive the following error message:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\test\87752894\3f64ba7e\assembly\dl3\48cfd1a4\005d27b4_7c3ad201\VMware.VimAutomation.Sdk.Impl.dll' or one of its dependencies. The system cannot find the file specified.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'file:///C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\test\87752894\3f64ba7e\assembly\dl3\48cfd1a4\005d27b4_7c3ad201\VMware.VimAutomation.Sdk.Impl.dll' could not be loaded.


WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Stack Trace: 


[FileNotFoundException: Could not load file or assembly 'file:///C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\test\87752894\3f64ba7e\assembly\dl3\48cfd1a4\005d27b4_7c3ad201\VMware.VimAutomation.Sdk.Impl.dll' or one of its dependencies. The system cannot find the file specified.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +225
   System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark) +172
   System.Reflection.Assembly.LoadFrom(String assemblyFile, Evidence securityEvidence) +53
   System.Activator.CreateInstanceFromInternal(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo) +29
   System.Activator.CreateInstanceFrom(String assemblyFile, String typeName) +52
   VMware.VimAutomation.Sdk.Interop.V1.CoreServiceFactory..cctor() +148

[TypeInitializationException: The type initializer for 'VMware.VimAutomation.Sdk.Interop.V1.CoreServiceFactory' threw an exception.]
   VMware.VimAutomation.HorizonView.Impl.V1.ViewServerClientManagerImpl.RegisterClientServer(ViewServerClient client, ViewServerInterop server) +69
   VMware.VimAutomation.HorizonView.Impl.V1.ViewServerClientManagerImpl.UpdateClient(ViewServerClient client, String domain, HviClientImpl hviClientImpl) +228
   VMware.VimAutomation.HorizonView.Impl.V1.ViewServerClientManagerImpl.ConnectViewServer(String server, String username, SecureString password, String domain) +257
   WebApplication17.Controllers.HomeController.Index() in C:\Users\jdavis\source\repos\WebApplication17\WebApplication17\Controllers\HomeController.cs:34
   lambda_method(Closure , ControllerBase , Object[] ) +87
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +35
   System.Web.Mvc.Async.<>c.<BeginInvokeSynchronousActionMethod>b__9_0(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +39
   System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +77
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +42
   System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__11_0() +72
   System.Web.Mvc.Async.<>c__DisplayClass11_1.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2() +387
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +42
   System.Web.Mvc.Async.<>c__DisplayClass3_6.<BeginInvokeAction>b__3() +50
   System.Web.Mvc.Async.<>c__DisplayClass3_1.<BeginInvokeAction>b__5(IAsyncResult asyncResult) +188
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
   System.Web.Mvc.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState) +26
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +73
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +52
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +39
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
   System.Web.Mvc.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState) +40
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +73
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +602
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +195
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +128

Web.config file:

<?xml version="1.0"?>

<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="WebApplication17" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <appSettings>
    <!--<add key="webpages:Enabled" value="false" />-->
  </appSettings>

  <system.webServer>
    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>

  <system.web>
    <compilation>
      <assemblies>
        <add assembly="System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>
  </system.web>
</configuration>

It's clear that VMware.VimAutomation.Sdk.Impl.dll is not being copied into that temporary directory. And even if I manually copy it and try to re-run the code, the error message persists.

I've reviewed and tried every answer in the following related questions:

Could not load file or assembly Temporary ASP.NET Files

Unmanaged DLLs fail to load on ASP.NET server

If anyone can share some ideas for troubleshooting this, it would be appreciated.

Jason D
  • 1,863
  • 2
  • 16
  • 30

1 Answers1

2

So after a day and a half of fighting this, I found a very simple solution.

Adding the following code to my Web.Config, solved the problem:

  <system.web>
      <hostingEnvironment shadowCopyBinAssemblies="false" />
  </system.web>

This stopped ALL files being copied to Temporary ASP.NET Files directory, thus avoiding the missing referenced DLL issue.

Although I cannot be sure which directory now the files are being loaded from. Possibly my project \bin?

Jason D
  • 1,863
  • 2
  • 16
  • 30