Bug 7354 - TypeInitializationException in System.Data.Services.Client.TypeSystem static constructor
Summary: TypeInitializationException in System.Data.Services.Client.TypeSystem static ...
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 5.4.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
Depends on:
Reported: 2012-09-20 14:36 UTC by Len Charest
Modified: 2012-09-27 11:02 UTC (History)
2 users (show)

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

Demo of error in TypeSystem static constructor (17.87 KB, application/x-gzip)
2012-09-20 14:36 UTC, Len Charest
extra linker definition file (827 bytes, text/xml)
2012-09-27 10:55 UTC, Sebastien Pouliot

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 Len Charest 2012-09-20 14:36:46 UTC
Created attachment 2582 [details]
Demo of error in TypeSystem static constructor

When running a linked debug build on an iOS device, the static constructor for System.Data.Services.Client.TypeSystem throws a TypeInitializationException. The constructor is attempting to populate a Dictionary<MethodInfo, string> and failing on the lookup of method String.Contains(String).

In brief, my app is failing when it tries to do the following:

var context = new MyDataServiceContext(); // inherits from DataServiceContext
var query = context.Users.AddQueryOption("$filter", "Username eq 'bob'"); // type is DataServiceQuery<User>
var uri = query.RequestUri;

The getter for RequestUri starts a call chain that eventually hits TypeSystem.GetElementType, which triggers the static constructor.

The root cause seems to be that the linker has removed the String.Contains(String) method. 

I have attached a project which demonstrates the error; the project contains a crash log from my device (iPod Touch, iOS 4.2.1).
Comment 1 Sebastien Pouliot 2012-09-27 10:55:30 UTC
Created attachment 2639 [details]
extra linker definition file

Add "--xml=${ProjectDir}/sdsc.xml" to your project options (iPhone Build, Additional mtouch arguments) and you'll be able to enable the linker (Link SDK assemblies only).
Comment 2 Sebastien Pouliot 2012-09-27 11:02:05 UTC
Fixed (without using the xml attachment) in:

master: 2170249d065c173b2dd87bfc6ba6cec43563d87f
ios6: 305199eee0f03266484ece37eab73c8a3cd668e0