Bug 32886 - [Mono 3.12] Some WCF methods that do _not_ use "ref" parameters fail with "InvalidOperationException" during "ClientRuntimeChannel.EndProcess" when called via a ChannelFactory channel
Summary: [Mono 3.12] Some WCF methods that do _not_ use "ref" parameters fail with "In...
Alias: None
Product: Installers
Classification: Mono
Component: General ()
Version: 4.0.0
Hardware: PC All
: --- normal
Target Milestone: 4.2.0 (C6)
Assignee: Martin Baulig
Depends on:
Reported: 2015-08-07 23:21 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2015-10-05 22:32 UTC (History)
4 users (show)

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

Test case (5.61 KB, application/zip)
2015-08-07 23:21 UTC, Brendan Zagaeski (Xamarin Team, assistant)

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 GitHub or Developer Community 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 Brendan Zagaeski (Xamarin Team, assistant) 2015-08-07 23:21:03 UTC
Created attachment 12420 [details]
Test case

Some WCF methods that do _not_ use "ref" parameters fail with "InvalidOperationException" during "ClientRuntimeChannel.EndProcess" when called via a ChannelFactory channel

## Regression status: regression caused by mono/8b10d9b + mono/87622fc (the fix for Bug 22129)

These changes were first released in Mono 3.12.0.

### Details

I can stop the problem if I comment out the following three lines from `System.ServiceModel/ClientRuntimeChannel.cs` and rebuild "System.ServiceModel.dll":

> if (p.Length == parameters.Length)
>	throw new InvalidOperationException ();
> Array.Copy (p, parameters, p.Length);

## Steps to reproduce

Build and run the attached test case. This is a tiny little console program that uses the W3 Schools' TempConvert example service.

## Results

### Debugging into the `EndProcess()` source

The two key lines are:

> object[] p = parameters;
> _processDelegate.EndInvoke (ref p, result);

After the first line, `p.Length` is 1.
After the second line, `p.Length` is 0.

The length of 0 causes an exception to be thrown later in the method:

> if (p.Length != parameters.Length)
> 	throw new InvalidOperationException ();

Maybe it is not strictly true that the number of input parameters must match the number of output parameters? Or perhaps the count of input parameters is incorrect? I don't think the input parameter for this service is a `ref` parameter, so maybe the count of input parameters is meant to be 0 rather than 1?

### Stack trace

> System.InvalidOperationException: Operation is not valid due to the current state of the object
>   at System.ServiceModel.MonoInternal.ClientRuntimeChannel.EndProcess (System.Reflection.MethodBase method, System.String operationName, System.Object[] parameters, IAsyncResult result) [0x00059] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr3/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.3/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:463 
>   at System.ServiceModel.ClientRealProxy.DoInvoke (IMessage inputMessage) [0x001f3] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr3/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.3/mcs/class/System.ServiceModel/System.ServiceModel/ClientRealProxy.cs:130 
>   at System.ServiceModel.ClientRealProxy.Invoke (IMessage inputMessage) [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr3/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.3/mcs/class/System.ServiceModel/System.ServiceModel/ClientRealProxy.cs:86 
>   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke (System.Runtime.Remoting.Proxies.RealProxy rp, IMessage msg, System.Exception& exc, System.Object[]& out_args) [0x0009c] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr3/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.3/mcs/class/corlib/System.Runtime.Remoting.Proxies/RealProxy.cs:194  

## Results on .NET on Windows

The test case builds and runs successfully. The WCF request completes, and the program outputs the return value from the service:

> The converted value is: 37
Comment 2 Martin Baulig 2015-08-18 14:03:00 UTC
Should be fixed now.
Comment 3 Miguel de Icaza [MSFT] 2015-08-19 10:39:46 UTC