Skip to content

XmlBinaryReader.ReadElementContentAsDouble() double.NaN deserialization issue .net7 #79056

Closed
@jvnvenu

Description

@jvnvenu

Description

XmlBinaryReader.ReadElementContentAsDouble() is not working for double.NaN which is throwing an exception in .net7 The input source is not correctly formatted.. But which is working fine in .net6.

We are using CoreWCF and we are trying to send double.NaN as a parameter. Samething we are getting the below exception .net7
System.ServiceModel.FaultException: 'The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'NanTest'. The input source is not correctly formatted.'. But which is working fine in .net6

Reproduction Steps

Run the below code

var message = System.ServiceModel.Channels.Message.CreateMessage(System.ServiceModel.Channels.MessageVersion.Default,
    "http://tempuri.org/IHelpServ/NanTest",
    double.NaN);
var reader = message.GetReaderAtBodyContents();
double value = reader.ReadElementContentAsDouble();

Expected behavior

It should deserialize the content as double

Actual behavior

throwing an exception in .net7 The input source is not correctly formatted.

Regression?

working fine in .net 6

Known Workarounds

No response

Configuration

.Net 7 - x64 - Windows

Other information

Core WCF snippet

[System.ServiceModel.ServiceContract]
public interface INanService
{
    [System.ServiceModel.OperationContract]
    void NanTest(double data);
}

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,
    ConcurrencyMode = ConcurrencyMode.Multiple)]
public class NanService : INanService
{
    public void NanTest(double data)
    {
    }
}

CoreWCF.NetTcpBinding binding = new CoreWCF.NetTcpBinding(CoreWCF.SecurityMode.None);
IWebHost webHost = WebHost.CreateDefaultBuilder()
.ConfigureServices(x =>
{
    x.AddServiceModelServices();
})
.UseNetTcp(IPAddress.IPv6Any, 1234)
.Configure(x =>
{
    x.UseServiceModel(y =>
    {
        y.AddService<NanService>();
        y.AddServiceEndpoint<NanService, INanService>(binding, "INanService");
    });
}).Build();
webHost.Start();
System.ServiceModel.NetTcpBinding binding1 = new System.ServiceModel.NetTcpBinding(System.ServiceModel.SecurityMode.None);
ChannelFactory<INanService> secureChannelFactory = new ChannelFactory<INanService>(binding1, null);
INanService service1 = secureChannelFactory.CreateChannel(new System.ServiceModel.EndpointAddress("net.tcp://localhost:1234/INanService"));
service1.NanTest(double.NaN);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions