Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling while loading types from assembly #22

Merged
merged 1 commit into from Sep 1, 2013

Conversation

jni-
Copy link
Contributor

@jni- jni- commented Aug 28, 2013

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 added a commit that referenced this pull request Sep 1, 2013
Error handling while loading types from assembly
@Daniel15 Daniel15 merged commit ca8a51d into Daniel15:master Sep 1, 2013
@Daniel15
Copy link
Owner

Daniel15 commented Sep 1, 2013

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-
Copy link
Contributor Author

jni- commented Sep 1, 2013

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
Copy link
Owner

Daniel15 commented Sep 1, 2013

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-
Copy link
Contributor Author

jni- commented Sep 1, 2013

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 added a commit that referenced this pull request Sep 4, 2013
… only return the types that were loaded successfully. Closes #22 and #24
@Daniel15
Copy link
Owner

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

@jni-
Copy link
Contributor Author

jni- commented Sep 10, 2013

thank you!

@jni- jni- deleted the fix-gettypes branch September 10, 2013 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants