[英]Windows Phone 8.1 C# app: critical crash (ExecutionEngineException) only on real device in release mode
Imagine the following struct type: 想象以下结构类型:
public struct Token : IDictionary<string, Token>
{
public readonly object Value;
public Token(string str) { Value = str; }
public Token(IDictionary<string, Token> dict) { Value = dict; }
/* IDictionary<string, Token> implementation is here */
}
Don't ask me anything about what it does. 不要问我什么事。 Implementation doesn't matter, you can throw NotImplementedException in all methods/properties. 实现并不重要,您可以在所有方法/属性中引发NotImplementedException。 It is placed in separate portable class library. 它放置在单独的可移植类库中。
Then imagine the usage of this struct: 然后想象一下这个结构的用法:
var token = new Token("111");
var kvp = new KeyValuePair<string, Token>("aaa", token);
var val = kvp.Value.Value;
var t = val.GetType(); // XXX
This code works perfectly almost everywhere: 这段代码几乎可以在任何地方正常工作:
But when I run this code on real WP 8.1 device (Lumia 625, latest updates) in RELEASE mode, then I get ExecutionEngineException
exception at line XXX
with message An unhandled exception of type 'System.ExecutionEngineException' occurred in Unknown Module.
但是,当我在RELEASE模式下在实际的WP 8.1设备(Lumia 625,最新更新)上运行此代码时,我在XXX
行上收到ExecutionEngineException
异常,消息An unhandled exception of type 'System.ExecutionEngineException' occurred in Unknown Module.
This exception can't be caught and doesn't contain any details - app just crashes. 无法捕获此异常,并且不包含任何详细信息-应用程序崩溃。
Is this a bug? 这是错误吗? Or known limitations of WinPhone? 还是WinPhone的已知限制? Why it works on emulator? 为什么它可以在模拟器上运行? And all this strange "conditions" are important: 所有这些奇怪的“条件”都很重要:
Token
must be struct
, not class
Token
必须是struct
而不是class
IDictionary<K,V>
, not any other interface (tried IList<Token>
, ICollection
) 它必须实现IDictionary<K,V>
,而不是任何其他接口(尝试IList<Token>
, ICollection
) Token
must be placed inside KeyValuePair<K,V>
. Token
实例必须放在KeyValuePair<K,V>
。 If you do just token.Value.GetType()
- it works fine 如果您只做token.Value.GetType()
-它可以正常工作 I created VS 2013 solution to reproduce this situation. 我创建了VS 2013解决方案来重现这种情况。 It can be downloaded here . 可以在这里下载。
I created the error report at Microsoft Connect couple months ago and have been waiting for response but it doesn't look that somebody in Microsoft is interested in fixing this bug. 我几个月前在Microsoft Connect上创建了错误报告 ,一直在等待响应,但是Microsoft似乎没有人对此错误感兴趣。
By the way I created a more simple repro: 顺便说一下,我创建了一个更简单的副本:
public struct Token : IDictionary<string, Token>
{
/* IDictionary<string, Token> implementation is here */
}
public static class Test
{
//[MethodImpl(MethodImplOptions.NoOptimization)]
public static void Method()
{
var dict = new Dictionary<string, Token> { { "qwe", new Token() } };
var arr = dict.ToArray(); // XXX
}
}
Implementation of IDictionary<string, Token>
doesn't matter, the exception occurs at line XXX
. IDictionary<string, Token>
实现无关紧要,例外发生在第XXX
行。 And they ( Token
definition and usage) can be located in one assembly. 并且它们( Token
定义和用法)可以位于一个程序集中。
I also noticed that adding the MethodImpl(MethodImplOptions.NoOptimization)
attribute to a method that uses Token
fixes the problem, so even considering that I'm not a .NET guru I'm 99% sure that it is a bug in compiler (C#, MDIL, NGEN, whatever) for ARM that is somehow related to optimizations. 我还注意到,将MethodImpl(MethodImplOptions.NoOptimization)
属性添加到使用Token
的方法可以解决此问题,因此即使考虑到我不是.NET专家,我也有99%的把握确保它是编译器中的错误(C# ,MDIL,NGEN,等等)与优化相关的ARM。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.