Bug 32886

Summary: [Mono 3.12] Some WCF methods that do _not_ use "ref" parameters fail with "InvalidOperationException" during "ClientRuntimeChannel.EndProcess" when called via a ChannelFactory channel
Product: [Mono] Installers Reporter: Brendan Zagaeski (Xamarin Team, assistant) <brendan.zagaeski>
Component: GeneralAssignee: Martin Baulig <martin.baulig>
Severity: normal CC: geir.rune, greg.rivington, miguel, mono-bugs+mono
Priority: ---    
Version: 4.0.0   
Target Milestone: 4.2.0 (C6)   
Hardware: PC   
OS: All   
Tags: BZRC4A1_C3S2 Is this bug a regression?: ---
Last known good build:
Attachments: Test case

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