Bug 18259 - WCF service call throws NullReferenceException in release configuration
Summary: WCF service call throws NullReferenceException in release configuration
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.12.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Alex Rønne Petersen
: 19411 ()
Depends on:
Reported: 2014-03-07 18:28 UTC by Jon Goldberger [MSFT]
Modified: 2016-03-15 01:03 UTC (History)
8 users (show)

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

Test Project. This is Xamarin's WCF walkthrough tutorial project, unchanged (76.54 KB, application/zip)
2014-03-07 18:28 UTC, Jon Goldberger [MSFT]

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:

Comment 1 Jon Goldberger [MSFT] 2014-03-07 18:29:44 UTC
From case:
I noticed a crash when using an Task.FromAsync style WCF call in my release build (no crash in debug). The proxy classes were created with slsvcutil as per the instructions on the site.

Changing Linking to None makes it not crash.

Here's a bit of the call stack window

0x14A in System.ServiceModel.MonoInternal.ClientRuntimeChannel..ctor C#
0x2F in System.ServiceModel.MonoInternal.ClientRuntimeChannel..ctor C#
0x24 in System.ServiceModel.ClientBase<MyApp.Portable.Services.EventsService.IEventsService>.ChannelBase<MyApp.Portable.Services.EventsService.IEventsService>.get_Inner C#
0x3D in System.ServiceModel.ClientBase<MyApp.Portable.Services.EventsService.IEventsService>.ChannelBase<MyApp.Portable.Services.EventsService.IEventsService>.BeginInvoke C#
> 0x15 in MyApp.Portable.Services.EventsService.EventsServiceClient.EventsServiceClientChannel.BeginCheckToken at c:\files\MyApp.Portable\Services\EventsService\EventsService.cs:694 C#
0xA in MyApp.Portable.Services.EventsService.EventsServiceClient.MyApp.Portable.Services.EventsService.IEventsService.BeginCheckToken at c:\files\MyApp.Portable\Services\EventsService\EventsService.cs:362 C#
0x70 in System.Threading.Tasks.TaskFactory<bool>.FromAsyncBeginEnd<MyApp.Portable.Services.EventsService.MyAppToken> C#
0x7 in System.Threading.Tasks.TaskFactory<bool>.FromAsync<MyApp.Portable.Services.EventsService.MyAppToken> C#
0xC in System.Threading.Tasks.TaskFactory<bool>.FromAsync<MyApp.Portable.Services.EventsService.MyAppToken> C#
0x60 in MyApp.Droid.LoginActivity.CheckToken at c:\files\MyApp.Android\LoginActivity.cs:176 C#

If I go back to the debug build (which works) and change linking to Sdk Assemblies Only and untick Use Shared Runtime it also crashes.

Those tests all use Compile using 18, min target 15, target 18.
Comment 2 Jon Goldberger [MSFT] 2014-03-07 18:30:45 UTC
More from case:
I was looking at making a minimal example, but you’ve already made one!

No need to run the service. Just run the Android app (haven’t tried iOS).

Clicking the “Say Hello World” button…

· Debug mode

o “Waiting for WCF”

· Release mode

o Crash

Tried to file this on bugzilla but it never sent me a new account email.

I’m fairly certain this used to work so I’m going to try an older version.

Here’s version info you asked for.

Microsoft Visual Studio Professional 2013
Version 12.0.30110.00 Update 1
Microsoft .NET Framework
Version 4.5.50938

Installed Version: Professional

Microsoft Office Developer Tools for Visual Studio 2013 ENU 06177-004-0447006-02727
Microsoft Office Developer Tools for Visual Studio 2013 ENU

Team Explorer for Visual Studio 2013 06177-004-0447006-02727
Microsoft Team Explorer for Visual Studio 2013

Visual Basic 2013 06177-004-0447006-02727
Microsoft Visual Basic 2013

Visual C# 2013 06177-004-0447006-02727
Microsoft Visual C# 2013

Visual C++ 2013 06177-004-0447006-02727
Microsoft Visual C++ 2013

Visual F# 2013 06177-004-0447006-02727
Microsoft Visual F# 2013

Visual Studio 2013 Code Analysis Spell Checker 06177-004-0447006-02727
Microsoft® Visual Studio® 2013 Code Analysis Spell Checker

Portions of International CorrectSpell™ spelling correction system © 1993 by Lernout & Hauspie Speech Products N.V. All rights reserved.

The American Heritage® Dictionary of the English Language, Third Edition Copyright © 1992 Houghton Mifflin Company. Electronic version licensed from Lernout & Hauspie Speech Products N.V. All rights reserved.

ASP.NET and Web Tools 2013.1.41009
Microsoft Web Developer Tools contains the following components:
Support for creating and opening ASP.NET web projects
Browser Link: A communication channel between Visual Studio and browsers
Editor extensions for HTML, CSS, and JavaScript
Page Inspector: Inspection tool for ASP.NET web projects
Scaffolding: A framework for building and running code generators
Server Explorer extensions for Windows Azure Web Sites
Web publishing: Extensions for publishing ASP.NET web projects to hosting providers, on-premises servers, or Windows Azure

ASP.NET Web Frameworks and Tools 2012.2 4.1.21001.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013 5.0.11213.0
For additional information, visit http://www.asp.net/

Common Azure Tools 1.0
Provides common services for use by Azure Mobile Services and Windows Azure Tools.

Intel(R) Visual Fortran Package ID: w_fcompxe_2013_sp1.1.139
Intel(R) Visual Fortran Composer XE 2013 SP1 Update 1 Integration for Microsoft Visual Studio* 2013, 14.0.0074.12, Copyright (C) 2002-2013 Intel Corporation
* Other names and brands may be claimed as the property of others.

JetBrains ReSharper C++ EAP C# Edition build on 2014-02-24T15:32:20
JetBrains ReSharper C++ EAP package for Microsoft Visual Studio. For more information about ReSharper, visit http://www.jetbrains.com/resharper/. Copyright © 2003–2014 JetBrains, Inc.

NuGet Package Manager 2.8.50126.477
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

PreEmptive Analytics Visualizer 1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools 12.0.30919.1
Microsoft SQL Server Data Tools

Windows Azure Mobile Services Tools 1.0
Windows Azure Mobile Services Tools

Windows Azure Remote Debugging 1.0
Windows Azure Remote Debugging Community Technology Preview

Windows Azure Tools 2.2
Windows Azure Tools for Microsoft Visual Studio 2013 - v2.2.11003.1601

Workflow Manager Tools 1.0 1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin.Android 4.12.01000 (0deb0164)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS 1.10.39 (e0334707)
Visual Studio extension to enable development for Xamarin.iOS
Comment 3 Jon Goldberger [MSFT] 2014-03-07 18:31:08 UTC
More form case:
Hi I downgraded mono android and rebuilt. Going in back and forth between these fixes and breaks the linking.

Working: mono-android-4.10.02014.msi (Feb 4th)
Broken: mono-android-4.12.01000.msi (Feb 24th)

Frankly I feel this broke it https://bugzilla.xamarin.com/show_bug.cgi?id=13370

But that’s just my gut feel ☺
Comment 5 Alex Rønne Petersen 2014-03-07 22:53:25 UTC
As posted on #18239, this is a workaround:

Step 1:  Create a new file called System.ServiceModel.xml in the root of the
Xamarin.Android project

--> System.ServiceModel.xml

Step 2: Change the build action of that file to: "LinkDescription".

Step 3: Add the following to the contents of System.ServiceModel.xml


Step 4: Ensure Linker settings are set to Link SDK Assemblies only.
Comment 7 Yuri 2014-03-12 12:03:46 UTC
Will this workaround affect the Debug build too or Debug still should be set as NoLink?
Comment 8 Alex Rønne Petersen 2014-03-12 12:11:00 UTC
You need that workaround whenever you do SDK linking, regardless of Debug/Release.
Comment 9 Yuri 2014-03-12 12:20:17 UTC
I am using WCF in PCL. Anything should be done in PCL or just in Android project? What about iOS? This is my next step. Should it work there without any changes?
Comment 10 Alex Rønne Petersen 2014-03-12 12:43:45 UTC
This issue is basically only related to linking. Anywhere where linking is available (Android, iOS, Mac, ...) can potentially have this issue. PCL is largely unrelated.

The linker descriptor file should be put in the library where you're using WCF, if you have such a library. Otherwise, just the application project.
Comment 11 Yuri 2014-03-12 12:56:30 UTC
I am using WCF in PCL which is linked to Android and IOS project. Where should I put the file?
Comment 12 Yuri 2014-03-12 15:07:06 UTC
So, from what I discovered. You should put the file in Android project (PCL project doesn't have a build option for LinkDescription anyway).
Comment 13 Yuri 2014-03-14 10:58:08 UTC
I spoke too soon :-( It works in simulator but on real device I get an error
"No constructor found for System.ServiceModel.FaultException`1"
I am stuck. Should I roll back to version 10? Please reply ASAP. Thank you.
Comment 14 Yuri 2014-03-14 13:33:42 UTC
After rolling back to mono-android-4.10.02014 I get an error DataMember property 'System.StringMessage' on type 'System.ServiceModel.ExceptionDetail' must have both getter and setter.
I need to release a new version of my app and completely stack. Please advice what should I do ASAP.
Comment 15 Alex Rønne Petersen 2014-03-14 13:54:31 UTC
(In reply to comment #13)
> I spoke too soon :-( It works in simulator but on real device I get an error
> "No constructor found for System.ServiceModel.FaultException`1"
> I am stuck. Should I roll back to version 10? Please reply ASAP. Thank you.

I would need a project that reproduces this issue in order to suggest a workaround. You can email me one at alexrp at xamarin dot com.
Comment 16 Yuri 2014-03-14 15:44:12 UTC
Hi Alex. It is funny. When I create a new project NullPointerException doesn't happen. I don't even need to add link xml file, it works without it. Unfortunately I cannot send you my full project which causing an error. Meantime I just specified in link to skip System.ServiceModel library and it works. Any ideas why new created project doesn't cause the problem?
Comment 17 Yuri 2014-03-14 16:07:20 UTC
I was able to reproduce the problem and sent to Alex the project with a screen shot. The workaround is to set linker to skip System.ServiceModel library. Then you don't need to include linker description file but it would be nice to get the fix.
Comment 18 Alex Rønne Petersen 2014-03-31 10:50:53 UTC
Fixed in XA master.

Note that there may be other WCF/linking bugs lurking, so please open bugs if you run into any!
Comment 19 Jonathan Pryor 2014-04-30 21:43:31 UTC
*** Bug 19411 has been marked as a duplicate of this bug. ***
Comment 21 Ronak Vala 2016-03-14 22:58:07 UTC
Hi Yuri,

I am working with Xamarin Forms for the first time and I come across the similar issue while building my Xamarin Forms project with WCF services for Android.

It works fine when I run my application in debug mode but it gives below error while I run it in release mode:
System.ServiceModel.FaultException`1[[System.ServiceModel.ExceptionDetail, System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:paramsDictionary. The InnerException message was 'Error in line 1 position 333. 'EndElement' 'KeyValueOfstringstring' from namespace 'http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Expecting element 'Key'.'. Please see InnerException for more details.
System.Object.__icall_wrapper_mono_delegate_end_invoke(object, intptr)(wrapper managed-to-native)
at (wrapper delegate-end-invoke) <Module>:end_invoke_object__this___object[]&_IAsyncResult (object[]&,System.IAsyncResult)
System.ServiceModel.MonoInternal.ClientRuntimeChannel.EndProcess(MethodBase method, string operationName, object[] parameters, IAsyncResult result)
System.ServiceModel.ClientBase<TChannel>.ChannelBase<T>.EndInvoke(string methodName, object[] args, IAsyncResult result)
TasleemApp.EngageWebServices.EngageCSSServiceClient.EngageCSSServiceClientChannel.EndSendPasswordReminder(IAsyncResult result)
TasleemApp.EngageWebServices.EngageCSSServiceClient.TasleemApp.EngageWebServices.IEngageCSSService.EndSendPasswordReminder(IAsyncResult result)
System.Threading.Tasks.TaskFactory<TResult>.FromAsyncCoreLogic(IAsyncResult iar, Func<_,_> endFunction, Action<_> endAction, Task<_> promise, bool requiresSynchronization)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)

I have tried the solution provided by Alex for adding XML file and changing build action to Link Description but it doesn't seem to work for me.

Can you please guide me of how can I set linker to skip System.ServiceModel library or do I need to upgrade something in my Android project?

Let me know if you need any further information.

Thanks in advance.
Comment 22 Yuri 2016-03-15 01:03:43 UTC
Hi Ronak, I will answer directly to your email. This is not a forum :-)