dotnet / wcf

This repo contains the client-oriented WCF libraries that enable applications built on .NET Core to communicate with WCF services.
MIT License
1.71k stars 558 forks source link

.net core 2 serialisation issue talking to wcf with System.Data.Linq.Binary property (The use of type 'System.Data.Linq.Binary' as a get-only collection is not supported with NetDataContractSerializer) #2951

Closed bafrin closed 6 years ago

bafrin commented 6 years ago

System.Data.Linq is not part of .NET Core 2.0 and therefore the following class is created in the data contract while importing service reference wsdl

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="Binary", Namespace="http://schemas.datacontract.org/2004/07/System.Data.Linq")]
public partial class Binary : object
{        
    private byte[] BytesField;
    [System.Runtime.Serialization.DataMemberAttribute()]
    public byte[] Bytes
    {
        get
        {
            return this.BytesField;
        }
        set
        {
            this.BytesField = value;
        }
    }
}

As you see, it has a setter. But at run time it ends in the following exception

"The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter ... The InnerException message was 'The use of type 'System.Data.Linq.Binary' as a get-only collection is not supported with NetDataContractSerializer. Consider marking the type with the CollectionDataContractAttribute attribute or the SerializableAttribute attribute or adding a setter to the property.'. Please see InnerException for more details."

" at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)\r\n at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)\r\n at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)\r\n at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass1_0.b__0(IAsyncResult asyncResult)\r\n--- End of stack trace from

The same wsdl does not create a binary class in .net framework and simply uses System.Data.Linq.Binary

I have already tried IgnoreDataMemberAttribute SerializableAttribute CollectionDataContractAttribute

but non of them help. I even tried a .net framework class library making the service call to wcf as a reference in .net core2 project but resulted in the framework version is not supported

Any help would be appreciated

Lxiamail commented 6 years ago

@bafrin Can you share the WSDL file that reproduce the problem?

bafrin commented 6 years ago

Hi @Lxiamail, Thanks for your comment, I am still struggling with this issue; Expression: (new System.Collections.Generic.Mscorlib_CollectionDebugView(((System.ServiceModel.FaultException)error).Reason.Translations.Items).Items[0]).Text

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter ... The InnerException message was 'The use of type 'System.Data.Linq.Binary' as a get-only collection is not supported with NetDataContractSerializer. Consider marking the type with the CollectionDataContractAttribute attribute or the SerializableAttribute attribute or adding a setter to the property.'. Please see InnerException for more details. ---InnerException---- The use of type 'System.Data.Linq.Binary' as a get-only collection is not supported with NetDataContractSerializer. Consider marking the type with the CollectionDataContractAttribute attribute or the SerializableAttribute attribute or adding a setter to the property.

Unfortunately I cannot share the original wsdl for you and I haven't been able to replicate the error in a new project!! I will share the wsdl as soon as it is ready!

StephenBonikowsky commented 6 years ago

@bafrin any updates on this issue?

Lxiamail commented 6 years ago

@bafrin NetDataContractSerializer is not supported on WCF Core. Are you doing this on .NET Framework?

Lxiamail commented 6 years ago

@bafrin Haven't heard back from you for sometime. Closing this issue for now.