我有这样的方法,从Silverlight客户端记录错误:我有时无法从我的方法在Silverlight
[MethodImpl(MethodImplOptions.NoInlining)]
public static bool ErrorHandler(Exception error, bool showError = true)
{
string callingMethod = new StackFrame(1).GetMethod().Name;
//write log - call webservice
//show error that some error happened if showError is true
}
我的问题是这样的,当我运行的应用程序,并调用方法抛出它记录这样一个例外:
<ThrowExceptionMethod>b__72: test
但是当有人有一个正常的(非开发人员运行时)运行这个程序,并把它扔了记录这样一个例外:
b__72: test
我只是猜测这是由于SDK Silverlight运行时。很难说,因为我的大多数同事都安装了Silverlight SDK ...有人可以确认这是否是此异常的原因。
已解决!
这不是由于SDK运行时造成的,只是因为我称之为匿名方法。 我加入这行代码吧:
var listStackFrame = new List<StackFrame>();
for (int i = 1; i < 20; i++)
{
listStackFrame.Add(new StackFrame(i));
}
string callingMethod = string.Empty; //new StackFrame(1).GetMethod().Name;
foreach (var item in listStackFrame
.Where(m => m != null && m.GetMethod() != null && !string.IsNullOrEmpty(m.GetMethod().Name) && m.GetMethod().Name.Contains("__")))
{
callingMethod += item.GetMethod().Name + "->";
}
我不担心这个多少钱吃起来的资源,因为所有的异常已发生之后,用户将停止一切他在做什么,联系技术支持。
这可能是真的,因为我们称之为web服务我们创建匿名方法来处理结果 – Rumplin
我认为你可以检查创建10个StackFrames并查看最后10个方法。你会看到从那里得到的处理错误是有意义的。 – ivowiblo
我用适合我的解决方案更新了我的问题。谢谢各位 – Rumplin