Bug 36401

Summary: [XM 2.4] "System.Configuration.ConfigurationErrorsException: Failed to load configuration section for dataContractSerializer" when using ChannelFactory with the "Xamarin.Mac .NET 4.5 Framework"
Product: [Desktop] Xamarin.Mac Reporter: Brendan Zagaeski (Xamarin Support) <brendan.zagaeski>
Component: OtherAssignee: Chris Hamons <chris.hamons>
Severity: blocker CC: anuj.bhatia, bruce.mcneish, Kent.Green, mono-bugs+monomac, saurabhd, smitty825
Priority: High    
Version: 2.4.0 (C6)   
Target Milestone: master   
Hardware: PC   
OS: Mac OS   
Tags: BZRC6S1_C5SR5S1 Is this bug a regression?: ---
Last known good build:
Attachments: Test case
Diagnostic build output and version info

Description Brendan Zagaeski (Xamarin Support) 2015-11-30 23:00:46 UTC
Created attachment 14046 [details]
Test case

[XM 2.4] "System.Configuration.ConfigurationErrorsException: Failed to load configuration section for dataContractSerializer" when using ChannelFactory with the "Xamarin.Mac .NET 4.5 Framework"

## Regression status: effectively a regression in Xamarin.Mac 2.4

BAD:  Xamarin.Mac (815e5d6)
GOOD: Xamarin.Mac (6db87c5)

The regression status might be slightly "special" because I think this new error might be caused by a "new feature" in Xamarin.Mac 2.4 where "System.Configuration" is more intentionally excluded from the "Xamarin.Mac .NET 4.5 Framework" profile.

## Steps to reproduce

1. Build the attached test case in the Debug configuration:
> $ xbuild /t:Build MacWCFClient.sln

2. Run the compiled binary on the command line:
> $ MacWCFTest/bin/Debug/MacWCFTest.app/Contents/MacOS/MacWCFTest

## Results

The WCF request fails because the program tries to use "System.Configuration" and "System.Configuration" is not included in the "Xamarin.Mac .NET 4.5 Framework" profile.

### Output of the program from standard output and standard error

> Sent request...
> 2015-11-30 17:10:06.840 MacWCFTest[8139:139662] 
> Unhandled Exception:
> System.Configuration.ConfigurationErrorsException: Failed to load configuration section for dataContractSerializer.
>   at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_remoting_wrapper (intptr,intptr)
>   at (wrapper remoting-invoke) TempConvertSoap:EndFahrenheitToCelsius (System.IAsyncResult)
>   at MacWCFTest.ViewController.OnTestMethodCompleted (IAsyncResult asyncResult) [0x0000d] in /private/tmp/Working/MacWCFTest/MacWCFTest/ViewController.cs:49 

## Possible workaround that was observed to stop the problem

1. Navigate to "Project Options -> General".

2. Change the "Target Framework" to either:

(a) "Xamarin.Mac Mobile Framework"


(b) "Unsupported Framework: Mono / .NET 4.5"

(See also http://developer.xamarin.com/guides/mac/advanced_topics/target-framework/)

## Why this is not expected behavior

At first I thought this unhandled exception might be the correct, expected behavior because the "Xamarin.Mac .NET 4.5 Framework" is explicitly documented not to include "System.Configuration" [1]. The problem with that theory is that the "Xamarin.Mac Mobile Framework" _does_ work correctly in this test case. I would expect the "Xamarin.Mac .NET 4.5 Framework" to include all of the functionality (i.e., be a superset) of the "Xamarin.Mac Mobile Framework".

[1] "The Xamarin.Mac .NET 4.5 Framework ... is missing large, rarely used elements, such as System.Configuration"
> http://developer.xamarin.com/guides/mac/advanced_topics/assemblies/#The_Xamarin.Mac_.NET_4.5_Framework

It seems like maybe the problem is that the "Xamarin.Mac .NET 4.5 Framework" still includes some "vestigial" piece of System.Configuration that needs to be _removed_. For example...

### When built with the "Xamarin.Mac .NET 4.5 Framework", the `MonoBundle/` folder _does_ include `System.Configuration.dll`

> $ ls MacWCFTest/bin/Debug/MacWCFTest.app/Contents/MonoBundle/System.Configuration.dll
> MacWCFTest/bin/Debug/MacWCFTest.app/Contents/MonoBundle/System.Configuration.dll

### When built with the "Xamarin.Mac Mobile Framework", the `MonoBundle/` folder does _not_ include `System.Configuration.dll`

> $ ls MacWCFTest/bin/Debug/MacWCFTest.app/Contents/MonoBundle/System.Configuration.dll
> ls: MacWCFTest/bin/Debug/MacWCFTest.app/Contents/MonoBundle/System.Configuration.dll: No such file or directory
Comment 1 Brendan Zagaeski (Xamarin Support) 2015-11-30 23:02:19 UTC
Created attachment 14047 [details]
Diagnostic build output and version info
Comment 10 Chris Hamons 2016-01-26 22:34:13 UTC
So my analysis was wrong. This turns out to be significantly more straightforward than expected.

Working on a fix now. Support contacts will reach out to customer w/ build to test.
Comment 11 Bruce McNeish 2016-01-27 10:52:46 UTC
Hey Chris,

I have hit this issue also and would be interested in testing any fix you may have, if possible?

Comment 12 Chris Hamons 2016-01-27 15:57:12 UTC
Fixed in master/maccore. Will make C7 release. A build is out to the reporter w/ fix for testing.

@Bruce - I will contact you directly to discuss.
Comment 14 Chris Hamons 2016-09-16 15:10:26 UTC
This is completely unrelated. This stack trace:

Parameter name: typeArguments
  at (wrapper managed-to-native) System.RuntimeType:MakeGenericType (System.Type,System.Type[])
  at System.RuntimeType.MakeGenericType (System.Type[] instantiation) [0x000ef] in /Library/Frameworks/Xamarin.Mac.framework/Versions/ 
  at Registrar.DynamicRegistrar.VerifyIsConstrainedToNSObject (System.Type type, System.Type& constrained_type) [0x000ce] in /Users/builder/data/lanes/1381/4a87ccf9/source/xamarin-macios/src/ObjCRuntime/DynamicRegistrar.cs:473 
  at Registrar.Registrar.VerifyIsConstrainedToNSObject (System.Collections.Generic.List`1[System.Exception]& exceptions, System.Type type, Registrar.Registrar+ObjCMethod method) [0x0000c] in /Users/builder/data/lanes/1381/4a87ccf9/source/xamarin-macios/src/ObjCRuntime/Registrar.cs:1178 
  at Registrar.Registrar.RegisterTypeUnsafe (System.Type type, System.Collections.Generic.List`1[System.Exception]& exceptions) [0x00fba] in /Users/builder/data/lanes/1381/4a87ccf9/source/xamarin-macios/src/ObjCRuntime/Registrar.cs:1819 
  at Registrar.Registrar.RegisterAssembly (System.Reflection.Assembly assembly) [0x000b0] in /Users/builder/data/lanes/1381/4a87ccf9/source/xamarin-macios/src/ObjCRuntime/Registrar.cs:1933 

is this bug: https://bugzilla.xamarin.com/show_bug.cgi?id=44309