Bug 43337 - WCF on iOS TypeInitializationException Error
Summary: WCF on iOS TypeInitializationException Error
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.3.1
Hardware: Other Mac OS
: --- normal
Target Milestone: ---
Assignee: Samantha Houts [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2016-08-15 00:21 UTC by mwg@thoughts.net
Modified: 2017-06-19 21:35 UTC (History)
6 users (show)

Tags:
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:
Status:
RESOLVED ANSWERED

Description mwg@thoughts.net 2016-08-15 00:21:33 UTC
I have a cross-platform forms app which runs the following WCF code in the PCL without issue on WinPhone and Droid, but on iOS it throws a TypeInitializationException error. Looking at the parameters being passed in, the queryDevices parameter is shown as "System.TypeInitializationException: The type initializer for 'System.Data.Services.Client.TypeSystem' threw an exception."

<<<
    IR_context = new IdentityServices.identityrelationships_dbEntities(svcUri);

    DataServiceQuery<IdentityServices.Device> queryDevices = (DataServiceQuery<IdentityServices.Device>)(from device in IR_context.Devices where device.MAC == DeviceID select device);

    try
    {
        // Begin query execution, supplying a method to handle the response 
        // and the original query object to maintain state in the callback.
        queryDevices.BeginExecute(OnDeviceQueryComplete, queryDevices);
    }
>>>
Comment 1 E.Z. Hart [MSFT] 2016-08-16 20:01:13 UTC
Do you have the linker turned on for your iOS project? If so, does the problem persist with the linker turned off?
Comment 2 mwg@thoughts.net 2016-08-16 23:01:49 UTC
Are you referring to the iOS Build Linker Behavior of the project in VS?
Comment 3 E.Z. Hart [MSFT] 2016-08-16 23:52:05 UTC
(In reply to mwg@thoughts.net from comment #2)
> Are you referring to the iOS Build Linker Behavior of the project in VS?

Yes.
Comment 4 mwg@thoughts.net 2016-08-17 00:08:46 UTC
That seems to have worked. Thanks!!!

FMI, what does "not linking" do compared to "linking"?
Comment 5 mwg@thoughts.net 2016-08-17 02:54:10 UTC
Resolved. Thanks E.Z.
Comment 6 E.Z. Hart [MSFT] 2016-08-17 21:06:02 UTC
(In reply to mwg@thoughts.net from comment #4)
> That seems to have worked. Thanks!!!
> 
> FMI, what does "not linking" do compared to "linking"?

The linker removes unused code and libraries from your final application in order to produce a smaller application size.

In some cases, the linker is unable to determine whether or not particular code is used; this is a common issue when using reflection (which I'm guessing WCF is doing in this case). So by turning off the linker, you can fix your problem, but the downside is that your application ends up being much larger.

You probably don't want to disable linking entirely; rather, you probably want to tell the linker to leave some of your classes or assemblies alone. You can find information on the various ways to do this at https://developer.xamarin.com/guides/ios/advanced_topics/linker/
Comment 7 mwg@thoughts.net 2016-08-17 23:19:03 UTC
Thanks again E.Z. Will review and implement were appropriate.
Comment 8 mwg@thoughts.net 2016-08-20 14:14:19 UTC
Per "Linking on iOS - Don't Link"[https://developer.xamarin.com/guides/ios/advanced_topics/linker/], this should be treated as a bug to be resolved and reported.
Comment 9 E.Z. Hart [MSFT] 2016-08-22 15:19:17 UTC
Yes, we still need to determine why your code is being removed on iOS. 

Can you provide a reproduction project?
Comment 10 mwg@thoughts.net 2016-10-01 02:12:50 UTC
Use the files provided for Bug 44152  - Lost Event Trigger Footprint
Comment 11 mwg@thoughts.net 2016-10-01 02:15:47 UTC
Checkout Bug 44152  - Lost Event Trigger Footprint. The project was provided for it.
Comment 12 mwg@thoughts.net 2016-10-01 02:54:33 UTC
Project available
Comment 13 E.Z. Hart [MSFT] 2017-01-09 21:37:47 UTC
The application provided with https://bugzilla.xamarin.com/show_bug.cgi?id=44152 doesn't seem to have an iOS project or contain any WCF code.
Comment 14 mwg@thoughts.net 2017-02-02 13:17:57 UTC
Try this solution sample: http://public.thoughts.net/Downloads/Sentry-iOS.zip
Comment 15 Chris King 2017-06-19 16:36:00 UTC
Assigned to you because bug you were last to resolve bug before it was re-opened.
Comment 16 Cody Beyer (MSFT) 2017-06-19 21:26:47 UTC
Linked file in comment 14 results in a 404. Marking as NEEDINFO until that file is produced
Comment 17 Rui Marinho 2017-06-19 21:35:50 UTC
Because we have not received a reply to our request for more information we are closing this issue. If you are still encountering this issue, please reopen the ticket with the requested information. Thanks!