无法加载类型“MongoDB.Bson.PreserveAttribute”

问题描述 投票:0回答:1

我将 .NetFramework 更新到 4.7.2 并将 MongoDb.Driver 更新到 2.19.1 时出现此错误。我已经清理了我的参考资料,但错误仍然存在。

Could not load type 'MongoDB.Bson.PreserveAttribute' from assembly 'MongoDB.Bson, Version=2.4.3.23, Culture=neutral, PublicKeyToken=null'.

[TypeLoadException: Could not load type 'MongoDB.Bson.PreserveAttribute' from assembly 'MongoDB.Bson, Version=2.4.3.23, Culture=neutral, PublicKeyToken=null'.]
   System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) +0
   System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) +197
   System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) +166
   System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) +156
   System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) +612
   System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) +149
   Owin.Loader.DefaultLoader.SearchForStartupAttribute(String friendlyName, IList`1 errors, Boolean& conflict) +199
   Owin.Loader.DefaultLoader.GetDefaultConfiguration(String friendlyName, IList`1 errors) +68
   Owin.Loader.DefaultLoader.LoadImplementation(String startupName, IList`1 errorDetails) +89
   Owin.Loader.DefaultLoader.Load(String startupName, IList`1 errorDetails) +30
   Microsoft.Owin.Host.SystemWeb.OwinBuilder.GetAppStartup() +165
   Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint() +37
   System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) +139
   Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication context) +160
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +587
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +173
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +255
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +347

[HttpException (0x80004005): Could not load type 'MongoDB.Bson.PreserveAttribute' from assembly 'MongoDB.Bson, Version=2.4.3.23, Culture=neutral, PublicKeyToken=null'.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +552
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +122
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +737

我已经把所有的项目都更新到4.7.2了,并且在配置属性的项目解决方案中做了check uncheck的方法。我已经解决了其他问题,但这对我来说是一个障碍。

另外:System.Runtime.CompilerServices.Unsafe 的版本是 5.0.0,我使用的是 Visual Studio 2022 版本 17.4.4

更新:我已经看到了这个问题。似乎我的清理并没有真正删除未使用的引用,因为我没有清理未使用的引用的选项,我删除了项目中未使用的文件

Fix

c# mongodb-.net-driver .net-framework-version .net-4.7.2
1个回答
0
投票

我将我的 MongoDb.Driver 更新到 2.19.1.

您还应该更新相关的 nugets,例如

MongoDB.Bson
MongoDB.Driver.Core

© www.soinside.com 2019 - 2024. All rights reserved.