WcfSVCHost 遇到严重错误,必须退出。这可能是由于配置文件无效造成的

发布于 2024-10-16 12:47:45 字数 473 浏览 7 评论 0原文

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)

如何循环遍历 LoaderExceptions 属性以查看发生了什么错误,因为它没有命中任何服务,并在运行任何代码之前给我此错误?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

满身野味 2024-10-23 12:47:45

我设法解决了这个问题。我的一个项目设置为 x86,其他项目设置为 Any CPU。全部更改为 Any CPU 解决了我的问题。

谢谢

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

飘逸的'云 2024-10-23 12:47:45

解决方案对我来说是不同的。对于那些稍微熟悉 WCF 开发的人来说,这可能是显而易见的信息。但希望它能帮助其他遇到同样问题的新手,这就是我的想法。

事实证明,我正在调试的应用程序根本不需要 WcfSvcHost.exe。 WcfSvcHost.exe 用于自托管 WCF 应用程序。该应用程序使用作为 Web 应用程序端点公开的服务。

最终让我明白这一点的是:首先,将显示此屏幕:

​​ 错误消息的屏幕截图“WcfSvcHost 遇到严重错误,必须退出。”

我注意到这显示为 WcfSvcHost 的单独进程Windows 任务管理器中的 .exe。这解释了为什么当我将异常设置调整为在引发 System.Reflection.ReflectionTypeLoadException 时中断时,我无法让调试器中断。 Visual Studio 没有中断,因为它没有附加到 WcfSvcHost.exe 进程。它附加到正在运行我的应用程序的 IISExpress.exe 进程。但 WcfSvcHost.exe 进程引发异常。

当我单击上述错误消息上的“确定”按钮时,WcfSvcHost.exe 进程将退出并且不再出现在任务管理器中。但该应用程序仍然运行良好。很明显,无论发生什么都是不必要的。与另一位开发人员的快速检查确认该应用程序不需要自托管 WCF 服务。

由于某种原因,Visual Studio 无论如何都会启动 WcfSvcHost.exe。这最终让我找到了这个答案。可以将 WCF 类库项目配置为在调试开始时启动 WcfSvcHost.exe。

答案是右键单击每个 WCF 类库项目,选择“属性”,然后单击“WCF 选项”选项卡。然后取消选中在同一解决方案中调试另一个项目时启动 WCF 服务主机

屏幕截图WCF 类库属性页,WCF 选项选项卡

您必须对解决方案中的所有 WCF 类库执行此操作。我不确定哪些是哪些,所以我只是查看了每个类库的属性并修复了具有 WCF 选项选项卡的类库。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文