C#使用MongoDB的注意事项

来源:互联网 发布:淘宝运费险怎么设置 编辑:程序博客网 时间:2024/05/19 22:58

  1、使用Nuget Package Manager——Package Manager Console安装MongoDB,如下

PM> Install-Package MongoDB.Driver
Attempting to gather dependency information for package 'MongoDB.Driver.2.4.4' with respect to project 'AccessServerDebug', targeting '.NETFramework,Version=v4.5'
Attempting to resolve dependencies for package 'MongoDB.Driver.2.4.4' with DependencyBehavior 'Lowest'
Resolving actions to install package 'MongoDB.Driver.2.4.4'
Resolved actions to install package 'MongoDB.Driver.2.4.4'
  GET https://api.nuget.org/packages/mongodb.bson.2.4.4.nupkg
  OK https://api.nuget.org/packages/mongodb.bson.2.4.4.nupkg 16ms

2、若自己引用MongoDB 2.4.4则需要安装Install-Package System.Runtime.InteropServices.RuntimeInformation,不然会报Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation异常,另外需要在app.config中添加

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>