需要帮助解决.NET webapi2应用程序启动

时间:2017-09-12 12:53:04

标签: asp.net .net-assembly typeloadexception

我有一个有效的webapi2应用程序,它引用了我们拥有的一些常见/共享库程序集。这些共享库具有不同的存储库,并且它们在构建过程中作为nuget包发布。最近,我将webapi2应用程序的nuget包引用更新为这些常见包的更新版本。其中一个程序集的较新版本Microsoft.Icm.Common.Web不再具有属性WebApiExceptionHandlerAttribute。因此,在构建webapi2应用程序时,我在webapi2控制器类中删除了对该属性的所有引用。当我重新构建应用程序并将其部署到我们的一个临时环境时,我看到以下类型加载异常:

消息:无法加载类型' Microsoft.Icm.Common.Web.WebApiExceptionHandlerAttribute'来自assembly' Microsoft.Icm.Common.Web,Version = 2.4.0.0,Culture = neutral,PublicKeyToken = null'。

StackTrace:在System.ModuleHandle.ResolveType(RuntimeModule模块,Int32 typeToken,IntPtr * typeInstArgs,Int32 typeInstCount,IntPtr * methodInstArgs,Int32 methodInstCount,ObjectHandleOnStack类型)    在System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule模块,Int32 typeToken,RuntimeTypeHandle [] typeInstantiationContext,RuntimeTypeHandle [] methodInstantiationContext)    在System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken,Type [] genericTypeArguments,Type [] genericMethodArguments)    at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord,MetadataImport scope,Assembly& lastAptcaOkAssembly,RunadataModule decoratedModule,MetadataToken decoratedToken,RuntimeType attributeFilterType,Boolean mustBeInheritable,Object [] attributes,IList derivedAttributes,RuntimeType& attributeType,IRuntimeMethodInfo& ctor,Boolean& ctorHasParameters ,布尔& isVarArg)    在System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule,Int32 decoratedMetadataToken,Int32 pcaCount,RuntimeType attributeFilterType,Boolean mustBeInheritable,IList derivedAttributes,Boolean isDecoratedTargetSecurityTransparent)    在System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType类型,RuntimeType caType,布尔继承)    在System.Web.Http.Controllers.HttpControllerDescriptor.InvokeAttributesOnControllerType(HttpControllerDescriptor controllerDescriptor,Type type)    在System.Web.Http.Controllers.HttpControllerDescriptor..ctor(HttpConfiguration配置,字符串controllerName,类型controllerType)    在System.Web.Http.Dispatcher.DefaultHttpControllerSelector.InitializeControllerInfoCache()    在System.Lazy 1.CreateValue() at System.Lazy 1.LazyInitValue()    在System.Web.Http.Dispatcher.DefaultHttpControllerSelector.GetControllerMapping()    在System.Web.Http.Routing.AttributeRoutingMapper.AddRouteEntries(SubRouteCollection collector,HttpConfiguration配置,IInlineConstraintResolver constraintResolver,IDirectRouteProvider directRouteProvider)    在System.Web.Http.Routing.AttributeRoutingMapper。<> c__DisplayClass2。<> c__DisplayClass4.b__1()    在System.Web.Http.Routing.RouteCollectionRoute.EnsureInitialized(Func`1初始化程序)    在System.Web.Http.Routing.AttributeRoutingMapper。<> c__DisplayClass2.b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在System.Web.OData.Routing.Conventions.AttributeRoutingConvention。<> c__DisplayClass1。< .ctor> b__0(HttpConfiguration config)    在E:\ bt \ 787852 \ repo \ src \ OData \ ICMV3OData \ Global.asax.cs中的Microsoft.AzureAd.Icm.IcmV3OData.Global.Initialize():第66行    在E:\ bt \ 787852 \ repo \ src \ OData \ ICMV3OData \ App_Start \ PreLoadInitializationClient.cs中的Microsoft.AzureAd.Icm.IcmV3OData.PreLoadInitializationClient.Preload(String []参数):第40行    在System.Web.Hosting.PreloadHost.CreateIProcessHostPreloadClientInstanceAndCallPreload(String preloadObjTypeName,String [] paramsForStartupObj)    在System.Web.Hosting.PreloadHost.CreateIProcessHostPreloadClientInstanceAndCallPreload(String preloadObjTypeName,String [] paramsForStartupObj)    在System.Web.Hosting.ProcessHost.PreloadApplicationIfRequired(String appId,IApplicationHost appHostParameter,HostingEnvironmentParameters hostingParameters,LockableAppDomainContext ac)'。工作进程将被标记为不健康并将被关闭。数据字段包含错误代码。

即使我最近构建的webapi2应用程序不再引用不可用的WebApiExceptionHandlerAttribute(在较新的Microsoft.Icm.Common.Web程序集中),但在运行应用程序时,看起来似乎正在使用不可用的属性。我使用了像Resharper的dotnetpeek这样的工具并搜索了术语" WebApiExceptionHandlerAttribute"在binplaced程序集中,我没有看到该属性的任何匹配项。那么,我如何弄清楚为什么Web应用程序仍然试图在应用程序启动时找到该类型?

1 个答案:

答案 0 :(得分:0)

我已找出此问题的根本原因。看起来我在webapi2应用程序的bin文件夹中有另一个陈旧的程序集,它已经被弃用了近3个月,并且在构建应用程序时不再生成。陈旧的程序集引用了现在已经不存在的属性。一旦我从iis webapi2应用程序文件夹中删除过时的程序集,事情就开始正常了。