Daniel15 / RouteJs

JavaScript URL routing for ASP.NET MVC and WebForms
84 stars 19 forks source link

Error handling while loading types from assembly #22

Closed jni- closed 11 years ago

jni- commented 11 years ago

Some assemblies on our project gives us a headache while it comes to loading types from assemblies in the appdomain. Actually only one does, PdfSharp. You may list PdfSharp's assembly from the appdomain, but once you call assembly.GetTypes() on it, it throws a ReflectionTypeLoadException. We're trying to see why it is like that, but in the mean time I think it simply makes RouteJs a tiny bit more robust anyways, so I'm submitting this fix.

I am not including a test for this fix, since I have no idea how to reproduce it without adding a dependency to a faulty assembly (and I'm not sure how to reproduce that).

Here is the complete error we had, I tried to translate the relevant parts :

RouteJs.TinyIoc.TinyIoCResolutionException: Unable to resolve type: RouteJs.Mvc.MvcRouteFilter ---> System.Reflection.TargetInvocationException: An exception was throw by the target. ---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the required types. See the LoaderExceptions property for more information.
   à System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   à System.Reflection.RuntimeModule.GetTypes()
   à System.Reflection.Assembly.GetTypes()
   à RouteJs.Mvc.MvcRouteFilter.<BuildLists>b__0(Assembly assembly)
   à System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
   à System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   à System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   à System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   à RouteJs.Mvc.MvcRouteFilter.BuildLists()
Daniel15 commented 11 years ago

Thanks, I'll have to investigate further and see what's causing the issue, but I'm happy with this as an interim fix. You should be able to download a NuGet package with this fix as soon as the build server builds it.

jni- commented 11 years ago

Hi, thanks for the merge! The error wasn't coming from your side, it's one of our assemblies that caused this issue. We pretty much gave up figuring out the details of that.

Daniel15 commented 11 years ago

Did you try catching the ReflectionTypeLoadException exception and looking at the LoaderExceptions property? Perhaps my code is doing something wrong that PdfSharp doesn't like.

That exception is one of my most hated exceptions. I've seen it in production systems a few times, but the LoaderExceptions property is never logged and its details aren't in the ToString() of the exception so they're pretty tricky to figure out.

jni- commented 11 years ago

Yes I did manage to catch it in the debugger, but it still made no sense at all (can't remember it though). And I don't this it's your code, we have some assembly scanning code as well that looks pretty much identical to yours, and the same thing happens with the same assembly. I might give it another go this week, just because it bugs me. It's not easy to catch either, since all of this happens on the Application_Start(), but I have a way to trick it. However since it comes from a third party assembly, it's not going to be that easy to figure out I guess.

Daniel15 commented 11 years ago

FYI @jni-, this has been fixed in the 1.1.4 release :)

jni- commented 11 years ago

thank you!