Microsoft Unity 丢失“行号”异常发生在哪里,我该怎么办?
在发布版本中,在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
社区维基。答案在评论里。任何在搜索中找到该主题的人都会看到有答案,并且更有可能寻找有用的答案。
“通常你需要让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