Bug 50701 - "Index was out of range" in `ClientRuntimeChannel.EndProcess()` when getting WCF reply types that use Dictionaries if SDK assemblies are set to be linked
Summary: "Index was out of range" in `ClientRuntimeChannel.EndProcess()` when getting ...
Status: RESOLVED DUPLICATE of bug 36710
Alias: None
Product: Android
Classification: Xamarin
Component: Linker ()
Version: 7.0 (C8)
Hardware: PC Windows
: --- normal
Target Milestone: 7.1 (C9)
Assignee: Radek Doulik
URL:
Depends on:
Blocks:
 
Reported: 2016-12-23 02:55 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2016-12-23 02:56 UTC (History)
1 user (show)

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


Attachments
Test case (64.41 KB, application/zip)
2016-12-23 02:55 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Details


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 DUPLICATE of bug 36710

Description Brendan Zagaeski (Xamarin Team, assistant) 2016-12-23 02:55:00 UTC
Created attachment 18977 [details]
Test case

"Index was out of range" in `ClientRuntimeChannel.EndProcess()` when getting WCF reply types that use Dictionaries if SDK assemblies are set to be linked


I am filing this bug and marking it as a duplicate just to document some symptoms that are are in fact already resolved in Cycle 9 Alpha by the fixes mentioned in Bug 36710, Comment 8 [1, 2].  The precise error message from this test case did not previously appear in Bugzilla.


[1] https://github.com/xamarin/xamarin-android/commit/ae7d535efa3749ddf2f8e47b2f08f56f1d87e166
[2] https://github.com/xamarin/xamarin-android/commit/ac5269d54e518d9db6dac31e49de26c8b288662c




## Verification status: resolved in Xamarin.Android 7.1 (Cycle 9) Alpha version

GOOD: Xamarin.Android 7.1.0.14 (cea7c6e)
BAD:  Xamarin.Android 7.0.2.42 (501e63c)
BAD:  Xamarin.Android 7.0.2.37 (ce955cc)
BAD:  Xamarin.Android 6.1.2.21 (1cf254d)




## Manual fix for Xamarin.Android apps that hit this issue

1. Add the following lines to an XML file in the Android app project:

<?xml version="1.0" encoding="utf-8" ?>
    <linker>
        <assembly fullname="System.Runtime.Serialization">
        <type fullname="System.Runtime.Serialization.KeyValue*" />
    </assembly>
</linker>


2. Set the build action of the XML file to "LinkDescription".


3. Clean, rebuild, and run the Android app.




## Steps to replicate

1. Open HelloWorld.sln from the attached test case in Visual Studio, and follow the steps on [1] to get the "HelloWorldWcfHost" project running under IIS Express on your machine.  For example, you'll need to adjust the IP address for port 9608 in ".vs\config\applicationhost.config".  Once you've completed those steps, make sure you can access the service via the IP address of the Windows computer in a web browser.

[1] https://developer.xamarin.com/guides/cross-platform/application_fundamentals/web_services/walkthrough_working_with_WCF/


2. Make sure the "HelloWorldWcfHost" project is running.


3. Open HelloWorld.sln in a second instance of Visual Studio (or in Xamarin Studio on Mac if you prefer) to run the "HelloWorld.Android" project.  Make sure you update the IP address in the `EndpointAddress()` constructor in MainActivity.cs to match the Windows computer.


4. Build and run the "HelloWorld.Android" project in the "Debug|Any CPU" configuration on a device or emulator that can access the Windows computer over the network.  Note: The project intentionally does _not_ use the Shared Runtime.  It currently has armeabi-v7a and x86 enabled under "Supported architectures".


5. Click the "Get Hello World data" button in the running Android app.




## BAD Results

The deserialization of the SOAP response fails.  The error message and stack trace are printed to the application output:

> Error: Index was out of range. Must be non-negative and less than the size of the collection.
> Parameter name: index
>   at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_delegate_end_invoke (object,intptr)
>   at (wrapper delegate-end-invoke) <Module>:end_invoke_object__this___object[]&_IAsyncResult (object[]&,System.IAsyncResult)
>   at System.ServiceModel.MonoInternal.ClientRuntimeChannel.EndProcess (System.Reflection.MethodBase method, System.String operationName, System.Object[] parameters, System.IAsyncResult result) [0x00025] in <cda7b5abb2824ad5b313d3676c6883f8>:0 
>   at System.ServiceModel.ClientBase`1+ChannelBase`1[TChannel,T].EndInvoke (System.String methodName, System.Object[] args, System.IAsyncResult result) [0x00048] in <cda7b5abb2824ad5b313d3676c6883f8>:0 
>   at HelloWorldServiceClient+HelloWorldServiceClientChannel.EndGetWarehouseRows (System.IAsyncResult result) [0x00008] in C:\source\LinkerRemovesSerializationKeyValue\HelloWorld.Android\HelloWorldService.cs:363 
>   at HelloWorldServiceClient.IHelloWorldService.EndGetWarehouseRows (System.IAsyncResult result) [0x00001] in C:\source\LinkerRemovesSerializationKeyValue\HelloWorld.Android\HelloWorldService.cs:210 
>   at HelloWorldServ
> iceClient.OnEndGetWarehouseRows (System.IAsyncResult result) [0x00001] in C:\source\LinkerRemovesSerializationKeyValue\HelloWorld.Android\HelloWorldService.cs:220 
>   at System.ServiceModel.ClientBase`1+<InvokeAsync>c__AnonStorey0[TChannel].<>m__0 (System.IAsyncResult ar) [0x00006] in <cda7b5abb2824ad5b313d3676c6883f8>:0 



## GOOD Results with the "manual fix" in place

The deserialization succeeds, and the text view on the Android app shows "Success".




## Additional test environment info (brief)

Windows 10 (64-bit), Version 1607 (OS Build 14393.576)

Microsoft Visual Studio Enterprise 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.6.01586

Tested on VS Emulator for Android (API 19) and Google x86 Android Emulator (API 23).