I am trying to use Enterprise Library with MVC, and it is not working. It took me a while to figure out this was the problem, because the Exception is not very descriptive.
Basically, the repro steps are:
Create a new MVC application (I make sure this application runs correctly after being created)
Add a reference to Microsoft.Practices.EnterpriseLibrary.Common (I use version 3.1.0.0)
Run the application again with no code changes
Here you get the following exception:
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
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.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
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:
[ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.] System.Reflection.Module._GetTypesInternal(StackCrawlMark& stackMark) +0 System.Reflection.Assembly.GetTypes() +96 System.Web.Mvc.MvcHandler.GetControllerType(String controller) +338 System.Web.Mvc.MvcHandler.ProcessRequest(IHttpContext httpContext) +44 System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +32 System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +4 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +358 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64
I also get a "Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information." when using Castle.Windsor and NHibernate. Anyone got the combination MVC, Castle.Windsor and NHibernate to work together?
How can I get information from LoaderExceptions below?
Br, Martin
Server Error in '/' Application.
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
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.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
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:
[ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
System.Reflection.Module._GetTypesInternal(StackCrawlMark& stackMark) +0
System.Reflection.Assembly.GetTypes() +96
System.Web.Mvc.MvcHandler.GetControllerType(String controller) +310
System.Web.Mvc.MvcHandler.ProcessRequest(IHttpContext httpContext) +154
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +55
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +28
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +358
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
Set a break point on the last brace. Run the project with debugging. When the error occures, bring up exc in a Quick Watch window and you can browse through the properties to determine what the issue is.
When I have seen this in the past it is generally a problem that a dependent assembly has not been copied to the bin\ directory of your web project. In the case of NHibernate, this could be log4net.dll, or Castle.DynamicProxy2.dll. It is very possible
that the EntLib assembly has other dependent assemblies that have not been copied to the bin\ directory.
When you figure out what the problem dlls are, simple right-click on your web project and add them as references. This will ensure that they are automatically copied to the bin\ folder as needed.
juliand
Member
2 Points
4 Posts
Enterprise Library not working with MVC
Dec 20, 2007 04:06 PM|LINK
Hi,
I am trying to use Enterprise Library with MVC, and it is not working. It took me a while to figure out this was the problem, because the Exception is not very descriptive.
Basically, the repro steps are:
Here you get the following exception:
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
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.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Source Error:
Stack Trace:
Is there a workaround for this?
robconery
Participant
852 Points
195 Posts
Re: Enterprise Library not working with MVC
Dec 20, 2007 07:26 PM|LINK
We found this error during testing - Eilon's looking into it. Thanks for letting us know :)
di97mni
Member
6 Points
10 Posts
Re: Enterprise Library not working with MVC
Dec 21, 2007 07:26 AM|LINK
I also get a "Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information." when using Castle.Windsor and NHibernate. Anyone got the combination MVC, Castle.Windsor and NHibernate to work together?
How can I get information from LoaderExceptions below?
Br, Martin
Server Error in '/' Application.
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
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.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
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:
[ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
System.Reflection.Module._GetTypesInternal(StackCrawlMark& stackMark) +0
System.Reflection.Assembly.GetTypes() +96
System.Web.Mvc.MvcHandler.GetControllerType(String controller) +310
System.Web.Mvc.MvcHandler.ProcessRequest(IHttpContext httpContext) +154
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +55
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +28
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +358
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
katokay
Member
93 Points
50 Posts
Re: Enterprise Library not working with MVC
Feb 12, 2008 03:57 PM|LINK
I hope this issue is resolved in the next CTP, or at least a workaround... All of our excitement came to a screeching halt.
Read documentation. check!
Work through custom samples. check!
Evaluate if MVC is a good fit for our organization and project. check!
Integration with existing solution. $#@&!
wcpierce
Member
47 Points
16 Posts
Re: Enterprise Library not working with MVC
Feb 12, 2008 07:56 PM|LINK
Do the following to interrogate the LoaderException.
Add this code to your Global.asax.cs:
protected void Application_Error(object sender, EventArgs e)
{
Exception exc = Server.GetLastError();
}
Set a break point on the last brace. Run the project with debugging. When the error occures, bring up exc in a Quick Watch window and you can browse through the properties to determine what the issue is.
When I have seen this in the past it is generally a problem that a dependent assembly has not been copied to the bin\ directory of your web project. In the case of NHibernate, this could be log4net.dll, or Castle.DynamicProxy2.dll. It is very possible that the EntLib assembly has other dependent assemblies that have not been copied to the bin\ directory.
When you figure out what the problem dlls are, simple right-click on your web project and add them as references. This will ensure that they are automatically copied to the bin\ folder as needed.
-Bill
ReflectionTypeLoadException LoaderExceptions
http://blechie.com/wpierce/
katokay
Member
93 Points
50 Posts
Re: Enterprise Library not working with MVC
Feb 12, 2008 11:04 PM|LINK
That helped us track down the problematic reference.
Integration with existing solution. Check!
Thanks for the help.
wcpierce
Member
47 Points
16 Posts
Re: Enterprise Library not working with MVC
Feb 12, 2008 11:16 PM|LINK
Hey katokay,
For the benefit of the others experiencing the problem, could you share what the problematic reference was?
-Bill
http://blechie.com/wpierce/