Silverlight 3 XamlReader 异常未捕获
当我将 XamlReader.Load() 与无效的 XAML 字符串一起使用时,虽然处于 try-catch-block 中,但不会捕获生成的 XAMLParseException:
try
{
UIElement xamlCode = XamlReader.Load(XamlText) as UIElement;
}
catch (Exception ex)
{
ErrorText = ex.Message;
}
该代码是从 DispatcherTimer 的 Tick-Event 调用的,但也在诸如 MouseLeftButtonDown 之类的事件中调用未捕获异常,导致我调用 .Load() 的行中断。
有谁知道如何捕获此异常并恢复正常的程序活动?
谢谢,安德烈
when I use XamlReader.Load() with an invalid XAML string, the resulting XAMLParseException is not caught although beeing in a try-catch-block:
try
{
UIElement xamlCode = XamlReader.Load(XamlText) as UIElement;
}
catch (Exception ex)
{
ErrorText = ex.Message;
}
The code is called from the Tick-Event of a DispatcherTimer, but also in Events like MouseLeftButtonDown the exception is not caught resulting in a break in the Line where I call .Load().
Does anyone know how to catch this Exception and resume normal programm activity?
Thanks, Andrej
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这段代码不会捕获异常,这是完全不可思议的。如何确定此处发生了 XAMLParseException?您确定不是来自项目中的其他 Xaml Load?
It is completely unfathomable that this code would not catch the exception. How do you determine that the XAMLParseException is occuring here? Are you sure is not coming from some other Xaml Load in the project?
总是这样吗?还是仅在调试时?
我知道这是一个非常晚的答案,您可能已经找到了解决方案,作为参考,人们发现您的问题与他们的问题类似(例如我的情况),我的答案可能仍然有用。
如果在 debuggin 时发生,可能是因为异常被配置为抛出。
您可以更改此设置:
Is this always the case ? or onlys while debugging ?
I'm aware this is an extremely late answer and you might have found the solution to it, for as reference to people finding your question similar to theirse (like my case ), my answer might still be of use.
If its happening while debuggin, it might be because the exeption is configured to be thrown.
You can change this:
有多种 Silverlight 操作被“重新编组”到单独的线程上,大概有各种充分且充分的原因。它看起来有点像这样:
LoadSomeXamlOrSomething() 中引发的任何异常都不会被普通的 try/catch 块捕获。即使在 SL 4 中,当加载格式无效的图像时也会发生这种情况。这很烦人,微软需要想出一个更好的方法来处理这个问题,例如,让你在调用时注册一个异常处理程序。
在 MS 弄清楚这一点之前,您的选择是:
There are various Silverlight operations that get "re-marshalled" onto separate threads for what are presumably various good and sufficient reasons. It looks kind of like this:
Any exception thrown within LoadSomeXamlOrSomething() won't be caught by normal try/catch blocks. This happens even in SL 4 with things like loading images with invalid formats. It's annoying, and MS needs to come up with a better way to handle this, for instance, by letting you register an exception handler when you make the call.
Until MS figures this out, your options are: