I have 4 projects:
A - .NET Core 2.2 project - reference to B and D (knows nothing about C)
B - .NET 4.7.2 Class Library - reference to C and D
C - .NET 4.7.2 Class Library - reference D and the the MongoDB C# Driver (Version 2.7.30) installed with NuGet.
D - .NET 4.7.2 Class Library - just a container for DTO classes
All projects do build and run.
===
B is a generic data repository.
C is a database context, which uses the MongoDB C# driver.
Both projects B and C work well without any errors, when I use them in "normal" .NET 4.7.2, also 4.5.2 projects.
===
The error:
When I make a call from the .NET Core project A to B which ends in C, I get an error at this point:
private IMongoCollection<T> _Collection;
public IMongoCollection<T> Collection
{
get
{
if (_Collection == null)
{
//This is still ok!
_Collection = _DataBase.GetCollection<T>("MyTableName");
}
return _Collection;
}
}
public IEnumerable<T> All
{
get
{
try
{
//Collection is NOT Null and was loaded from the DB
return Collection.Find(new BsonDocument()).ToList();
}
catch (Exception ex)
{
//THE EXCEPTION APPEARS HERE
}
return null;
}
}
The exception details are:
{System.TypeLoadException: Could not load type 'System.Runtime.Remoting.Messaging.CallContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
at MongoDB.Driver.Core.Events.EventContext.AsyncLocal1.get_Value()
at MongoDB.Driver.Core.Events.EventContext.BeginOperation(Nullable1 operationId)
at MongoDB.Driver.Core.Operations.FindCommandOperation1.Execute(IReadBinding binding, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Operations.FindOperation1.Execute(IReadBinding binding, CancellationToken cancellationToken)
at MongoDB.Driver.OperationExecutor.ExecuteReadOperation[TResult](IReadBinding binding, IReadOperation1 operation, CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl1.ExecuteReadOperation[TResult](IClientSessionHandle session, IReadOperation1 operation, ReadPreference readPreference, CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl1.ExecuteReadOperation[TResult](IClientSessionHandle session, IReadOperation1 operation, CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl1.FindSync[TProjection](IClientSessionHandle session, FilterDefinition1 filter, FindOptions2 options, CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl1.<>c__DisplayClass41_01.b__0(IClientSessionHandle session)
at MongoDB.Driver.MongoCollectionImpl1.UsingImplicitSession[TResult](Func2 func, CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl1.FindSync[TProjection](FilterDefinition1 filter, FindOptions2 options, CancellationToken cancellationToken)
at MongoDB.Driver.FindFluent2.ToCursor(CancellationToken cancellationToken)
at MongoDB.Driver.IAsyncCursorSourceExtensions.ToList[TDocument](IAsyncCursorSource`1 source, CancellationToken cancellationToken)
...}
(sorry for the full exception, but I thought it would help)
My question:
What can I do to solve this problem?
As I said earlier above - this seems to be a .NET Core problem, since the projects run without any error in other projects.