davidebbo / WebActivator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WebActivator throws exception with latest version of ASP.NET MVC 4

joelnet opened this issue · comments

I created a New ASP.NET MVC 4 Project and selected Web API as my template. This template installs the package Microsoft.Net.Http version 2.0.20710.0. If I upgrade this package to 2.1.10 (http://nuget.org/packages/Microsoft.Net.Http/2.1.10) WebActivator throws the following exception when I run the project...

Server Error in '/' Application.

Token 0x02000001 resolves to the special module type representing this module.
Parameter name: metadataToken

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.ArgumentException: Token 0x02000001 resolves to the special module type representing this module.
Parameter name: metadataToken

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: 


[ArgumentException: Token 0x02000001 resolves to the special module type representing this module.
Parameter name: metadataToken]
   System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) +750
   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) +1281
   System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) +1574
   System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean isDecoratedTargetSecurityTransparent) +460
   System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) +470
   System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit) +563
   WebActivatorEx.AssemblyExtensions.GetActivationAttributes(Assembly assembly) +394
   WebActivatorEx.ActivationManager.RunActivationMethods(Boolean designerMode) +490
   WebActivatorEx.ActivationManager.RunPreStartMethods(Boolean designerMode) +286
   WebActivatorEx.ActivationManager.Run() +260

[InvalidOperationException: The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: Token 0x02000001 resolves to the special module type representing this module.
Parameter name: metadataToken.]
   System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +1247
   System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +356
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +424
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +431
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1458

[HttpException (0x80004005): The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: Token 0x02000001 resolves to the special module type representing this module.
Parameter name: metadataToken.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +1037
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +392
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +578

I wasn't able to repro this. Here is my test app: https://github.com/davidebbo-test/WebActivatorBug12. Can you try with that app to see if you repro? If not, maybe there are differences with what you're doing?

It looks like it's something specific to one of the machine's here. On one machine it produces an exception, on the other machine, no exception. (aren't these fun to trouble shoot?)

I will attempt to discover the difference.

Yeah, that's a weird error; no idea what that even means! :) And very few references to it out there, so it's not at a common thing.

And if you switch back to the older Microsoft.Net.Http, it definitely doesn't happen?

Here is where WebActivator calls GetCustomAttributes: https://github.com/davidebbo/WebActivator/blob/master/WebActivator/AssemblyExtensions.cs#L12. If you debug it, you should be able to tell which specific assembly is triggering that. And then maybe you can isolate to a simple Console app repro that just does that on that assembly.

i've never seen that error before either. and ya, if i switch back to v2.0.20710.0 it starts to work again. I'll poke around it some more tomorrow.

Has anyone found out why this is happening. I am getting this error. WebActivator is added when im trying to add Ninject.MVC3 to my project. I have another project running webactivator v2.0.20710.0 and its running fine.

I'm yet to be able to repro this myself, making it hard to investigate. If you have a repro, can you try isolating it as I suggest above (calling GetCustomAttributes directly to see what assembly causes it)?

Hi David, How to i call this. Im fairly new to all of this.

For my project it only happens when i updated ALL the base MVC Internet Template then added Ninject which add WebActivator.

You can reproduce it this way.

I gave him the steps to reproduce, and it works just fine on his machine. He also gave me his project, which doesn't work on my machine. It seems to be something specific to our machines maybe like .net version or some other assembly.

This is just one of about a handful off issues I've been having on this project so I haven't had time to look into it further. I'm going to test this later.

No i think it has to do with what you have installed for your project.

Heres the debug info.. and steps to reproduce

  1. Create a MVC 4 , Targeting 4.5 Project
  2. Go to Nuget and Update ALL packages right off the bat.
  3. Add a Reference to the WebActivate Project.
  4. Run debug and BAM!!! error here is the details

T = WebActivatorEx.PreApplicationStartMethodAttribute
Assembly = System.Net.Http.Primitives, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Under CustomAttributes says assembly.CustomAttributes threw and exception of type 'System.MissingMethodException'

Hope this helps

Hmmm, interesting that you get a MissingMethodException. If you run it in debugger with Break on all Exceptions, can you maybe get more details? e.g. what specific method is missing, and from where?

I think we've established that these repro steps don't actually repro the issue on all machines, only on some.

Sorry never dont that before how to i do that in VS2012?

The error I was getting was not System.MissingMethodException, it was System.ArgumentException.

I do not believe it has to do with what is installed (nuget) in the project. I ran David's project exactly as it was, which works for him, yet I got the error message above.

@LorenDorez Try:

  • Ctrl-Alt-E
  • Click check box next to CLR Exceptions
  • Run scenario in debugger

It still breaks at the same point.

All i see digging in the Assembly object is Method not found: 'Void ..ctor(System.String)'. all associated around a ResolveModule Method

@joelnet I notice david's project wasnt using the latest versions System.Net.Http and all of its dependecies like OpenAuth etc.. that the Basic Internet Template for MVC4 comes with

@LorenDorez it contains this in the packages.config (https://github.com/davidebbo-test/WebActivatorBug12/blob/master/MvcApplication5/packages.config), which is the latest released build:

Though regardless, his project works on his machine, yet the same exact project produces the error on my machine, which is why he's not able to reproduce.

@joelnet David Pack is not using the lastest MVC See here

HIS:
MINE:

Differeences like these make all the difference.

It appears the System.Net.Http.Primitives.dll method GetCustomAttributes doesnt have or load the modules properly.

If i change From

return assembly.GetCustomAttributes(
typeof(T),
inherit: false).OfType();

To

return assembly.GetModules(false)[0].GetCustomAttributes(
typeof(T),
inherit: false).OfType();

Everything works just fine. I will try later tonight to decompile the System.Net.Http.Primitives.dll

Hmmm, interesting. What's strange is that is I evaluate a.GetModules().Length for System.Net.Http.Primitives.dll, it only finds one module. Maybe there is more than one for you?

Hi David, no just one for me as well. From what im seeing the System.Net.Http.Primitives.dll doesnt support the method call for CustomAttributes

Strange that it worked when you called assembly.GetModules(false)[0].GetCustomAttributes() instead, since in the end it's the same module.

Back to your earlier finding about it relating to Void ..ctor(System.String). Can you tell what type this ctor is supposed to be on?

I get that message when i did through the main assembly > Base > base > Base etc..

Also from what i can tell System.Net.Http.Primitives is a completely blank module, there is no actual code inside the default namespace. And ill im finding on the web is its something MS is planning to use to help with backwards compatibility for .net 40 and 4.5 apps

I really wish I could repro myself. But if all else fails, I think using assembly.GetModules(false)[0].GetCustomAttributes() should be ok. Please make sure it works well, and if so, send a pull request and I'll get it in.

Actually, an alternate approach would be to just ignore exceptions when assembly.GetCustomAttributes throws, as it really should not happen for 'normal' assemblies.

David If you do my steps you should be able to reproduce it but you need to make sure you MVC projects gets updated to the lastest version also might have to install WebTools 2012.2.

Here is how i get to the Voide

assembly > Custom Attributes (Currently says threw an ex of type 'System.MissingMethodException') > base >base> base > base (Thats Base 4 times) >

Actually a Pic probably does better..
capture

I still can't repro, but I put in a workaround to ignore GetCustomAttributes exceptions. Can you upgrade to WebActivatorEx 2.0.2 to verify that it fixes it?

Whilst I'm not a user of WebActivator I have encountered the very same issue in my own app and came across this thread when trying to work out the cause. I am running some of the prerelease ASP.Net bits - I suspect some of them are relying on other ASP.Net bits that haven't yet been released and the problem will end up righting itself in the coming days as new nightly packages get published. (at least I'm hoping!)

Hi David this updates works on my test. Now i just need to get ninject to update the reference/dependency to this new version.

If i knew how to upload to GIT i could upload my test project for you try try an reproduce

David i think i figured out how to upload/make repositories on here...

https://github.com/LorenDorez/WebActivator-Test

I had to create a New WebAppTest as you wasnt working correctly. See if you can download that and reproduce

Note from above that @joelnet was able to repro with my test app, while I wasn't. So we know it is not simply a function of the app, but some other machine factors (that we don't understand) come into play as well.

In any case, hopefully with the fix it's not longer an issue. Note that you shouldn't need to get ninject to update (although they should). All you have to do is update the WebActivator NuGet package in your solution, and everything should be fine.

@IanYates I hope you're right, but I wouldn't bet on it given how poorly we understand the issue. The team may not know about it at all.

I do have JustMock installed as part of the Telerik DevCraft suite but haven't made any use of JustMock itself yet. I'll remove it and see what happens. I found a couple of other links on the net for this issue from some time back to do with Delphi's ill-fated .NET product and I think the root cause was possibly similar (attributes from a non-existent or misbehaving assembly)
Cheers for the tip! Much appreciated :)

Interesting ill uninstalled JustTrace and run some more tests this weekend.

Oh, so is the Theory that this Telerik software was the root of this issue? Does everyone on this thread who ran into the WebActivator issue have this software installed?

@davidebbo

I have JustMock installed. I just uninstalled all Telerik products and the test project you gave me ran just fine.

I have since downloaded the latest version of JustMock and after reinstalling, things still seem to be working fine.

My problem appears to have been some sort of conflict with JustMock, WebActivator and HttpClient.

Thanks for your help!

Cool. Well, I have the fix in WebActivator anyway, so hopefully we won't see this again!

@joelnet, can you confirm what version of JustMock you installed in which the problem was resolved?

I just installed the latest. The version is 2013.1.507.0

I had the same problem. BTW, you have to actually uninstall JustMock from add and remove programs, disabling it doesn't help.

I've updated to the latest JustMock and the problem has gone away for me too.