[英]Code in filtered exception handler throws NullReferenceException when accessing exception
When I compile a UWP app with the .NET Native compiler and turn on code optimizations (essentially release mode), then I get a NullReferenceException
when I try to access the actual exception in the catch block. 当我使用.NET Native编译器编译UWP应用并打开代码优化(本质上是发布模式)时,当我尝试访问catch块中的实际异常时,会收到
NullReferenceException
。
Code Sample: 代码示例:
try
{
throw new ArgumentNullException("Param");
}
catch (ArgumentNullException ex) when (ex.ParamName == "Param")
{
ErrorBlock.Text = ex.ParamName; // ErrorBlock is a TextBlock in the xaml
}
catch (Exception)
{
}
It goes into the correct catch block, and throws a NullReferenceException
when I access ex
. 它进入正确的catch块,并在我访问
ex
时引发NullReferenceException
。 This only fails if both .Net Native and code optimizations are on. 只有同时启用.Net本机优化和代码优化,此操作才会失败。
What causes this issue? 是什么原因导致此问题?
I am not exactly sure why it is going wrong (have been debugging for quite some time now), but the lack of await
made me curious. 我不确定为什么会出错(现在已经调试了很长时间),但是缺少
await
使我感到好奇。
If you do await the ShowAsync
method the code runs without a problem (obviously you need to make the method async
if you didn't do that yet): 如果您确实等待
ShowAsync
方法,则代码可以正常运行(显然,如果您尚未这样做,则需要使该方法async
):
await new MessageDialog("Argument null exception: " + argEx.Message).ShowAsync();
While the code block without the await
failed. 而没有
await
代码块失败。 Not sure if this is a bug or something you should have fixed... 不知道这是错误还是应该修复的问题...
I work on the .NET Native runtime and compiler team. 我在.NET Native运行时和编译器团队中工作。
This is a bug inside of our compiler. 这是我们编译器内部的错误。 You can think of each exception handling region (try, catch, finally, when) as a small function or "funclet".
您可以将每个异常处理区域(尝试,捕获,最终,何时)视为一个小函数或“ funclet”。 We lose track of the exception object when setting up the stack for the "when" (aka filter block).
当为“ when”(又称过滤器块)设置堆栈时,我们将无法跟踪异常对象。 This bug is corrected in Windows Tools 1.3 which, given no major setbacks, should be shipping in another week or two.
Windows工具1.3中已纠正了该错误,在没有重大挫折的情况下,该工具应在另外一两周内发货。 It'll show up as an update for folks that have installed VS 2015 Update 2.
对于已安装VS 2015 Update 2的人员,它将显示为更新。
Let me know if you have any other questions. 如果您还有其他问题,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.