2017-07-31 70 views
2

我有兩個庫。一個消耗另一個,消費庫本身被Web應用使用。 Web應用程序返回下面的錯誤,而實例化類型的代碼(摻雜JWT簽名驗證)在兩個庫的單元測試中都成功執行。庫,應用程序是目標框架.NET 4.5.2我驗證了的Web應用程序的.csproj的文件中有一個有效的參考無法加載類型'System.IdentityModel.Tokens.JwtSecurityToken'

<Reference Include="System.IdentityModel.Tokens.Jwt, Version=5.1.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">  <HintPath>..\packages\System.IdentityModel.Tokens.Jwt.5.1.4\lib\net451\System.IdentityModel.Tokens.Jwt.dll</HintPath> 
</Reference> 

我不覺得在GAC大會除去

C:\Program Files (x86)\Microsoft Visual Studio 11.0>gacutil /u System.IdentityMo 
del.Tokens.Jwt 
Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.17929 
Copyright (c) Microsoft Corporation. All rights reserved. 

No assemblies found matching: System.IdentityModel.Tokens.Jwt 
Number of assemblies uninstalled = 0 
Number of failures = 0 

我已經嘗試清理,重建,重新啓動,刪除/ bin和/ lib並重建,並且無所適從。就個人而言,這本身可能不是System.IdentityModel.Tokens.Jwt,但是我需要關於類型加載錯誤等疑難解答的指導。我已明確resintalled的.Tokens包以及所有套餐:

nuget install packages.config 

我仍然得到錯誤,而不是身材,而是隻執行:

Server Error in '/' Application. 

Could not load type 'System.IdentityModel.Tokens.JwtSecurityToken' from assembly 'System.IdentityModel.Tokens.Jwt, Version=5.1.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.TypeLoadException: Could not load type 'System.IdentityModel.Tokens.JwtSecurityToken' from assembly 'System.IdentityModel.Tokens.Jwt, Version=5.1.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. 

Source Error: 


Line 12:  protected void Application_Start(object sender, EventArgs e) 
Line 13:  { 
Line 14:  GlobalConfiguration.Configure(WebApiConfig.Register); 
Line 15:  } 
Line 16: 

Source File: C:\Dev\Git\Connect-Applications\ControllerlessApp\src\Connect.Rest.MainApp\Global.asax.cs Line: 14 

Stack Trace: 


[TypeLoadException: Could not load type 'System.IdentityModel.Tokens.JwtSecurityToken' from assembly 'System.IdentityModel.Tokens.Jwt, Version=5.1.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.] 
    System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes) +0 
    System.Reflection.RuntimeAssembly.GetExportedTypes() +31 
    Plex.Web.UI.ServiceResolverDefaults..ctor() +842 

[TargetInvocationException: Exception has been thrown by the target of an invocation.] 
    System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0 
    System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +138 
    System.Activator.CreateInstance(Type type, Boolean nonPublic) +105 
    System.Activator.CreateInstance(Type type) +12 
    Plex.Activation.AssemblyDefaultRegistrationConvention.Process(Type type, Registry registry) +118 
    StructureMap.StringExtensions.Each(IEnumerable`1 enumerable, Action`1 action) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Extensions.cs:10 
    StructureMap.StringExtensions.Each(IEnumerable`1 enumerable, Action`1 action) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Extensions.cs:10 
    StructureMap.Graph.AssemblyScanner.ScanForAll(PluginGraph pluginGraph) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Graph\AssemblyScanner.cs:248 
    StructureMap.Graph.PluginGraph.Seal() in c:\BuildAgent\work\767273992e840853\src\StructureMap\Graph\PluginGraph.cs:121 
    StructureMap.PluginGraphBuilder.Build() in c:\BuildAgent\work\767273992e840853\src\StructureMap\PluginGraphBuilder.cs:72 
    StructureMap.Container..ctor(Action`1 action) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Container.cs:25 
    Plex.Activation.ServiceResolverBuilder.Initialize(ApplicationContext context) +288 
    Connect.Rest.Framework.Hosting2.Infrastructure.AppDomainSharedServices.get_ServiceResolver() +1373 
    Connect.Rest.Framework.Hosting2.WebApiConfig.Register(HttpConfiguration config) +80 
    System.Web.Http.GlobalConfiguration.Configure(Action`1 configurationCallback) +63 
    Connect.Rest.MainApp.WebApiApplication.Application_Start(Object sender, EventArgs e) in C:\Dev\Git\Connect-Applications\ControllerlessApp\src\Connect.Rest.MainApp\Global.asax.cs:14 

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.] 
    System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +544 
    System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +186 
    System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172 
    System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +402 
    System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +343 

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.] 
    System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +579 
    System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +112 
    System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +716 
+0

你發佈到bin文件夾中智威湯遜庫? – Gusman

+0

謝謝@Gusman我所做的就是從基礎庫中獲取所有DLL實例化這種類型,並完成所有必需的DLL並將它們複製到應用程序的bin。這導致行爲沒有變化。 –

回答

相關問題