无法加载文件或程序集 'MvcSiteMapProvider

Could not load file or assembly 'MvcSiteMapProvider

我通过 nuget 控制台 Install-Package MvcSiteMapProvider.MVC4 添加了提供程序。 安装看起来不错:

已成功将 'MvcSiteMapProvider.MVC4 4.6.22' 添加到 XYZ。

当我执行应用程序时,我收到此错误消息关于故障排除的任何建议?

“/XYZ”应用程序中的服务器错误。

无法加载文件或程序集 'MvcSiteMapProvider, Version=4.6.22.0, Culture=neutral, PublicKeyToken=1923abe4657913cc' 或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (HRESULT 异常:0x80131040) 说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

异常详细信息:System.IO.FileLoadException:无法加载文件或程序集 'MvcSiteMapProvider, Version=4.6.22.0, Culture=neutral, PublicKeyToken=1923abe4657913cc' 或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (HRESULT 异常:0x80131040)

来源错误:

在执行当前网络请求的过程中产生了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常来源和位置的信息。

程序集加载跟踪:以下信息有助于确定无法加载程序集 'MvcSiteMapProvider, Version=4.6.22.0, Culture=neutral, PublicKeyToken=1923abe4657913cc' 的原因。

警告:程序集绑定日志记录已关闭。 要启用程序集绑定失败日志记录,请将注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) 设置为 1。 注意:程序集绑定失败日志记录会带来一些性能损失。 要关闭此功能,请删除注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog].

堆栈跟踪:

[FileLoadException: 无法加载文件或程序集 'MvcSiteMapProvider, Version=4.6.22.0, Culture=neutral, PublicKeyToken=1923abe4657913cc' 或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (HRESULT 异常:0x80131040)] System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule, IRuntimeMethodInfo pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs) +0 System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule 模块、IRuntimeMethodInfo 构造函数、IntPtr& blob、IntPtr blobEnd、Int32& namedArgs) +38 System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) +571 System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly 程序集, RuntimeType caType) +103 System.Reflection.RuntimeAssembly.GetCustomAttributes(布尔继承)+37 Owin.Loader.DefaultLoader.SearchForStartupAttribute(String friendlyName, IList1 errors, Boolean& conflict) +106 Owin.Loader.DefaultLoader.GetDefaultConfiguration(String friendlyName, IList1 个错误) +46 Owin.Loader.DefaultLoader.LoadImplementation(String startupName, IList1 errorDetails) +75 Owin.Loader.DefaultLoader.Load(String startupName, IList1 errorDetails) +21 Microsoft.Owin.Host.SystemWeb.OwinBuilder.GetAppStartup() +115 Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint() +28 System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) +115 Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication 上下文)+106 System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext、HttpContext 上下文、MethodInfo[] 处理程序)+534 System.Web.HttpApplication.InitSpecial(HttpApplicationState 状态、MethodInfo[] 处理程序、IntPtr appContext、HttpContext 上下文)+172 System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext 上下文) +352 System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

[HttpException (0x80004005): 无法加载文件或程序集 'MvcSiteMapProvider, Version=4.6.22.0, Culture=neutral, PublicKeyToken=1923abe4657913cc' 或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (HRESULT 异常:0x80131040)] System.Web.HttpRuntime.FirstRequestInit(HttpContext 上下文) +9947380 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext上下文)+101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext 上下文) +261

假设您确实安装了 Nuget 包,该错误通常是 Web.config 中绑定重定向的问题。您可以尝试手动解决问题,方法是找到适当的绑定重定向并确保版本号正确。我发现强制删除软件包并重新安装它更容易。这通常会解决问题:

> uninstall-package MvcSiteMapProvider.MVC4 -Force
> install-package MvcSiteMapProvider.MVC4

确保您的 Web.config 未在您的文档窗格中打开,或者如果是,请允许它重新加载。如果在安装 Nuget 包后没有从文件系统刷新就保存它,您经常会遇到诸如绑定重定向之类的事情,从而导致这个问题。