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.7k stars 559 forks source link

Upgrade to 6.0.0 (from 4.10.2) is missing IBindingRuntimePreferences #5202

Open amjidq opened 1 year ago

amjidq commented 1 year ago

I have a wcf CustomBinding that is using BasicHttpBinding. After the upgrade to 6.0.0 I get the following error in VS 2022

Error CS7069 Reference to type 'IBindingRuntimePreferences' claims it is defined in 'System.ServiceModel.Primitives', but it could not be found

I have added the nuget package Primitives. As well as alot of others to test with no joy

Looking in github, the interface exists in the RTM tag but not the 6.0.0 tag is this the problem??? Or am I doing something wrong??

https://github.com/dotnet/wcf/blob/**v6.0.0-rtm**/src/System.ServiceModel.Primitives/src/System/ServiceModel/Channels/IBindingRuntimePreferences.cs

https://github.com/dotnet/wcf/blob/**v6.0.0**/src/System.ServiceModel.Primitives/src/System/ServiceModel/Channels/IBindingRuntimePreferences.cs

I have replicated this on a new console app with a class library with a single class ConsoleApp1.zip](https://github.com/dotnet/wcf/files/12075724/ConsoleApp1.zip)

TestClass.cs

using System.ServiceModel;
using System.ServiceModel.Channels;

namespace TestNamespace
{

    public abstract class TestClass
    {
        private static CustomBinding BuildBinding()
        {
            //ERROR ON LINE BELOW
            var binding = new CustomBinding(new BasicHttpBinding
            {
                MaxBufferSize = int.MaxValue,
                ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max,
                MaxReceivedMessageSize = int.MaxValue,
                AllowCookies = true,
                Security =
                {
                    Mode = BasicHttpSecurityMode.TransportWithMessageCredential,
                }
            });

            return binding;

        }
    }
}

The ClassLibrary1.csproj file is as follows

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="System.ServiceModel.Duplex" Version="6.0.0" />
    <PackageReference Include="System.ServiceModel.Http" Version="6.0.0" />
    <PackageReference Include="System.ServiceModel.NetTcp" Version="6.0.0" />
    <PackageReference Include="System.ServiceModel.Primitives" Version="6.0.0" />
    <PackageReference Include="System.ServiceModel.Security" Version="6.0.0" />
    <PackageReference Include="System.ServiceModel.Syndication" Version="6.0.0" />
  </ItemGroup>

</Project>

ConsoleApp1.zip

amjidq commented 1 year ago

hey, thanks for the fix. DO you know when the fix will be available and is there a nightly build I could test on???

v-karnaukhov commented 1 year ago

Hi! Very important feature for my project too. Is where any information about plans of releasing it?

munichmule commented 1 year ago

@imcarolwang @HongGit @mconnew Hey guys, could you provide a workaround or something?

johannesmols commented 1 year ago

Having the same issue here, when will this be released?

imcarolwang commented 1 year ago

I am also not sure of the release schedule. To unblock compiling, try cast type BasicHttpBinding to type Binding explicitly when passing it as parameter for composing CustomBinding instance?

bdcberuni commented 9 months ago

Same issue with the interface System.ServiceModel.Channels.IMergeEnabledMessageProperty.

Can be easily reproduced with the following test:

using System.ServiceModel.Channels;
using Xunit;

namespace ServiceModelPrimitives;

public class ServiceModelPrimitivesTests
{
    [Fact]
    public void UsingHttpRequestMessageProperty_ShouldCompile()
    {
        var actual = new HttpRequestMessageProperty();
        Assert.NotEqual(null, actual);
    }
}

Will throw the following compilation error:

Error CS7069 : Reference to type 'IMergeEnabledMessageProperty' claims it is defined in 'System.ServiceModel.Primitives', but it could not be found

Reproducible using System.ServiceModel.Http version 6.0.0, 6.0.1, 6.0.2 on dotnet 6, dotnet 7 and dotnet 8.

Here's the csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <IsPackable>false</IsPackable>
    <IsTestProject>true</IsTestProject>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="System.ServiceModel.Http" Version="6.0.2" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
    <PackageReference Include="xunit" Version="2.4.2" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="coverlet.collector" Version="6.0.0">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>
</Project>
Lanayx commented 4 months ago

So, it's really wierd This doesn't compile [CS7069] Reference to type 'IMergeEnabledMessageProperty' claims it is defined in 'System.ServiceModel.Primitives', but it could not be found

        var actual = new HttpRequestMessageProperty();
        Assert.NotEqual(null, actual);

this compiles well

        var actual = new HttpRequestMessageProperty();
        Assert.NotNull(actual);
bdcberuni commented 4 months ago

So, it's really wierd This doesn't compile [CS7069] Reference to type 'IMergeEnabledMessageProperty' claims it is defined in 'System.ServiceModel.Primitives', but it could not be found

        var actual = new HttpRequestMessageProperty();
        Assert.NotEqual(null, actual);

this compiles well

        var actual = new HttpRequestMessageProperty();
        Assert.NotNull(actual);

I suppose it's because XUnit Assert.Equal is creating a custom EqualityComparer that uses reflection, which triggers the exception to be thrown.

yarutyunov commented 4 months ago

the only way i could get around this issue is to do this:

//request.Should().NotBeNull();
if (request == null) throw new InvalidOperationException("Request is null");