I'm upgrading my web application from the .NET Framework version of ASP.NET MVC to ASP.NET Core. I've worked through all of the C# and Razor build errors, and now I'm trying to run the application for the first time. When I make any calls into MongoDB's C# driver:
public static Analytics Find(Enums.Platform platform, DateTime date) {
var builder = Filter;
var filters = builder.Eq("Platform", platform) & builder.Eq("Date", date);
return Collection().Find(filters).FirstOrDefault();// Exception thrown here.
}
It errors:
System.TypeLoadException HResult=0x80131522 Message=Could not load type 'System.Runtime.Remoting.Messaging.CallContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Source=MongoDB.Driver.Core
StackTrace: at MongoDB.Driver.Core.Events.EventContext.AsyncLocal1.get_Value() at MongoDB.Driver.Core.Events.EventContext.BeginOperation(Nullable
1 operationId) at MongoDB.Driver.Core.Operations.FindCommandOperation1.Execute(IReadBinding binding, CancellationToken cancellationToken) at MongoDB.Driver.Core.Operations.FindOperation
1.Execute(IReadBinding binding, CancellationToken cancellationToken) at MongoDB.Driver.OperationExecutor.ExecuteReadOperation[TResult](IReadBinding binding, IReadOperation1 operation, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionImpl
1.ExecuteReadOperation[TResult](IClientSessionHandle session, IReadOperation1 operation, ReadPreference readPreference, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionImpl
1.ExecuteReadOperation[TResult](IClientSessionHandle session, IReadOperation1 operation, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionImpl
1.FindSync[TProjection](IClientSessionHandle session, FilterDefinition1 filter, FindOptions
2 options, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionImpl1.<>c__DisplayClass41_0
1.b__0(IClientSessionHandle session) at MongoDB.Driver.MongoCollectionImpl1.UsingImplicitSession[TResult](Func
2 func, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionImpl1.FindSync[TProjection](FilterDefinition
1 filter, FindOptions2 options, CancellationToken cancellationToken)
2.ToCursor(CancellationToken cancellationToken) at MongoDB.Driver.IAsyncCursorSourceExtensions.FirstOrDefault[TDocument](IAsyncCursorSource
at MongoDB.Driver.FindFluent1 source, CancellationToken cancellationToken) at MongoDB.Driver.IFindFluentExtensions.FirstOrDefault[TDocument,TProjection](IFindFluent
2 find, CancellationToken cancellationToken) at Housters.Data.DataAccess.AnalyticsData.Find(Platform platform, DateTime date) in C:\Housters\Data\DataAccess\Common\AnalyticsData.cs:line 22 at Housters.Business.Services.Common.AnalyticsService.Get(Platform platform, DateTime date) in C:\Housters\Business\Services\Common\AnalyticsService.cs:line 31 at Housters.Business.Services.Common.AnalyticsService.Log(Platform platform, String deviceId, AnalyticsEventType type, Boolean onlyLogIfSignedUp) in C:\Housters\Business\Services\Common\AnalyticsService.cs:line 19 at Housters.Web.Controllers.HomeController.Index() in C:\Housters\Web\Controllers\HomeController.cs:line 8 at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters) at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__12.MoveNext()
I'm confused as to what's going on because MongoDB supports .NET Core, and yet System.Runtime.Remoting.Messaging.CallContext is a .NET Framework method, .NET Core doesn't support it. I saw another SO thread where the OP was facing this issue, however his problem was that he wasn't using the latest MongoDB C# Driver. I'm using the latest driver, 2.8.0, within a .NET Standard (2.0.3) class library.
Nupkg is essentially a zip file with multiple versions of the DLL and some metadata.
In case of Mongo driver, there are DLLs for two target environments
When installing a NuGet package, the dll matching your project is selected. I assume you are still referencing .NET framework DLL, despite using a NuGet package that supports .NET Standard.
Try re-installing your NuGet package. Verify that DLL that lands in your bin for matches .NET Standard version.
User contributions licensed under CC BY-SA 3.0