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. 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:
- in desktop app / windows service (haven't tried 'metro' apps)
- on WinPhone 8.1 emulator in any mode (release, debug, with or without debugger)
- on real WinPhone 8.1 device (tried on Lumia 625) in debug mode
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.
This exception can't be caught and doesn't contain any details - app just crashes.
Is this a bug? Or known limitations of WinPhone? Why it works on emulator? And all this strange "conditions" are important:
Token
must bestruct
, notclass
- It must implement
IDictionary<K,V>
, not any other interface (triedIList<Token>
,ICollection
) - It must be placed in separate portable class library. If I move it in WP 8.1 project - it works fine
- Instance of
Token
must be placed insideKeyValuePair<K,V>
. If you do justtoken.Value.GetType()
- it works fine
I created VS 2013 solution to reproduce this situation. It can be downloaded here.