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 
4

1 回答 1

1

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

“通常你需要让 C# 编译器生成 .pdb(符号文件)以及程序集(exe/dll),以便在应用程序执行时打印出行号信息。 – Lex Li

于 2015-03-18T01:02:11.500 回答