Deploying MVC4 site for Azure results in ExtensionAttribute exception

After viewing Scott Gu's address note in AspConf, I was delighted with trying to use Windows Azure websites with MVC4. I tried deploying an existing MVC application after reconfiguring it to target the .NET framework 4.0 instead of 4.5 and received the following error.

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

Since I already added a few NuGet packages, I thought this might have something to do with Ninject, so I created a new MVC project targeted at .NET 4.0 without NuGet packages and deployed to Windows Azure using Visual Studio 2012 RC publishing (right click web project) and I am still getting this error.

Does anyone know what is happening or how to solve this problem? Thanks in advance.

Including full stack trace:

[TypeLoadException: Failed to load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089.]
System.ModuleHandle.ResolveType (module RuntimeModule, Int32 typeToken, IntPtr * typeInstArgs, Int32 typeInstCount, IntPtr * methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) +0
System.ModuleHandle.ResolveTypeHandleInternal (RuntimeModule module, Int32 typeToken, RuntimeTypeHandle [] typeInstantiationContext, RuntimeTypeHandle [] method InstantiationContext) +180
System.Reflection.RuntimeModule.ResolveType (Int32 metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) +192
System.Reflection.CustomAttribute.FilterCustomAttributeRecord (CustomAttributeRecord caRecord, region MetadataImport, Assembly & lastAptcaOkAssembly, RuntimeModule ukrashenModule, MetadataToken ukrashenToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object [] attributes, IList derivatives attributes, RuntimeType & AttributeType, IRuntimeMethodInfo & ctor, Boolean & ctorHasParameters , Boolean & isVarArg) +115
System.Reflection.CustomAttribute.GetCustomAttributes (RuntimeModule ukrashennyyModule, Int32 ukrashennyyMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList Derived attributes, 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) +64 WebActivator.ActivationManager.RunActivationMethods () +143 WebActivator.ActivationManager.Run () +22

[InvalidOperationException: initializing a run before the application The Run method of type WebActivator.ActivationManager threw an exception with the following error message: Failed to 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): initializing the start before the application The Run method of type WebActivator.ActivationManager threw an exception with the following error message: Failed to load the type 'System.Runtime.CompilerServices.ExtensionAttribute' from the assembly 'mscorlib, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089 '..]
System.Web.HttpRuntime.FirstRequestInit (HttpContext context) +9090044 System.Web.HttpRuntime.EnsureFirstRequestInit (HttpContext context) +97 System.Web.HttpRuntime.ProcessRequestNotificationPrivate (IIS7WorkerRequest wr

+7
source share
3 answers

In the web application publishing wizard, if I select Settings | Delete the additional files to the destination, and this problem has disappeared.

+1
source

It seems to me that the problem is with links to .NET FX.

As per ASP.NET MVC 4 release notes, there is a problem with the nuget package for Entity Framework and downgrade from .NET 4.5 → .NET 4. http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253815

Modifying an ASP.NET MVC 4 project for target 4.0 out of 4.5 do not update the EntityFramework assembly reference: if you change ASP.NET MVC 4 for the target version 4.0, after setting 4.5 the assembly reference, EntityFramework will still point to version 4.5. To resolve this issue, uninstall and reinstall the EntityFramework NuGet package.

0
source

Another possible solution (others with the same exception) may be that your build server does not have a .net 4.0 link assembly after installing .net 4.5, you will need to copy them from your dev module.

Usually this is somewhere like:

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

For more, see Marc's Blog Entry .

0
source

All Articles