Issue with SimpleInjector.Integration.Web using .NET Framework 4.0

Dec 7, 2012 at 11:25 AM
Edited Dec 7, 2012 at 11:31 AM

I'm trying to build an ASP.NET MVC site that uses the .NET Framework 4.0, but am getting the following error message when my application starts:

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

Removing the references to SimpleInjector.Integration.Web{.Mvc} stops the error from occurring, which is why I think it's those assemblies with the problem. Google tells me that this happens when you try to use a .NET Framework 4.5 assembly with .NET Framework 4.0.

Is Simple Injector compatible with .NET Framework 4.0 or do I need to install 4.5? I'm installing .NET Framework 4.5 now to see if that fixes the issue. I'm still on Visual Studio 2010 so can't actually use .NET Framework 4.5 in my app.

UPDATE: Just the presence of .NET Framework 4.5 on my computer is enough to fix the issue (my app is still running under .NET Framework 4.0 I believe - At least VIsual Studio says it is). Using SimpleInjector.Integration.Web on a computer that doesn't have .NET Framework 4.5 installed is broken. Count this as a bug report. :P

Coordinator
Dec 7, 2012 at 11:43 AM
Simple Injector core libraries are developed for .NET 3.5 and the integration packages such as Web and Web.Mvc are developed for .NET 4.0 and up.

I and many others are using these integration packages successful with both .NET 4.0 and 4.5.

Did you perhaps have some special configuration in you web.config that could cause this? For instance configuration to rebind certain assemblies?
Dec 7, 2012 at 11:47 AM

Nothing special in my Web.config: http://pastebin.ws/3j78j2

Like I mentioned, just installing .NET Framework 4.5 was enough to make the error go away for me. It only seemed to occur when I did not have .NET Framework 4.5 installed. Seems to be working in Mono too (which uses .NET Framework 4.5).

Here are all the NuGet packages I have installed - Perhaps it's only a coincidence and one of the other packages is causing this issue.

<package id="dotless" version="1.3.1.0" targetFramework="net40" />
<package id="Microsoft.AspNet.Mvc" version="4.0.20710.0" targetFramework="net40" />
<package id="Microsoft.AspNet.Razor" version="2.0.20710.0" targetFramework="net40" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.0.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebPages" version="2.0.20710.0" targetFramework="net40" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
<package id="MySql.Data" version="6.5.4" targetFramework="net40" />
<package id="ServiceStack.Common" version="3.9.28" targetFramework="net40" />
<package id="ServiceStack.OrmLite.MySql" version="3.9.28" targetFramework="net40" />
<package id="ServiceStack.Text" version="3.9.29" targetFramework="net40" />
<package id="SimpleInjector" version="1.6.0.12319" targetFramework="net40" />
<package id="SimpleInjector.Extensions" version="1.6.0.12319" targetFramework="net40" />
<package id="SimpleInjector.Integration.Web" version="1.6.0.12319" targetFramework="net40" />
<package id="SimpleInjector.MVC3" version="1.6.0.12319" targetFramework="net40" />
<package id="T4MVC" version="3.0.3" targetFramework="net40" />
<package id="T4MVCExtensions" version="3.0.3" targetFramework="net40" />
<package id="WebActivator" version="1.4.4" targetFramework="net40" />
<package id="WebGrease" version="1.1.0" targetFramework="net40" />

 

Dec 10, 2012 at 1:12 PM

Hi there! I confirm that there is the issue with version 1.6.0, when I downgraded SimpleInjector to ver 1.5.0 the error dissapeared. Using Framework 4.5 is not an option in my case as I use WinXP sp 3. Please make sure that Framework 4.5 is not a requirement. Thanks a lot in advance.

Coordinator
Dec 10, 2012 at 10:03 PM

Since the application fails at runtime, can you supply me with a stack trace?

Dec 11, 2012 at 4:19 AM
Trace is below:


Server Error in '/' Application.

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

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.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[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) +113
   WebActivator.ActivationManager.RunActivationMethods() +216
   WebActivator.ActivationManager.RunPreStartMethods() +28
   WebActivator.ActivationManager.Run() +55

[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) +9088636
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +258


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272



Best regards,
Alexander



On Tue, Dec 11, 2012 at 3:03 AM, dot_NET_junkie <notifications@codeplex.com> wrote:

From: dot_NET_junkie

Since the application fails at runtime, can you supply me with a stack trace?

Read the full discussion online.

To add a post to this discussion, reply to this email (simpleinjector@discussions.codeplex.com)

To start a new discussion for this project, email simpleinjector@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Coordinator
Dec 11, 2012 at 5:27 PM

I’m really anxious to solve this issue asap, but I need more info. Aoz, can you supply me with the list of NuGet packages that you installed? Which version of VS are you running and on which OS do you run this?

Dec 12, 2012 at 6:09 AM
Hi Junkie! Thank you for your help ))

==========================
Microsoft Visual Studio 2010
Version 10.0.40219.1 SP1Rel

Microsoft .NET Framework
Version 4.0.30319 SP1Rel

Installed Version: Ultimate

Windows XP Professional SP3


<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Iesi.Collections" version="3.2.0.4000" targetFramework="net40" />
<package id="jQuery" version="1.8.3" targetFramework="net40" />
<package id="jQuery.UI.Combined" version="1.9.2" targetFramework="net40" />
<package id="jQuery.Validation" version="1.9.0.1" targetFramework="net40" />
<package id="json2" version="1.0.2" targetFramework="net40" />
<package id="knockoutjs" version="2.2.0" targetFramework="net40" />
<package id="Microsoft.AspNet.Mvc" version="4.0.20710.0" targetFramework="net40" />
<package id="Microsoft.AspNet.Razor" version="2.0.20715.0" targetFramework="net40" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.0-alpha1" targetFramework="net40" />
<package id="Microsoft.AspNet.WebApi" version="4.0.20710.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebApi.Client" version="4.1.0-alpha-120809" targetFramework="net40" />
<package id="Microsoft.AspNet.WebApi.Core" version="4.0.20710.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="4.0.20710.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebPages" version="2.0.20710.0" targetFramework="net40" />
<package id="Microsoft.jQuery.Unobtrusive.Ajax" version="2.0.20710.0" targetFramework="net40" />
<package id="Microsoft.jQuery.Unobtrusive.Validation" version="2.0.20710.0" targetFramework="net40" />
<package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net40" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
<package id="Modernizr" version="2.6.2" targetFramework="net40" />
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net40" />
<package id="NHibernate" version="3.3.2.4000" targetFramework="net40" />
<package id="NHibernate.Caches.SysCache" version="3.2.0.4000" targetFramework="net40" />
<package id="SimpleInjector" version="1.6.0.12319" targetFramework="net40" />
<package id="SimpleInjector.Extensions" version="1.6.0.12319" targetFramework="net40" />
<package id="SimpleInjector.Integration.Web" version="1.6.0.12319" targetFramework="net40" />
<package id="SimpleInjector.MVC3" version="1.6.0.12319" targetFramework="net40" />
<package id="WebActivator" version="1.5.2" targetFramework="net40" />
<package id="WebGrease" version="1.3.0" targetFramework="net40" />
</packages>
Coordinator
Dec 12, 2012 at 11:33 AM

I want to let you know that I was able to reproduce this error and I'm working on a fix.

Coordinator
Dec 12, 2012 at 11:36 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Dec 12, 2012 at 2:08 PM

I'm happy to report the problem is fixed. A new release is published here on CodePlex and new packages are published on NuGet. I'm sorry for the inconvenience.

Marked as answer by dot_NET_Junkie on 11/4/2013 at 2:04 AM
Dec 13, 2012 at 5:39 AM

Thank you for your help. Everything work as expected. Спасибо ))