【问题标题】:Wrong assembly version from Owin dependency来自 Owin 依赖项的错误程序集版本
【发布时间】:2019-03-11 21:33:44
【问题描述】:

我需要将一个特定的库从之前的 16.1 版切换到 15.0 版。我通过删除较高版本并通过 nuget 安装较低版本来做到这一点。

在构建时,会在 bin 目录中创建正确的 dll (15.0)。但是在启动(Web)应用程序时收到以下错误:

    [FileLoadException: Could not load file or assembly 'Microsoft.SharePoint.Client.Runtime, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
   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) +145
   System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) +158
   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) +91
   System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) +438
   System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) +103
   System.Reflection.RuntimeAssembly.GetCustomAttributes(Boolean inherit) +37
   Owin.Loader.DefaultLoader.SearchForStartupAttribute(String friendlyName, IList`1 errors, Boolean& conflict) +106
   Owin.Loader.DefaultLoader.GetDefaultConfiguration(String friendlyName, IList`1 errors) +46
   Owin.Loader.DefaultLoader.LoadImplementation(String startupName, IList`1 errorDetails) +75
   Owin.Loader.DefaultLoader.Load(String startupName, IList`1 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 context) +106
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +534
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +352
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

这个错误最让人恼火的是 Owin-package 似乎导致了这个错误。但是根据 NuGet 文档,Owin 根本不应该引用 Microsoft.SharePoint.Client。

或者这整个轨迹是否具有误导性,而 Owin 不必对这个问题做任何事情?

【问题讨论】:

    标签: c# visual-studio dependencies owin


    【解决方案1】:

    我遇到了同样的问题。

    对我来说,通过从 bin 目录中删除导致错误的 .dll 解决了这个问题。 (在我的例子中是 Microsoft.Online.Sharepoint.Tentant.dll

    【讨论】:

      【解决方案2】:

      我也遇到了这个问题。可以通过在web.config中指定启动类来规避,这样Owin就不会去尝试搜索正确的启动类了。

      appSetting 元素覆盖 OwinStartup 属性和 命名约定。您可以有多个启动类(每个使用 OwinStartup 属性)并配置哪个启动类将是 使用类似于以下的标记加载到配置文件中:

      <appSettings>  
          <add key="owin:appStartup" value="StartupDemo.ProductionStartup" />
      </appSettings>
      

      以下键,明确指定启动类和 也可以使用汇编:

      <add key="owin:appStartup" value="StartupDemo.ProductionStartup, StartupDemo" />
      

      更多详情请见in the documentation

      【讨论】:

        猜你喜欢
        • 2012-04-14
        • 2019-06-29
        • 2020-11-03
        • 2019-11-25
        • 2012-11-30
        • 1970-01-01
        • 1970-01-01
        • 2014-12-03
        • 2016-08-11
        相关资源
        最近更新 更多