【发布时间】:2014-05-17 21:44:11
【问题描述】:
全部,
我的项目 -(VS 2010 / .NET 4 / ASP.NET 应用程序,我的 Web 应用程序作为 Sitefinity 应用程序存在于 Sitefinity 中)
我有两个版本的 MongoDB 程序集。我想在我的 Web 应用程序中并排运行这些。这是我的设置:
\bin\AuxFiles\[1.8.3.9] assemblies
\bin\[1.4.x.x] assemblies
网络配置:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="MongoDB.Bson" publicKeyToken="f686731cfb9cc103" culture="neutral" />
<codeBase version="1.4.2.4500" href="bin\MongoDB.Bson.dll" />
<codeBase version="1.8.3.9" href="bin\AuxFiles\MongoDB.Bson.dll" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="MongoDB.Driver" publicKeyToken="f686731cfb9cc103" culture="neutral" />
<codeBase version="1.4.2.4500" href="bin\MongoDB.Driver.dll" />
<codeBase version="1.8.3.9" href="bin\AuxFiles\MongoDB.Driver.dll" />
</dependentAssembly>
</assemblyBinding>
当应用程序启动时,它默认加载 1.4.x.x 程序集。当我转到使用 1.8.3.9 版本程序集的页面时,出现错误:
Server Error in '/' Application.
Could not load file or assembly 'MongoDB.Driver, Version=1.8.3.9, Culture=neutral, PublicKeyToken=f686731cfb9cc103' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
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.FileLoadException: Could not load file or assembly 'MongoDB.Driver, Version=1.8.3.9, Culture=neutral, PublicKeyToken=f686731cfb9cc103' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source Error: ....
Source File: ...... Line: 18
Assembly Load Trace: The following information can be helpful to determine why the assembly 'MongoDB.Driver, Version=1.8.3.9, Culture=neutral, PublicKeyToken=f686731cfb9cc103' could not be loaded.
=== Pre-bind state information ===
LOG: DisplayName = MongoDB.Driver, Version=1.8.3.9, Culture=neutral, PublicKeyToken=f686731cfb9cc103
(Fully-specified)
LOG: Appbase = file:///C:/DEV/Visual Studio 2010/WebStoreApp/WebStoreApp/
LOG: Initial PrivatePath = C:\DEV\Visual Studio 2010\WebStoreApp\WebStoreApp\bin
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\DEV\Visual Studio 2010\WebStoreApp\WebStoreApp\web.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: MongoDB.Driver, Version=1.8.3.9, Culture=neutral, PublicKeyToken=f686731cfb9cc103
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/d73c4379/cb2aee95/MongoDB.Driver.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/d73c4379/cb2aee95/MongoDB.Driver/MongoDB.Driver.DLL.
LOG: Attempting download of new URL file:///C:/DEV/Visual Studio 2010/WebStoreApp/WebStoreApp/bin/MongoDB.Driver.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
Stack Trace:
[FileLoadException: Could not load file or assembly 'MongoDB.Driver, Version=1.8.3.9, Culture=neutral, PublicKeyToken=f686731cfb9cc103' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint
更新 1:
我尝试将新的 1.8.x.x 程序集从 MongoDB.Driver.dll 重命名为 MongoDB.Driver.exe,以便文件可以在同一目录下共存(旧程序集的扩展名为 .dll,新版本的程序集具有扩展名.exe) 但装载机似乎没有拾取组件。我的理解是加载程序总是先尝试.dlls,然后再尝试.exes。我有点疑惑。
更新 2:
我创建了一个控制台应用程序,其中包含完全相同的双重引用设置和您在此处看到的应用程序配置条目,并且该应用程序工作正常,它执行 2 个版本的 Mongo dll。现在的问题是,为什么这个设置在我的 Web 应用程序中不起作用?我的目录错了吗?如果您在下面查看程序集的探测,它从不检查我的 AuxFiles 目录,它似乎只是忽略了我在web.config 中并行执行的配置。
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/d73c4379/cb2aee95/MongoDB.Driver.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/d73c4379/cb2aee95/MongoDB.Driver/MongoDB.Driver.DLL.
LOG: Attempting download of new URL file:///C:/DEV/Visual Studio 2010/WebStoreApp/WebStoreApp/bin/MongoDB.Driver.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
更新 3:
找到了问题,但我不确定此解决方案的详细信息。 web.config 文件具有 'configuration' 根元素和以下命名空间声明 - 'xmlns=http://schemas.microsoft.com/.NetConfiguration/v2.0'。
根元素很好,但指定的命名空间导致我的'runtime' 元素被忽略。从配置元素中删除命名空间可以解决所有问题。
【问题讨论】:
-
我认为您误解了并行组装这个术语。它确实不意味着您可以将同一个DLL的两个版本加载到同一个执行上下文中。
-
您想要运行两个不同的驱动程序的任何具体原因?
-
根据 Jeffrey Richter 的“Applied MS .net Framework”,他说您可以加载同一个 DLL 的 2 个版本。
-
我正在运行两个版本,因为我正在使用的代码使用的是旧版本,但我需要使用新版本。
-
这是 Jeffrey Richter 的“Applied MS .net Framework”一书中关于并行执行的声明:CLR 能够将多个同名但路径不同的文件加载到单个地址空间。这称为并行执行...
标签: asp.net .net .net-assembly