Microsoft Unity 丢失“行号”异常发生在哪里,我该怎么办?

发布于 2024-12-13 22:27:36 字数 1493 浏览 4 评论 0原文

在发布版本中,在 Microsoft Unity 解析期间,如果抛出任何异常,StackTrace 没有发生异常的“行号”。 如果没有这些信息,调试可能会很麻烦...... 你们怎么处理?

我想这是由于 Microsoft Uniy 使用 Reflection.Emit 造成的。 我的猜测正确吗?

下面是示例


Project ABC uses Microsoft Unity to resolve ViewModel XYZ during initilization.
XYZViewModel constructor throws an exception. 

Source : Microsoft.Practices.Unity
Message : Resolution of the dependency failed, type = "XYZViewModel", name = "(none)".

Exception occurred while: Calling constructor XYZViewModel().

Exception is: Exception - test exception StrackTrace line number

在异常发生时,容器是:

  Resolving XYZViewModel,(none)

  Calling constructor XYZViewModel()
////// no line number in XYZViewModel code 

Type : Microsoft.Practices.Unity.ResolutionFailedException
TargetSite : System.Object DoBuildUp(System.Type, System.Object, System.String, System.Collections.Generic.IEnumerable`1[Microsoft.Practices.Unity.ResolverOverride])
StackTrace :    at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 515
////// has line number in Microsoft Unity code 

   at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 173
///// has line number in Microsoft Unity code 

In a Release Build, during Microsoft Unity resolving, if any exception throws up, the StackTrace has no "line number" where the exception happened.
Without such information, debugging might be troublesome....
How do you guys handle it?

I suppose this is due to Microsoft Uniy use Reflection.Emit.
Is my guess correct?

below is the example


Project ABC uses Microsoft Unity to resolve ViewModel XYZ during initilization.
XYZViewModel constructor throws an exception. 

Source : Microsoft.Practices.Unity
Message : Resolution of the dependency failed, type = "XYZViewModel", name = "(none)".

Exception occurred while: Calling constructor XYZViewModel().

Exception is: Exception - test exception StrackTrace line number

At the time of the exception, the container was:

  Resolving XYZViewModel,(none)

  Calling constructor XYZViewModel()
////// no line number in XYZViewModel code 

Type : Microsoft.Practices.Unity.ResolutionFailedException
TargetSite : System.Object DoBuildUp(System.Type, System.Object, System.String, System.Collections.Generic.IEnumerable`1[Microsoft.Practices.Unity.ResolverOverride])
StackTrace :    at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 515
////// has line number in Microsoft Unity code 

   at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 173
///// has line number in Microsoft Unity code 

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

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

发布评论

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

评论(1

茶花眉 2024-12-20 22:27:36

社区维基。答案在评论里。任何在搜索中找到该主题的人都会看到有答案,并且更有可能寻找有用的答案。

“通常你需要让C#编译器生成.pdb(符号文件)以及程序集(exe/dll),这样当应用程序执行时,就可以打印出行号信息。 – 莱克斯·李

Community wiki. Answer is in a comment. Anyone finding this topic in a search will see there is an answer and is more likely to look in for a hopefully useful answer.

"Usually you need to ask the C# compiler to generate .pdb (symbol files) along with the assemblies (exe/dll), so that when the application executes, the line number information can be printed out. – Lex Li

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