NLog.Mongo和最新的mongoDB C#驱动程序无法正常工作

时间:2015-04-07 09:12:38

标签: c# mongodb nlog

将项目升级到最新的mongoDB驱动程序时,

nLog不起作用:

---> System.TypeInitializationException: The type initializer for 'NLog.Mongo.MongoTarget' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'MongoDB.Driver, Version=1.9.2.235, 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)
at NLog.Mongo.MongoTarget..cctor()
--- End of inner exception stack trace ---
at NLog.Mongo.MongoTarget..ctor()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
 at NLog.Internal.FactoryHelper.CreateInstance(Type t)

它没有记录任何内容。我正在为nLog使用mongoDB目标。我已经发布了一个问题(https://github.com/loresoft/NLog.Mongo/issues/7)。但也许有办法自己解决它。

有什么建议吗?

目标适用于1.9之前的官方mongoDB驱动程序版本。

1 个答案:

答案 0 :(得分:3)

您可以将装配绑定添加到web.config

  <runtime>
       <dependentAssembly>
        <assemblyIdentity name="MongoDB.Driver" publicKeyToken="f686731cfb9cc103" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.10.0.62" newVersion="1.10.0.62" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="MongoDB.Bson" publicKeyToken="f686731cfb9cc103" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.10.0.62" newVersion="1.10.0.62" />
      </dependentAssembly>

  </runtime>