Jul 30 2022 06:26 PM - edited Jul 30 2022 06:31 PM
I'm trying to upgrade a Xamarin Android Native app to .NET 6 which connects to a Web Service (asmx) but I get many deserialization issues.
To isolate the issue I took HelloAndroid project from @JamesMontemagno repo: https://github.com/jamesmontemagno/net6-mobile-samples and added a Connected Service.
Here are the details on the deserialization issue:
My Visual Studio Version is: 2022 Community (64-bit) Version 17.3.0 Preview 5.0
Here is my csproj file for the Android .NET 6 Project:
<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
@JamesMontemagno Any ideas on why deserialization behaves different with the net6.0-android31.0 TFM?
Aug 02 2022 02:37 AM
Hi @Adolfo Perez,
Aug 02 2022 03:55 AM - edited Aug 02 2022 03:55 AM
@LanHuang hi. I have also posted on Q&A https://docs.microsoft.com/en-us/answers/questions/948725/asmx-web-service-client-net-6-android-dese... but they are telling me that Xamarin Traditional (Not MAUI) should target .net Standard which I don't think is right. Per my understanding Xamarin Traditional upgrade path should target .Net 6 as @JamesMontemagno did in his HelloAndroid project. I wish this wasn't this confusing