1

Closed

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

description

Setting up an existing site with N2, using NuGet package version 2.4.12.19. Not 100% sure it is N2 that causes the problems, but have you installed .NetFX 4.5 lately? You might be ILMerging it wrong. Found a great article about the problem on stackoverflow: Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib.

Failing at this code
Line 110:            var engine = MvcEngine.Create(new WindsorServiceContainer(container));

[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) +493
   System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) +43
   System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) +325
   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) +208
   System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) +1188
   System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean isDecoratedTargetSecurityTransparent) +36
   System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit) +346
   N2.Engine.<GetTypesWithAttribute>d__19`1.MoveNext() in c:\Projekt\OSS\github\n2cms\n2cms\src\Framework\N2\Engine\WebAppTypeFinder.cs:63
   System.Linq.<SelectManyIterator>d__14`2.MoveNext() +507
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +472
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +76
   N2.Engine.CachedAssembly.GetOrCreateCache(String key, Func`2 factory, Boolean& factoryInvoked) in c:\Projekt\OSS\github\n2cms\n2cms\src\Framework\N2\Engine\TypeCache.cs:31
   N2.Engine.<GetTypes>d__0.MoveNext() in c:\Projekt\OSS\github\n2cms\n2cms\src\Framework\N2\Engine\TypeCache.cs:57
   System.Linq.<SelectManyIterator>d__14`2.MoveNext() +578
   System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +148
   System.Linq.WhereEnumerableIterator`1.MoveNext() +148
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +472
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +76
   N2.Engine.ServiceRegistrator.RegisterServices(IEnumerable`1 services) in c:\Projekt\OSS\github\n2cms\n2cms\src\Framework\N2\Engine\ServiceRegistrator.cs:34
   N2.Engine.ContainerConfigurer.Configure(IEngine engine, EventBroker broker, ConfigurationManagerWrapper configuration) in c:\Projekt\OSS\github\n2cms\n2cms\src\Framework\N2\Engine\ContainerConfigurer.cs:46
   N2.Web.Mvc.MvcEngine.Create(IServiceContainer container) in c:\Projekt\OSS\github\n2cms\n2cms\src\Framework\Extensions\Web\Mvc\MvcEngine.cs:32
   NorwegianReward.Se.Web.MvcApplication.Application_Start() in c:\Reward\TeamCity\buildAgent\work\c9a1f23d61972e61\Se.Web\Web\Global.asax.cs:110

[HttpException (0x80004005): Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +587
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +1213
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +384
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +405
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +303

[HttpException (0x80004005): 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) +646
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +99
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +685
Closed Apr 8, 2013 at 10:30 PM by bherila
On Windows Server 2003, libraries may need to be recompiled from source to target .NET 4.0, as .NET 4.5 is not available on WS2003.

comments

bussemac wrote Mar 13, 2013 at 3:44 PM

It looks like someone built the 2.4.12 release of N2 on a machine that has the .Net 4.5 libraries installed. We just went through this headache ourselves. Even if you are targeting .Net 4.0, with .Net 4.5 installed, you can produce this exact error quite easily. You can be explicit to fix this... when you invoke msbuild from command line, pass the following argument:

/property:FrameworkPathOverride=C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0

As an end user, you can either: use 2.4.11.1 (works for us fine) or download the sources for 2.4.12 and build them yourself.

bussemac wrote Mar 13, 2013 at 4:09 PM

Strike that, we narrowed it down to a different library. I deployed a site running 2.4.12.9 to a server with only .net 4 and it ran fine. So check your other packages that you just updated.

ubcoder wrote Mar 14, 2013 at 6:37 PM

We actually took an easier path to "fix" the problem. We just installed .NET 4.5 :-)

bussemac wrote Mar 14, 2013 at 7:36 PM

Our production server is running Server 2003, so that's not an option. It's becoming increasingly important to watch that our third-party libraries are compiled correctly.