2

I am trying to add a reference to a WCF service in my project but whenever I do it, the classes in the Reference.cs file have the attribute [Microsoft.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.3-preview3.21351.2")] on top of it instead of [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")] (which I usually see in other projects).

The problem is that the assemblies for Microsoft.CodeDom can't be found. I found a nuget package named Microsoft.CodeDom.Providers.DotNetCompilerPlatfor but it is not compatible with .NET 5.

Also using a pre-release version of a package seems weird (2.0.3-preview3.21351.2).

Would anyone know why Visual Studio is generating that odd Reference.cs file?

If I try to add a reference to the same WCF service in a .NET Framework 4.8 project the Reference.cs file is generated as expected (using the attribute [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]).

Here is the information about my Visual Studio installation

Microsoft Visual Studio Professional 2019 Version 16.11.3 VisualStudio.16.Release/16.11.3+31702.278 Microsoft .NET Framework Version 4.8.04084

Installed Version: Professional

.NET Core Debugging with WSL 1.0 .NET Core Debugging with WSL

ASP.NET and Web Tools 2019 16.11.75.64347 ASP.NET and Web Tools 2019

ASP.NET Web Frameworks and Tools 2019 16.11.75.64347 For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0 16.11.75.64347 Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools 16.11.75.64347 Azure Functions and Web Jobs Tools

C# Tools 3.11.0-4.21403.6+ae1fff344d46976624e68ae17164e0607ab68b10 C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

IntelliCode Extension 1.0 IntelliCode Visual Studio Extension Detailed Info

Microsoft Azure Tools for Visual Studio 2.9 Support for Azure Cloud Services projects

Microsoft Continuous Delivery Tools for Visual Studio 0.4 Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager 2.1.113+g422d40002e.RR Install client-side libraries easily to any web project

Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual Studio Tools for Containers 1.2 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Node.js Tools 1.5.30526.3 Commit Hash:c09c81113bcbc86d57943fcdd67e82434263d61d Adds support for developing and debugging Node.js apps in Visual Studio

NuGet Package Manager 5.11.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info

Razor (ASP.NET Core)
16.1.0.2122504+13c05c96ea6bdbe550bd88b0bf6cdddf8cde1725 Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 16.0.62107.28140 Microsoft SQL Server Data Tools

TypeScript Tools 16.0.30526.2002 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools
3.11.0-4.21403.6+ae1fff344d46976624e68ae17164e0607ab68b10 Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools
16.11.0-beta.21322.6+488cc578cafcd261d90d748d8aaa7b8b091232dc Microsoft Visual F# Tools

Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Container Tools Extensions 1.0 View, manage, and diagnose containers within Visual Studio.

Visual Studio Tools for Containers 1.0 Visual Studio Tools for Containers

Cícero Neves
  • 401
  • 4
  • 13
  • You can first check that the properties of the corresponding class are checked by right-clicking add service reference. Then check to see if the class is a data contract attribute. You can refer to [this post](https://stackoverflow.com/questions/29495337/strange-reference-class-generation-when-using-wcf) to see if it helps. – Jiayao Oct 04 '21 at 09:01
  • @Jiayao, I checked the post you referred but I don't think that issue and mine are the same I am not having issues with which properties/fields are exposed in the auto-generated code but rather with the attributes being added to the auto-generated classes – Cícero Neves Oct 04 '21 at 19:01
  • I'm sorry that the previous answer didn't help you. You say that in.NET Framework 4.8 it is recognized normally, but in.NET 5 the file is not generated correctly, and the correct file contents can be copied over. Vs may have compatibility issues with files generated when service references are added to.NET 5. – Jiayao Oct 06 '21 at 08:45
  • It was my first thought. However my coworkers are able to generate those just fine for .NET 5 Thanks anyway – Cícero Neves Oct 08 '21 at 16:33
  • @CíceroNeves have you been able to solve the issue since then? – Andrei Ivascu Jan 06 '22 at 13:48
  • @AndreiIvascu, unfortunately no :/ I believe this to be a bug Are you facing the same issue? – Cícero Neves Jan 11 '22 at 23:04
  • 1
    @AndreiIvascu, I found out that VS 2019 was using version 2.0.3.preview.3.21351.2 of donet-svcutil to generated the reference file (no idea why it is using a preview version of a package though).What I did was install version 2.0.2 and run it via powershell or command line to update the reference. VS insists in using the preview version of the package even though I have version 2.0.2 installed. Hope that helps you – Cícero Neves Mar 30 '22 at 18:27
  • @CíceroNeves thank you for the update. We indeed were facing the same issue however we just opted out of the .NET 5 implementation at all. Instead we are using a .NET Framework 4.8 WCF service while we migrate to something more native to .NET 6. – Andrei Ivascu Mar 31 '22 at 11:28

1 Answers1

4

I found out that VS 2019 was using version 2.0.3.preview.3.21351.2 of donet-svcutil to generated the reference file (no idea why it is using a preview version of a package though)

So this is more an workaround then a solution but I managed to add update an existing reference by doing the following (I ran all commands in Powershell):

  1. Install version 2.0.2 of dotnet-svcutil

    dotnet tool update --global dotnet-svcutil --version 2.0.2

  2. To Update a reference go the root of the project which has the WCF reference and do

    dotnet-svcutil --update {path for the folder which contains the Reference.cs file}

To add a new reference you may refer to the doc of dotnet-svcutil by running

dotnet-svcutil -h

I have also created an issue for VisualStudio team so they can investigate why it is using a preview version of the nuget package You can access it here

Cícero Neves
  • 401
  • 4
  • 13