ASP.NET应用程序无法加载非托管DLL

杰森·德

我正在构建一个ASP.NET应用程序,该应用程序引用了一些VMware非托管DLL。依赖关系如下所示:

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

当我在控制台应用程序中运行测试代码时,一切正常。

但是,当我运行该应用程序的ASP.NET版本时,收到以下错误消息:

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文件:

<?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>

显然,没有将VMware.VimAutomation.Sdk.Impl.dll复制到该临时目录中。即使我手动复制它并尝试重新运行代码,错误消息仍然存在。

我已审阅并尝试了以下相关问题的所有答案:

无法加载文件或程序集临时ASP.NET文件

非托管DLL无法在ASP.NET服务器上加载

如果任何人都可以分享一些疑难解答的想法,将不胜感激。

杰森·德

经过一天半的努力,我找到了一个非常简单的解决方案。

将以下代码添加到我的Web.Config中,解决了该问题:

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

这将停止将所有文件复制到Temporary ASP.NET Files目录,从而避免了丢失的引用DLL问题。

虽然我不能确定现在从哪个目录加载文件。可能是我的项目\ bin?

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在共享Linux托管上托管ASP.NET Core应用程序

自托管ASP.NET MVC应用程序

IIS加载ASP.NET Web应用程序的哪些dll文件?

使用虚拟目录/应用程序在IIS中托管ASP.NET 5 WebAPI

在WPF自托管asp.net核心应用程序中加载视图

asp.net应用程序无法自动启动

从asp.net Web应用程序加密.dll

无法使用cmd.exe在iis托管的asp.net Web应用程序中执行命令ng build

无法在运行时通过IIS托管的ASP.NET Core应用程序设置ODBC源

在ASP.net Mvc应用程序的IIS中部署应用程序时,Crystal Report无法加载

为什么ASP.NET Core应用程序无法在同一域的iframe中加载?

Docker Asp.net核心应用程序将无法加载我的JS,imgs

在.net核心应用程序中自托管HTTP端点而不使用asp.net?

具有多个项目的asp.net应用程序无法加载页面代码类型

Font Awesome无法在托管的ASP应用程序中正确显示

如何为工作站应用程序成功自托管ASP.NET MVC应用程序或OData服务?

在子文件夹上托管ASP.net应用程序

ASP.net应用程序崩溃-无法加载文件或程序集“ Microsoft.Threading.Tasks.Extensions.Desktop”

无法从ASP NET应用程序中托管的WCF数据服务访问数据库

ASP.NET Web应用程序“无法加载程序集“ App_Web_”

托管后ASP.NET应用程序无法验证

是否可以在没有HttpPlatformHandler的情况下托管ASP.Net 5应用程序?

无法在ASP.NET Core 1应用程序中使用Oracle托管驱动程序

托管到本地 IIS 后,无法读取 ASP.NET Core 1.2 应用程序上的 swagger JSON 文件

Asp.net MVC 应用程序无法托管和正常工作

我有一个托管在 AWS 中的 ASP.NET Core MVC 应用程序。在此用户将加载文件。在哪里保存这些文件

无法使 ASP.Net Web 窗体应用程序超时

无法连接托管在 Azure Web 应用程序上的安全 Asp.Net Core Web 套接字(使用 TLS)

无法从控制台应用程序调用 TLS 身份验证的 Web API 转移到 ASP.NET MVC IIS 托管应用程序