簡體   English   中英

即使在bin文件夾中復制后,Visual Studio 2015仍找不到外部.dll,而僅在復制到c:\\ Windows \\

[英]Visual Studio 2015 does not find external .dll even after copying in bin folder, but only after copying to c:\Windows\

我嘗試在Visual Studio 2015中構建一個Web項目,該項目引用ac#.dll項目“ dotnetWrapper”,這是c ++項目“ managedDllWrapper”的ac#包裝器,其中包括一些第三方的64位本機c ++ .dll。

引用的項目和Web項目在.Net Framework 4.6.1和x64上運行。 VS2015使用iis Express 64位。

一切都編譯良好。

當我在VS2015中啟動本地Web服務器時(單擊綠色的“開始”按鈕),我收到一條錯誤消息,即找不到“ managedDllWrapper.dll”或其依賴項之一:

“ /”應用程序中的服務器錯誤。

無法加載文件或程序集“ managedDllWrapper.DLL”或其依賴項之一。 指定的模塊無法找到。

說明:執行當前Web請求期間發生未處理的異常。 請查看堆棧跟蹤,以獲取有關錯誤及其在代碼中起源的更多信息。

異常詳細信息:System.IO.FileNotFoundException:無法加載文件或程序集“ managedDllWrapper.DLL”或其依賴項之一。 指定的模塊無法找到。

源錯誤:

當前Web請求的執行期間生成了未處理的異常。 可以使用下面的異常堆棧跟蹤來標識有關異常的來源和位置的信息。

堆棧跟蹤:

[FileNotFoundException:無法加載文件或程序集'managedDllWrapper.DLL'或其依賴項之一。 找不到指定的模塊。] System.Reflection.RuntimeAssembly._nLoad(AssemblyName文件名,字符串codeBase,證據AssemblySecurity,RuntimeAssembly locationHint,StackCrawlMark&stackMark,IntPtr pPrivHostBinder,布爾型throwOnFileNotFound,布爾值用於Introspection,布爾值hibitSecurityChecks)

System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef,證據AssemblySecurity,RuntimeAssembly reqAssembly,StackCrawlMark&stackMark,IntPtr pPrivHostBinder,布爾型throwOnFileNotFound,布爾型用於自省,布爾型抑制安全檢查)+234

System.Reflection.RuntimeAssembly.InternalLoad(字符串assemblyString,證據AssemblySecurity,StackCrawlMark&stackMark,IntPtr pPrivHostBinder,用於自省的布爾值)+108

System.Reflection.RuntimeAssembly.InternalLoad(字符串assemblyString,證據assemblySecurity,StackCrawlMark&stackMark,用於自省的布爾值)+25

System.Reflection.Assembly.Load(字符串assemblyString)+34 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(字符串assemblyName,布爾starDirective)+49

[ConfigurationErrorsException:無法加載文件或程序集'managedDllWrapper.DLL'或其依賴項之一。 指定的模塊無法找到。]

System.Web.Configuration.CompilationSection.LoadAssemblyHelper(字符串assemblyName,布爾型starDirective)+772

System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory()+259

System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai)+163

System.Web.Compilation。<> c.b__143_0(AssemblyInfo ai)+29

System.Linq.d__16'2.MoveNext()+293

System.Linq.d__66'1.MoveNext()+100

System.Linq.d__63'1.MoveNext()+73

System.Web.UI.Util.GetTypeFromAssemblies(IEnumerable程序集,字符串typeName,布爾值ignoreCase)+217

System.Web.Compilation.BuildManager.GetType(字符串類型名稱,布爾throwOnError,布爾ignoreCase)+266

System.Web.Configuration.HandlerFactoryCache.GetTypeWithAssert(字符串類型)+48

System.Web.Configuration.HandlerFactoryCache.GetHandlerType(字符串類型)+17

System.Web.Configuration.HandlerFactoryCache..ctor(字符串類型)+25

System.Web.HttpApplication.GetFactory(字符串類型)+104

System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+262

System.Web.HttpApplication.ExecuteStep(IExecutionStep步驟,布爾值和已完成同步)+137

版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.6.1055.0

請注意,本機dll(依賴項)位於Web項目的bin文件夾(手動復制)中。

當我將本機dll復制到我的C:\\ Windows \\文件夾中時,Web應用程序可以正常運行。 以某種方式,Web應用程序的dll搜索路徑僅指向C:\\ Windows \\文件夾,但是它也應該查看webapp執行(bin)文件夾,對嗎?

當我不使用Web應用程序,而是使用C#控制台測試應用程序(該程序還包括所有dll的包裝程序)時,將dll復制到test-app bin文件夾中就可以正常工作,並且該應用程序可以運行。 僅Web應用程序有此問題,不接受其bin文件夾中的dll。

另外,當我將dll復制到C:\\ Windows \\目錄中,並運行Web應用程序,然后嘗試再次刪除dll時,它說無法刪除它們,因為

因為該文件是在IIS Express工作進程中打開的。

因此,也許這是IIS的問題,而不是VS2015的問題,但是我無法配置IIS(或者我不知道如何)。 我使用Visual Studio 2015隨附的IIS Express。

我在Google和stackoverflow上所做的所有研究均得出:

  • 將dll復制到bin文件夾(嘗試過,但如上所述無法運行,僅適用於C#控制台應用程序,不適用於Web應用程序)。
  • 直接在項目中引用dll(不可能:)

    “無法添加[..]。dll。請確保該文件可訪問,並且它是有效的程序集或COM組件。”

  • 檢查所有內容是否都是64位和相同的.Net版本(已檢查,64位,.Net 4.6.1。此外:它對於控制台應用程序正常工作,但不適用於Web應用程序)。
  • 更改web.config以添加其他.dll文件夾。 但這也沒有幫助。

如果我的Web項目可以在不同於C:\\ Windows \\的文件夾中找到.dll,我會很高興,因為我懷疑是否可以將17 .dll添加到MS azurewebsites的C:\\ Windows \\文件夾中當我想發布該網站時。 然后,路徑應以某種方式位於應用程序文件夾中。

我沒有一對一地解決問題,但是我成功地繞過了這個問題:

通過用顯式的dllimport重寫c#/ c ++包裝器,我直接用路徑處理了dll文件。 然后,從屬dll只需與引用的dll位於同一文件夾中。 這在Web應用程序中也適用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM