同时运行两个版本的MongoDB程序集

时间:2014-05-17 21:44:11

标签: asp.net .net .net-assembly

所有

我的项目 - (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.xx程序集从MongoDB.Driver.dll重命名为MongoDB.Driver.exe,因此这些文件可以在同一目录下共存(较旧的程序集具有扩展名.dll,新的程序集的版本具有扩展名.exe),但加载程序似乎不会拾取程序集。我的理解是加载器总是首先尝试.dll,然后尝试.exe秒。我有点不解。


更新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'根元素w /以下名称空间声明 - 'xmlns=http://schemas.microsoft.com/.NetConfiguration/v2.0'

root元素很好,但指定的命名空间导致我的'runtime'元素被忽略。从配置元素中删除命名空间可以修复所有问题。

1 个答案:

答案 0 :(得分:1)

发现问题:

&#39;配置&#39; web.config文件中的root元素包含以下名称空间声明 - &#39; xmlns = http://schemas.microsoft.com/.NetConfiguration/v2.0&#39;。从配置元素中删除命名空间可以修复所有内容。

为什么ns?它更像是VS中的任何错误,并且实际上没有任何真正的目的,但是搞乱了你的智能感知,在我的情况下是运行时配置。阅读更多相关信息: http://weblogs.asp.net/scottgu/archive/2005/12/02/432077.aspx