5
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.Assembly.GetTypes()
   at Microsoft.Tools.SvcHost.ServiceHostHelper.LoadServiceAssembly(String svcAssemblyPath)

How can I loop through LoaderExceptions property to see what errors have occured as it is not hitting any service and give me this error before it runs any code?

Thanks

Leo
  • 1,547
  • 3
  • 24
  • 40
  • Try inspecting the `.InnerException` property recursively. – marc_s Feb 08 '11 at 09:37
  • For what its worth, I experienced a similar problem when trying to debug a webservice local. I never did resolve the issue, however it was important to note that the project was hosting two services. Once you clicked on the service in IE that you wanted to debug, the symbols seemed to be available. – Todd Richardson Apr 14 '11 at 21:07
  • I had this same issue. On my local pc the client and the hosted wcf service works fine. When I deploy to Windows 2008 server the client give me this error "Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information." – Diganta Kumar Oct 24 '13 at 03:25

2 Answers2

11

I managed to fix the problem. One of my project was set to x86 and others were set to Any CPU. Changing all to Any CPU fixed the problem for me.

Thanks

Leo
  • 1,547
  • 3
  • 24
  • 40
3

The solution was different for me. This may be obvious information to people who are even passingly familiar with WCF development. But in the hopes that it will help other novices struggling with the same problem, here is what I figured out.

It turned out the app I was debugging didn't need WcfSvcHost.exe at all. WcfSvcHost.exe is for self-hosted WCF applications. This app used services exposed as an endpoint on a web application.

What finally clued me in to this was this: First, this screen would show up:

Screenshot of error message "WcfSvcHost encountered a critical error and must exit."

I noticed this shows up as a separate process for WcfSvcHost.exe in the Windows Task Manager. This explained why I couldn't get the debugger to break even when I adjusted Exception Settings to break when System.Reflection.ReflectionTypeLoadException was thrown. Visual Studio wasn't breaking because it was not attached to the WcfSvcHost.exe process. It was attached to the IISExpress.exe process that was running my app. But the WcfSvcHost.exe process was throwing the exception.

When I clicked the OK button on the error message above, the WcfSvcHost.exe process would exit and no longer appear in Task Manager. But the app was still running fine. So clearly whatever is happening isn't needed. A quick check with another developer confirmed that the app didn't require self-hosted WCF services.

For some reason, Visual Studio was starting WcfSvcHost.exe anyway. And that finally led me to this answer. WCF class library projects can be configured to launch WcfSvcHost.exe whenever debugging starts.

The answer is to right-click on each WCF class library project, choose Properties, and click on the "WCF Options" tab. Then uncheck Start WCF Service Host when debugging another project in the same solution.

Screenshot of WCF class library Properties page, WCF Options tab

You must do this for all WCF class libraries in your solution. I wasn't sure which ones were which, so I just looked at the Properties for each class library and fixed the ones that had the WCF Options tab.

Katie Kilian
  • 6,815
  • 5
  • 41
  • 64
  • 1
    Thank you @Charlie, I added a NET CORE API project in the same solution of WCF project and every time I start the new project I receive this error. Your solution works perfectly – E.Benedos Jun 16 '20 at 09:55