C#Interactive-无法加载文件或组装



我正在尝试使用C#Interactive尝试一些MongoDB驱动程序,但是一旦我尝试创建MongoClient,我就会得到以下例外:

> var client = new MongoClient();
Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
  + MongoDB.Driver.Core.Connections.ClientDocumentHelper.CreateOSDocument()
  + Lazy<T>.CreateValue()
  + Lazy<T>.get_Value()
  + MongoDB.Driver.Core.Connections.ClientDocumentHelper.CreateClientDocument(string)
  + MongoDB.Driver.Core.Connections.BinaryConnectionFactory..ctor(MongoDB.Driver.Core.Configuration.ConnectionSettings, MongoDB.Driver.Core.Connections.IStreamFactory, MongoDB.Driver.Core.Events.IEventSubscriber)
  + MongoDB.Driver.Core.Configuration.ClusterBuilder.BuildCluster()
  + MongoDB.Driver.ClusterRegistry.CreateCluster(MongoDB.Driver.ClusterKey)
  + MongoDB.Driver.ClusterRegistry.GetOrCreateCluster(MongoDB.Driver.ClusterKey)
  + MongoDB.Driver.MongoClient..ctor(MongoDB.Driver.MongoClientSettings)
  + MongoDB.Driver.MongoClient..ctor()

这是复制的完整详细信息: -

通过命令行安装MongoDB驱动程序的最新版本。

C:dev>nuget.exe install MongoDB.Driver -OutputDirectory tools -ExcludeVersion
Feeds used:
  https://api.nuget.org/v3/index.json
  C:Program Files (x86)Microsoft SDKsNuGetPackages
  C:Program FilesMicrosoft SDKsService Fabricpackages
Attempting to gather dependencies information for package 'MongoDB.Driver.2.4.3' with respect to project 'tools', targeting 'Any,Version=v0.0'
Attempting to resolve dependencies for package 'MongoDB.Driver.2.4.3' with DependencyBehavior 'Lowest'
Resolving actions to install package 'MongoDB.Driver.2.4.3'
Resolved actions to install package 'MongoDB.Driver.2.4.3'
Adding package 'MongoDB.Bson.2.4.3' to folder 'C:devtools'
Added package 'MongoDB.Bson.2.4.3' to folder 'C:devtools'
Successfully installed 'MongoDB.Bson 2.4.3' to tools
Adding package 'System.Runtime.InteropServices.RuntimeInformation.4.0.0' to folder 'C:devtools'
Added package 'System.Runtime.InteropServices.RuntimeInformation.4.0.0' to folder 'C:devtools'
Successfully installed 'System.Runtime.InteropServices.RuntimeInformation 4.0.0' to tools
Adding package 'MongoDB.Driver.Core.2.4.3' to folder 'C:devtools'
Added package 'MongoDB.Driver.Core.2.4.3' to folder 'C:devtools'
Successfully installed 'MongoDB.Driver.Core 2.4.3' to tools
Adding package 'MongoDB.Driver.2.4.3' to folder 'C:devtools'
Added package 'MongoDB.Driver.2.4.3' to folder 'C:devtools'
Successfully installed 'MongoDB.Driver 2.4.3' to tools

打开C#交互式窗口,并在DLLS中导入

Microsoft (R) Roslyn C# Compiler version 2.0.0.61501
Loading context from 'CSharpInteractive.rsp'.
Type "#help" for more information.
> #r "c:devtoolsMongoDB.Driverlibnet45MongoDB.Driver.dll"
> #r "c:devtoolsMongoDB.Bsonlibnet45MongoDB.Bson.dll"
> #r "c:devtoolsMongoDB.Driver.Corelibnet45MongoDB.Driver.Core.dll"
> #r "c:devtoolsSystem.Runtime.InteropServices.RuntimeInformationlibnet45System.Runtime.InteropServices.RuntimeInformation.dll"

然后尝试创建MongoClient

> var client = new MongoClient();
Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
  + MongoDB.Driver.Core.Connections.ClientDocumentHelper.CreateOSDocument()
  + Lazy<T>.CreateValue()

我最近遇到了这个问题,从web.config中删除System.Runtime.InteropServices.RuntimeInformation代码工作:(如果您有Windows应用程序,请检查App.Config(。

删除此代码,它将起作用:

<dependentAssembly>
  <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>

相关内容

  • 没有找到相关文章

最新更新