Issues migrating WCF Client from .NET Standard to MultiTarget
- Dominant language
- C#
- Stars
- 1.8k
- Forks
- 576
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 2
Description
**Describe the bug**
Over the last couple years we've migrated all our SOAP clients to Connected Services WCF Client on .NET standard 2.0 referencing the System.ServiceModel.* 4.*.* NuGet packages for consumption in a .NET framework 4.8 solution with a long term goal of targeting the latest versions of .NET (8 and beyond). I recently stumbled upon the [drop of support of .NET standard 2.0](https://learn.microsoft.com/en-us/dotnet/core/compatibility/wcf-client/6.0/net-standard-2-support) for WCF Client and started to understand what that means for our team. The docs linked in the previous sentence lists multi targeting as the solution.
I started noticing some issues with the migration to a multi target solution.
**To Reproduce**
Steps to reproduce the behavior:
1. Create a .net standard 2.0 library project.
2. Add a Connected Services WCF Service Client using the svc-util "wizard" within Visual Studio 2022 Version 17.8.7
3. This will Generate a Reference.cs file with an implementation for `CloseAsync()`
4. update `netstandard2.0` to `net48;net8.0`
5. replace all the System.ServiceModel PackageReference nodes with conditional statements as seen below:
```
```
7. build the solution
8. observe CS1061 build failures `'XXXClient' does not contain a definition for 'CloseAsync' and no accessible extension method 'CloseAsync' accepting a first argument of type 'XXXClient' could be found (are you missing a using directive or an assembly reference?)`
**Expected behavior**
given the Microsoft documentation to simply "multi target" any .NET standard 2.0 projects, I expected a successful build.
**Screenshots**
n/a
**Additional context**
I also noticed if I create a brand new .net8.0 class library and try to add a WCF Client, it's still using the 4.10.* version of the System.ServiceModel.* instead of the 8.0.0 versions. In this scenario, it does not generate the `CloseAsync` methods that failed the build in the multi target scenario.
I also noticed that while using the multi target approach, if I try to create an instance of the `XXXClient` CloseAsync is an available method in .net4.8 and is not available in .net8.0. I could not find any documentation mentioning this breaking change.
```
var client = new XXXServiceClient(new BasicHttpBinding(), new EndpointAddress(@"https://foo/foo.svc"));
client.CloseAsync();
```
Contributor guide
Assessment
This issue has not been assessed yet.