2017-12-18 8 views
4

私は、Web APIアプリケーションを作成しようとしていますし、それは私の既存のモンゴデータベースから結果を取得しますが、そうC#ASP.NET Core APIフレームワークでMongoDBドライバを使用するにはどうすればよいですか?

Could not load type 'System.Runtime.Remoting.Messaging.CallContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 

An unhandled exception occurred while processing the request. 
TypeLoadException: Could not load type 'System.Runtime.Remoting.Messaging.CallContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 
MongoDB.Driver.Core.Events.EventContext+AsyncLocal.get_Value() 

MongoDB.Driver.Core.Events.EventContext+AsyncLocal.get_Value() 
MongoDB.Driver.Core.Events.EventContext.BeginOperation(Nullable<long> operationId) 
MongoDB.Driver.Core.Operations.FindCommandOperation.Execute(IReadBinding binding, CancellationToken cancellationToken) 
MongoDB.Driver.Core.Operations.FindOperation.Execute(IReadBinding binding, CancellationToken cancellationToken) 
MongoDB.Driver.OperationExecutor.ExecuteReadOperation<TResult>(IReadBinding binding, IReadOperation<TResult> operation, CancellationToken cancellationToken) 
MongoDB.Driver.MongoCollectionImpl.ExecuteReadOperation<TResult>(IClientSessionHandle session, IReadOperation<TResult> operation, ReadPreference readPreference, CancellationToken cancellationToken) 
MongoDB.Driver.MongoCollectionImpl.ExecuteReadOperation<TResult>(IClientSessionHandle session, IReadOperation<TResult> operation, CancellationToken cancellationToken) 
MongoDB.Driver.MongoCollectionImpl.FindSync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options, CancellationToken cancellationToken) 
MongoDB.Driver.MongoCollectionImpl+<>c__DisplayClass35_0.<FindSync>b__0(IClientSessionHandle session) 
MongoDB.Driver.MongoCollectionImpl.UsingImplicitSession<TResult>(Func<IClientSessionHandle, TResult> func, CancellationToken cancellationToken) 
MongoDB.Driver.MongoCollectionImpl.FindSync<TProjection>(FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options, CancellationToken cancellationToken) 
MongoDB.Driver.FindFluent.ToCursor(CancellationToken cancellationToken) 

を行うとき、私は、このエラーが発生します、私は現在、ASPを持っています.NETコアを標的.NETコアフレームワークは2.0

これは、メソッド呼び出しからスローさ

var documents = collection.Find(_ => true).ToList();

明らかに、私が読んでいるリモーティングは.NET Coreではまだサポートされていませんが、MongoDBのWebサイト(https://docs.mongodb.com/ecosystem/drivers/csharp/)では、.NET 2.0でドライババージョン2.4がサポートされています。 2.4ドライババージョンをインストールしましたが、.Findを使用してDBから何かを引き出すことはできません。

私は本当にLinuxではなくウィンドウで使用できるアプリケーションが本当に好きなので、誰にもこれに対する解決策がありますか?

+0

をあなたはMongoDBのドライバ2.4を述べたが、あなたはどのバージョンを正確にあなたが意味するように、より具体的に説明してくださいすることができ、2.4.0、2.4.1など? – ostati

答えて

2

.NET Core 2.0に対するドライバの使用は間違いありません。あなたはちょうどあなたが以下のNuGetパッケージの一部として来る.NET標準1.5アセンブリを参照していることを確認する必要があります。

https://www.nuget.org/packages/MongoDB.Driver

また、新バージョン2.5がちょうどどのおそらく数日前にリリースされましたMongoDB 3.6に対して最も効果的です。

あなたも、このチュートリアルを読むことをお勧めします:http://www.qappdesign.com/using-mongodb-with-net-core-webapi/

+0

チュートリアルに感謝しています。私はドライバの衝突があり、私のプロジェクトはサポートされていないバージョンを使用していたことが判明しました。 – jjmcc

+0

そこに行くのに数時間かかりました。あなたが追加した素晴らしいチュートリアル。ありがとう。 –

関連する問題