Programing

어셈블리 'mscorlib에서'System.Runtime.CompilerServices.ExtensionAttribute '유형을로드 할 수 없습니다.

crosscheck 2020. 6. 21. 19:45
반응형

어셈블리 'mscorlib에서'System.Runtime.CompilerServices.ExtensionAttribute '유형을로드 할 수 없습니다.


웹 사이트를 처음 시작할 때이 오류가 발생합니다

Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

내가 뭘 잘못하고 있죠?

.NET 4를 사용하고 있으며 Visual Studio에서 사이트를 시작하고 있습니다.

내가 최근에 변경 한 유일한 것은 내 프로젝트에 Simple Injector (Nuget을 통해)를 추가하는 것입니다.

스택 추적은 다음과 같습니다

[TypeLoadException: Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.]
   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) +180
   System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) +192
   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) +115
   System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) +426
   System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) +103
   System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit) +64
   WebActivator.AssemblyExtensions.GetActivationAttributes(Assembly assembly) +132
   WebActivator.ActivationManager.RunActivationMethods() +216
   WebActivator.ActivationManager.RunPreStartMethods() +43
   WebActivator.ActivationManager.Run() +69

[InvalidOperationException: The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'..]
   System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +423
   System.Web.Compilation.BuildManager.CallPreStartInitMethods() +306
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +677

[HttpException (0x80004005): The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'..]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9090876
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +258

모든보기의 첫 번째 줄이 강조 표시되고 마우스를 올리면이 오류가 발생합니다

The pre-application start initialisation method Run on type WebActivator.ActivationManager threw an exception with the following error message Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

어셈블리 mscorlib에서 'System.Runtime.CompilerServices.ExtensionAttribute'유형을로드 할 수 없습니다.

예. .NET 4.5 대신 .NET 4.0에서 코드를 실행할 때 기술적으로 잘못 될 수 있습니다. .NET 4.5에서는 특성이 System.Core.dll에서 mscorlib.dll로 이동되었습니다. 100 % 호환되는 프레임 워크 버전에서는 다소 불쾌한 변화처럼 들리지만 [TypeForwardedTo] 특성은이 차이를 눈에 띄지 않게해야합니다.

머피가 가지고 있듯이, 이와 같은 모든 의도 된 변경에는 아무도 생각하지 못한 하나 이상의 실패 모드가 있습니다. ILMerge를 사용하여 여러 어셈블리를 하나로 통합하고 해당 도구를 잘못 사용한 경우에는 잘못된 것으로 보입니다. 이 파손을 설명하는 좋은 피드백 기사 가 여기 있습니다 . 실수를 설명 하는 블로그 게시물로 연결됩니다 . 다소 긴 기사이지만 올바르게 해석하면 잘못된 ILMerge 명령 줄 옵션으로 인해이 문제가 발생합니다.

  /targetplatform:"v4,c:\windows\Microsoft.NET\Framework\v4.0.30319"

어느 것이 맞지 않습니다. 프로그램을 빌드하는 머신에 4.5를 설치하면 해당 디렉토리의 어셈블리가 4.0에서 4.5로 업데이트되고 더 이상 4.0을 대상으로하기에 적합하지 않습니다. 이러한 어셈블리는 더 이상 존재하지 않아야하지만 컴 파트 이유 때문에 유지되었습니다. 올바른 참조 어셈블리는 다른 곳에 저장된 4.0 참조 어셈블리입니다.

  /targetplatform:"v4,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0"

따라서 가능한 해결 방법은 빌드 시스템에서 4.0으로 돌아가 대상 시스템과 실제 수정에 .NET 4.5를 설치하고 제공된 소스 코드에서 프로젝트를 다시 빌드하여 ILMerge 명령을 수정하는 것입니다.


이 실패 모드는 ILMerge에만 해당되는 것이 아니라 매우 일반적인 경우입니다. 이러한 4.5 어셈블리가 4.0을 대상으로하는 프로젝트에서 참조 어셈블리로 사용되는 다른 시나리오는 같은 방식으로 실패 할 수 있습니다. 다른 질문으로 판단 할 때 또 다른 일반적인 실패 모드는 유효한 VS 라이센스를 사용하지 않고 설정 한 빌드 서버입니다. 다중 타겟팅 팩이 무료로 다운로드 되는 것을 간과합니다 .

c : \ program files (x86) 하위 디렉토리에서 참조 어셈블리를 사용하는 것은 어려운 요구 사항입니다. .NET 4.0부터는 4.01, 4.02 및 4.03 릴리스에 추가 된 클래스 나 메소드에 실수로 의존하지 않도록하는 것이 중요합니다. 그러나 4.5가 릴리스 된 지금 절대적으로 필수적입니다.


로드 할 수없는 유형이 System.Reflection.AssemblyMetadataAttribute 인 것을 제외 하고는이 문제가있었습니다. 웹 응용 프로그램은 대상 프레임 워크가 4.0 인 .NET 4.5가 설치되어 (여기서 잘 실행 됨) 컴퓨터에 구축되었지만 4.0 만 설치된 웹 서버에서 실행될 때 오류가 발생했습니다. 그런 다음 4.5가 설치된 웹 서버에서 시도했지만 오류가 없었습니다. 다른 사람들이 말했듯이, 이것은 모두 Microsoft가 4.5를 출시 한 나사 방식으로 인한 것입니다. 이는 기본적으로 버전 4.0으로의 업그레이드 (및 덮어 쓰기)입니다. System.Reflection 어셈블리는 4.0 (AssemblyMetadataAttribute)에없는 형식을 참조하므로 새 System.Reflection.dll이 없으면 실패합니다.

You can either install .NET 4.5 on the target web server, or build the application on a machine that does not have 4.5 installed. Far from an ideal resolution.


I had this exact same problem with a site (Kentico CMS), starting development in 4.5, finding out the production server only supports 4.0, tried going back down to target framework of 4.0. Compiling the other posts in this thread (specifically changing target framework to .Net 4 and .Net 4.5 still being referenced). I searched through my solution and found that a handful of the NuGet packages were still using libraries with targetFramework="net45".

packages.config (before):
<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="AutoMapper" version="3.1.0" targetFramework="net45" />
  <package id="EntityFramework" version="5.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.0.0" targetFramework="net45" />
  <package id="Newtonsoft.Json" version="4.5.11" targetFramework="net45" />
</packages>

I changed the projects target framework back to 4.5, removed all NuGet libraries, went back down to 4.0 and re-added the libraries (had to use some previous versions that were not dependent on 4.5).

packages.config (after):
<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="AutoMapper" version="3.1.1" targetFramework="net40" />
  <package id="EntityFramework" version="6.0.2" targetFramework="net40" />
  <package id="Microsoft.AspNet.WebApi.Client" version="4.0.30506.0" targetFramework="net40" />
  <package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net40" />
  <package id="Newtonsoft.Json" version="4.5.11" targetFramework="net40" />
</packages>

I just ran into this annoying problem today. We use SmartAssembly to pack/obfuscate our .NET assemblies, but suddenly the final product wasn't working on our test systems. I didn't even think I had .NET 4.5, but apparently something installed it about a month ago.

I uninstalled 4.5 and reinstalled 4.0, and now everything is working again. Not too impressed with having blown an afternoon on this.


I did encounter the same problem while trying to read data from a Firebird Database. After many hours of searching, I found out that the problem was caused by an error I made in the query. Fixing it made it work perfectly. It had nothing to do with the version of the Framework


We ran into this problem and tracked it down to the Geocoding.net NuGet package that we were using to help with our Google Maps views (Geocoding.net version 3.1.0 published 2/4/2014).

The Geocoding dll appears to be .Net 4.0 when you examine the package file or view it using Jet Brains’ Dot Peek application; however, a colleague of mine says that it was compiled using ilmerge so it is most likely related to the ilmerge problems listed above.

It was a long process to track it down. We fetched different changesets from TFS till we narrowed it down to the changeset that added the aforementioned NuGet package. After removing it, we were able to deploy to our .NET 4 server.


In my case after downgrading from .NET 4.5 to .NET 4.0 project was working fine on a local machine, but was failing on server after publishing.

Turns out that destination had some old assemblies, which were still referencing .NET 4.5.

Fixed it by enabling publishing option "Delete all existing files prior to publish"


In my case, it was Blend SDK missed out on TeamCity machine. This caused the error due incorrect way of assembly resolving then.


Just adding this answer to help Google save some punter the hours I have spent to get here. I used ILMerge on my .Net 4.0 project, without the /targetplatform option set, assuming it would be detected correctly from my main assembly. I then had complaints from users only on Windows XP aka WinXP. This now makes sense as XP will never have > .Net 4.0 installed whereas most newer OSes will. So if your XP users are having issues, see the fixes above.


In my case I had an issue around using Microsoft.ReportViewer.WebForms. I removed validate=true from add verb line in web.config and it started working:

<system.web>
    <httpHandlers>
      <add verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

참고URL : https://stackoverflow.com/questions/13748055/could-not-load-type-system-runtime-compilerservices-extensionattribute-from-as

반응형