Bug 5316 - AOT Compiler not constructing dictionary type in generic class.
Summary: AOT Compiler not constructing dictionary type in generic class.
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 5.2
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-05-24 22:16 UTC by Ergwun
Modified: 2012-05-29 08:15 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Ergwun 2012-05-24 22:16:51 UTC
When creating a generic type that has a Dictionary that uses the type's generic type parameter for its values' type, the AOT compiler doesn't construct the required Dictionary type, resulting in a runtime error on an iOS device when it tries to invoke the JIT compiler.

For example:

public class Foo<T>
    private Dictionary<int, T> d = new Dictionary<int, T>();

var foo = new Foo<string>(); // Runtime error.

Writing code elsewhere to force construction of the Dictionary type with the required type parameters will work-around this problem.
Comment 1 Ergwun 2012-05-24 22:28:32 UTC
Tested on MonoTouch 5.2.12.

Only happens when dictionary key is a value type (primitive or custom), and then happens even if IEqualityComparer is passed in constructor.

Another workaround is to make the dictionary field public, and access it in code e.g.
add this line to end of unit test in attached project.
int x = foo.dict.Count;
Comment 2 Zoltan Varga 2012-05-29 07:33:09 UTC
Fixed in master/mobile-master.
Comment 3 Ergwun 2012-05-29 08:15:02 UTC
Cool, thanks.