调试“WCF 服务库”时我可以在哪里设置 try-catch 块(即入口点/Main() 方法在哪里)
Where can I set a try-catch block when debugging a `WCF Service Library` (i.e. where is the entry point / Main()-method)
这是我的情况:我在 Win 10 64 位计算机上使用 Visual Studio 2015 和 .NET Framework 4.6.1 来构建 WCF 服务。
在我的解决方案中,我有几种不同的项目类型,主要是纯 C# Class Library
(class 库)、一些 C++
-dll 引用,当然还有 WCF Service Library
本身。
在继续之前,我想声明这是我第一次与 WCF 约会...
这个 SO 问题解决的是一个类似的问题,Where is the startup method of a WCF Service?,但由于几年后我正在处理一个 WCF Service Library
问题,当时提出了最初的问题,而且事实上原始问题不是使用相同的项目类型,我相信(?)那里的答案不适合我的问题。至少在调试时不是?
在我的解决方案中,我已将 WCF Service Library
-项目设置为启动项目。当按下 F5 键(开始)时,这是我得到的:
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)
好的,通常,在普通的 C# Console Application
中,我会在 Main()
方法中设置一个 try-catch-block 来检查我的问题。但是我的 WCF Service Library
-project 好像没有。
我的问题: 我怎样才能知道 LoaderException
属性 是什么?
编辑 1:我尝试了@user497745 的回答(两个建议),第一个帮助了我:
-
- 我启动了 Visual Studio > 调试 > Windows > 异常设置
- 并提供了以下设置:
- 当开始我容易出错的 WCF 项目时,我仍然收到与以前完全相同的消息
- 尝试@user497745 建议的另一个选项时,禁用 Visual Studio > 调试 > 选项 > 调试 > 常规 > Just My Code,我更接近我的异常:
-
- 我通过在我的 App.config 文件中为
WCF Class Library
. 添加部分来尝试使用诊断跟踪的第二个建议
- 这是我的一部分
App.config
:
<system.serviceModel>
<diagnostics>
<messageLogging
logEntireMessage="true"
logMalformedMessages="false"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="false"
maxMessagesToLog="3000"
maxSizeOfMessageToLog="2000"/>
</diagnostics>
<behaviors>
<serviceBehaviors>
<behavior name="HemsamaritenServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<!-- This section is optional with the new configuration model
introduced in .NET Framework 4. -->
<service name="WCFServiceLibrary.HemsamaritenDuplexService"
behaviorConfiguration="HemsamaritenServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/Hemsamariten/service"/>
</baseAddresses>
</host>
<!-- this endpoint is exposed at the base address provided by host: http://localhost:8000/Hemsamariten/service -->
<endpoint address=""
binding="wsDualHttpBinding"
contract="WCFServiceLibrary.Interfaces.IHemsamaritenDuplexService" />
<!-- the mex endpoint is exposed at http://localhost:8000/Hemsamariten/service/mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="All"
propagateActivity="true">
<listeners>
<add name="xml" />
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="All">
<listeners>
<add name="xml" />
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="C:\Users\haunsTM\Desktop\WinService\debuglog.svclog" type="System.Diagnostics.XmlWriterTraceListener"
name="xml" />
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
- 我在 运行宁 Visual Studio 2015 年作为管理员开始我的应用程序
不幸的是,我的输出目录 C:\Users\haunsTM\Desktop\WinService\debuglog.svclog
在 运行 之后是空的。 不幸的是,配置管理器中的构建复选框未被选中对于我的可执行文件。检查时,我收到一条很长的日志消息!
因此,如果您试图中断调试器以在错误发生时捕获错误,我会推荐一种不同的方法。
任一:
转到 DEBUG > Exceptions 和 select Common Language Runtime Exceptions > System.Reflection 并检查您得到的确切异常类型。我不确定您是否还需要在 DEBUG > Options 中取消选中 "Enable Just my Code"。也许检查 "Enable .NET Framework source stepping." 然后当异常发生时,Visual Studio 应该中断并允许您像查看任何异常一样查看异常详细信息。
通过将以下内容添加到 WCF Class 库的 App.config 文件来添加诊断跟踪。然后尝试启动该库,在出现错误后,停止调试器并在 SvcTraceViewer 中打开生成的跟踪文件(位于您在下面选择的任何路径和文件名中)。您可以打开 Visual Studio 开发人员命令提示符并从那里启动它。
<system.serviceModel>
<diagnostics>
<messageLogging
logEntireMessage="true"
logMalformedMessages="false"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="false"
maxMessagesToLog="3000"
maxSizeOfMessageToLog="2000"/>
</diagnostics>
</system.serviceModel>
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="All"
propagateActivity="true">
<listeners>
<add name="xml" />
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="All">
<listeners>
<add name="xml" />
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="[SOME_PATH]\[SOME_FILENAME].svclog" type="System.Diagnostics.XmlWriterTraceListener"
name="xml" />
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
这是我的情况:我在 Win 10 64 位计算机上使用 Visual Studio 2015 和 .NET Framework 4.6.1 来构建 WCF 服务。
在我的解决方案中,我有几种不同的项目类型,主要是纯 C# Class Library
(class 库)、一些 C++
-dll 引用,当然还有 WCF Service Library
本身。
在继续之前,我想声明这是我第一次与 WCF 约会...
这个 SO 问题解决的是一个类似的问题,Where is the startup method of a WCF Service?,但由于几年后我正在处理一个 WCF Service Library
问题,当时提出了最初的问题,而且事实上原始问题不是使用相同的项目类型,我相信(?)那里的答案不适合我的问题。至少在调试时不是?
在我的解决方案中,我已将 WCF Service Library
-项目设置为启动项目。当按下 F5 键(开始)时,这是我得到的:
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)
好的,通常,在普通的 C# Console Application
中,我会在 Main()
方法中设置一个 try-catch-block 来检查我的问题。但是我的 WCF Service Library
-project 好像没有。
我的问题: 我怎样才能知道 LoaderException
属性 是什么?
编辑 1:我尝试了@user497745 的回答(两个建议),第一个帮助了我:
-
- 我启动了 Visual Studio > 调试 > Windows > 异常设置
- 并提供了以下设置:
- 当开始我容易出错的 WCF 项目时,我仍然收到与以前完全相同的消息
- 尝试@user497745 建议的另一个选项时,禁用 Visual Studio > 调试 > 选项 > 调试 > 常规 > Just My Code,我更接近我的异常:
- 我启动了 Visual Studio > 调试 > Windows > 异常设置
-
- 我通过在我的 App.config 文件中为
WCF Class Library
. 添加部分来尝试使用诊断跟踪的第二个建议
- 这是我的一部分
App.config
:
<system.serviceModel> <diagnostics> <messageLogging logEntireMessage="true" logMalformedMessages="false" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="false" maxMessagesToLog="3000" maxSizeOfMessageToLog="2000"/> </diagnostics> <behaviors> <serviceBehaviors> <behavior name="HemsamaritenServiceBehavior"> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> <services> <!-- This section is optional with the new configuration model introduced in .NET Framework 4. --> <service name="WCFServiceLibrary.HemsamaritenDuplexService" behaviorConfiguration="HemsamaritenServiceBehavior"> <host> <baseAddresses> <add baseAddress="http://localhost:8000/Hemsamariten/service"/> </baseAddresses> </host> <!-- this endpoint is exposed at the base address provided by host: http://localhost:8000/Hemsamariten/service --> <endpoint address="" binding="wsDualHttpBinding" contract="WCFServiceLibrary.Interfaces.IHemsamaritenDuplexService" /> <!-- the mex endpoint is exposed at http://localhost:8000/Hemsamariten/service/mex --> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> </system.serviceModel> <system.diagnostics> <sources> <source name="System.ServiceModel" switchValue="All" propagateActivity="true"> <listeners> <add name="xml" /> </listeners> </source> <source name="System.ServiceModel.MessageLogging" switchValue="All"> <listeners> <add name="xml" /> </listeners> </source> </sources> <sharedListeners> <add initializeData="C:\Users\haunsTM\Desktop\WinService\debuglog.svclog" type="System.Diagnostics.XmlWriterTraceListener" name="xml" /> </sharedListeners> <trace autoflush="true" /> </system.diagnostics>
- 我在 运行宁 Visual Studio 2015 年作为管理员开始我的应用程序
不幸的是,我的输出目录不幸的是,配置管理器中的构建复选框未被选中对于我的可执行文件。检查时,我收到一条很长的日志消息!C:\Users\haunsTM\Desktop\WinService\debuglog.svclog
在 运行 之后是空的。
- 我通过在我的 App.config 文件中为
因此,如果您试图中断调试器以在错误发生时捕获错误,我会推荐一种不同的方法。
任一:
转到 DEBUG > Exceptions 和 select Common Language Runtime Exceptions > System.Reflection 并检查您得到的确切异常类型。我不确定您是否还需要在 DEBUG > Options 中取消选中 "Enable Just my Code"。也许检查 "Enable .NET Framework source stepping." 然后当异常发生时,Visual Studio 应该中断并允许您像查看任何异常一样查看异常详细信息。
通过将以下内容添加到 WCF Class 库的 App.config 文件来添加诊断跟踪。然后尝试启动该库,在出现错误后,停止调试器并在 SvcTraceViewer 中打开生成的跟踪文件(位于您在下面选择的任何路径和文件名中)。您可以打开 Visual Studio 开发人员命令提示符并从那里启动它。
<system.serviceModel> <diagnostics> <messageLogging logEntireMessage="true" logMalformedMessages="false" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="false" maxMessagesToLog="3000" maxSizeOfMessageToLog="2000"/> </diagnostics> </system.serviceModel> <system.diagnostics> <sources> <source name="System.ServiceModel" switchValue="All" propagateActivity="true"> <listeners> <add name="xml" /> </listeners> </source> <source name="System.ServiceModel.MessageLogging" switchValue="All"> <listeners> <add name="xml" /> </listeners> </source> </sources> <sharedListeners> <add initializeData="[SOME_PATH]\[SOME_FILENAME].svclog" type="System.Diagnostics.XmlWriterTraceListener" name="xml" /> </sharedListeners> <trace autoflush="true" /> </system.diagnostics>