WcfSVCHost has encountered a critical error and should exit. This may be caused by an invalid configuration file.

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 go through the LoaderExceptions property to find out what errors have occurred since it does not get into any service and does not give me this error before I run any code?

thanks

+4
source share
2 answers

I managed to solve the problem. One of my projects was configured on x86, while others were configured on any processor. Changing everything to any processor, I solved the problem.

thanks

+9
source

The decision was different for me. This may be obvious information for people who are even fleetingly familiar with the development of WCF. But in the hope that this will help other newcomers struggling with the same problem, that’s what I understood.

It turned out that the application that I was debugging did not need WcfSvcHost.exe at all. WcfSvcHost.exe for standalone WCF applications. This application used the services presented as the endpoint in the web application.

In the end, I realized what it is: firstly, this screen will appear:

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

I noticed that this appears as a separate process for WcfSvcHost.exe in the Windows task manager. This explained why I could not get the debugger to work without crashing even when I configured the exception parameters so that they would break when a System.Reflection.ReflectionTypeLoadException exception occurred. Visual Studio did not break because it was not attached to the WcfSvcHost.exe process. It was attached to the IISExpress.exe process on which my application was running. But the WcfSvcHost.exe process threw an exception.

When I clicked the β€œOK” button in the error message above, the WcfSvcHost.exe process terminated and no longer appeared in the task manager. But the application still worked fine. It is so clear that what is happening is not necessary. A quick check with another developer confirmed that the application does not require its own WCF services.

For some reason, Visual Studio still ran WcfSvcHost.exe. And this finally led me to this answer . You can configure WCF class library projects to run WcfSvcHost.exe each time you start debugging.

The answer is to right-click on each WCF class library project, select "Properties" and go to the "WCF Settings" tab. Then uncheck the Run WCF service node when debugging another project in the same solution box.

Screenshot of WCF class library Properties page, WCF Options tab

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

0
source

Source: https://habr.com/ru/post/1338818/


All Articles