ASMX web service client .NET 6 (Android) Deserialization error with net6.0-android31.0 TFM
I'm running into a Web Service deserialization issue in a Xamarin .NET 6 Android project.
My Visual Studio Version is: Version 17.3.0 Preview 5.0
Here is my csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-android31.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.ServiceModel.Duplex" Version="4.9.0" />
<PackageReference Include="System.ServiceModel.Federation" Version="4.9.0" />
<PackageReference Include="System.ServiceModel.Http" Version="4.9.0" />
<PackageReference Include="System.ServiceModel.NetTcp" Version="4.9.0" />
<PackageReference Include="System.ServiceModel.Security" Version="4.9.0" />
<PackageReference Include="Xamarin.AndroidX.AppCompat" Version="1.3.0" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.3.0.1" />
</ItemGroup>
</Project>
I added a Connected Service pointing to an ASMX file and I get this exception when calling one of my Web Service methods:
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:GetLastLoginResponse. The InnerException message was 'There was an error deserializing the object of type ServiceReference1.GetLastLoginResponseBody. Unexpected end of file. Following elements are not closed: GetLastLoginResponse, Body, Envelope. Line 1, position 334.'. Please see InnerException for more details.
Inner exception: Unexpected end of file. Following elements are not closed: GetLastLoginResponse, Body, Envelope. Line 1, position 334.
The strange thing is that when I change the TFM to:
<TargetFramework>net6.0-android</TargetFramework>
Then I don't get the deserialization exception
Here is the Full Stack Trace:
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest) in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Dispatcher/DataContractSerializerOperationFormatter.cs:line 543
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameter(XmlDictionaryReader reader, PartInfo part, Boolean isRequest) in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Dispatcher/DataContractSerializerOperationFormatter.cs:line 513
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameters(XmlDictionaryReader reader, PartInfo[] parts, Object[] parameters, Boolean isRequest) in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Dispatcher/DataContractSerializerOperationFormatter.cs:line 484
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest) in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Dispatcher/DataContractSerializerOperationFormatter.cs:line 465
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest) in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Dispatcher/OperationFormatter.cs:line 259
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(Message message, Object[] parameters) in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Dispatcher/OperationFormatter.cs:line 133
at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc& rpc) in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Dispatcher/ProxyOperationRuntime.cs:line 137
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/ServiceChannel.cs:line 956
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/ServiceChannel.cs:line 775
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/ServiceChannel.cs:line 715
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(MethodCall methodCall, ProxyOperationRuntime operation) in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/ServiceChannelProxy.cs:line 372
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(MethodInfo targetMethod, Object[] args) in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/ServiceChannelProxy.cs:line 144
at generatedProxy_1.GetLastLogin(GetLastLoginRequest )
at ServiceReference1.TimeCardServiceSoapClient.ServiceReference1.TimeCardServiceSoap.GetLastLogin(GetLastLoginRequest request) in C:\Development\GitRepos\Prototypes\net6-mobile-samples-main\HelloAndroid\Connected Services\ServiceReference1\Reference.cs:line 12866
at ServiceReference1.TimeCardServiceSoapClient.GetLastLogin(String username, String password, String userType, String& message) in C:\Development\GitRepos\Prototypes\net6-mobile-samples-main\HelloAndroid\Connected Services\ServiceReference1\Reference.cs:line 12876
at HelloAndroid.MainActivity.OnCreate(Bundle savedInstanceState) in C:\Development\GitRepos\Prototypes\net6-mobile-samples-main\HelloAndroid\MainActivity.cs:line
Any ideas on why deserialization behaves different with the net6.0-android31.0 TFM?