Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Breaking change] .NET 7 with C++/CLI requires Visual Studio 2022 17.2 Preview 2 #28542

Closed
1 of 2 tasks
jeffhandley opened this issue Mar 9, 2022 · 9 comments · Fixed by #28762
Closed
1 of 2 tasks
Assignees
Labels
breaking-change Indicates a .NET Core breaking change 🏁 Release: .NET 7 Work items for the .NET 7 release doc-idea Indicates issues that are suggestions for new topics [org][type][category] Pri1 High priority, do before Pri2 and Pri3 source incompatible Source code may encounter a breaking change in behavior when targeting the new version.

Comments

@jeffhandley
Copy link
Member

Description

Starting in .NET 7 Preview 3, Visual Studio 2022 17.2 Preview 2+ must be used for C++/CLI projects.

.NET 7 Preview 3 includes "Generic Math" APIs that use static abstract interface members on primitive types such as System.Int32; earlier versions of the C++/CLI compiler were incompatible with such members. Because those members are used on many primitive types, compilation errors will occur when targeting net7.0 even if the Generic Math features are not used directly.

Beyond C++/CLI, it's also possible that the introduction of static abstract interface members on primitive System types will surface issues in other tools that are not forward-compatible with the usage of this new language construct. As was done with C++/CLI, any other tools impacted by this change will need to be updated to accommodate the usage of static abstract interface members. If needed on such issues, tool authors should file a New Issue · dotnet/runtime to request guidance.

Pull Request: Moving "Generic Math" in box and making it no longer experimental by tannergooding · Pull Request #65731 · dotnet/runtime

Version

.NET 7 Preview 3

Previous behavior

Compiling .NET projects using C++/CLI would not result in errors related to members on primitive System types.

New behavior

Compiling a .NET 7 Preview 3 net7.0 project using C++/CLI in an earlier release of Visual Studio will result in many errors similar to this example:

error C2253: 'System.Int32.Parse': pure specifier or abstract override specifier only allowed on virtual function

There is no way to work around this compiler error as it's generated because of static abstract interface members on primitive System types. By upgrading to Visual Studio 2022 17.2 Preview 2+, the compilation errors will no longer occur.

Implicitly-implemented static abstract interface members can be invoked, but even with Visual Studio 2022 17.2 Preview 2+ C++/CLI does not support invoking explicitly-implemented static abstract interface members.

Type of breaking change

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load/execute or different run-time behavior.
  • Source incompatible: Source code may encounter a breaking change in behavior when targeting the new runtime/component/SDK, such as compile errors or different run-time behavior.

Reason for change

.NET 7 Preview 3 includes the new API definitions for the "Generic Math" feature set. These APIs were introduced in .NET 6 as a preview feature, requiring an additional System.Runtime.Experimental package to be installed to gain access to the APIs. Those APIs are being included in-box with .NET 7 Preview 3 with further stabilization and refinement to come in later .NET 7 previews.

See Developers can use Generic Math without enabling preview features · Issue #63548 · dotnet/runtime for more information.

Recommended action

Upgrade to Visual Studio 2022 17.2 Preview 2+ to continue using C++/CLI with .NET 7 Preview 3+. See Visual Studio 2022 Preview Release Notes | Microsoft Docs for more information and downloads.

Feature area

Core .NET libraries

Affected APIs

No response

@jeffhandley jeffhandley added doc-idea Indicates issues that are suggestions for new topics [org][type][category] breaking-change Indicates a .NET Core breaking change Pri1 High priority, do before Pri2 and Pri3 labels Mar 9, 2022
@dotnet-bot dotnet-bot added ⌚ Not Triaged Not triaged 🏁 Release: .NET 7 Work items for the .NET 7 release source incompatible Source code may encounter a breaking change in behavior when targeting the new version. labels Mar 9, 2022
@dotnet-bot dotnet-bot removed the ⌚ Not Triaged Not triaged label Apr 1, 2022
@DerekSMorin
Copy link

0

I'm trying to use:
Visual Studio = Version 17.3.0 Preview 1.1
And Microsoft.NET SDK 7.0.100-preview.4.22252.9 (x64)

I seem to be getting a similar error. @gewarren?

I've been able to compile some csproj projects but for my vcxproj I am getting:

6>C:\Development\Source\ApmUpdateDotNet7\framework\oqkern\shared\ManagedDateTime.cpp(31,4): error C2220: the following warning is treated as an error 6>C:\Development\Source\ApmUpdateDotNet7\framework\oqkern\shared\ManagedDateTime.cpp(31,4): warning C4679: 'Parse': could not import member 6>C:\Development\Source\ApmUpdateDotNet7\framework\oqkern\shared\ManagedDateTime.cpp(31,4): message : static virtual methods of interfaces are not supported and will be unavailable 6>C:\Development\Source\ApmUpdateDotNet7\framework\oqkern\shared\ManagedDateTime.cpp(31,4): message : This diagnostic occurred while importing type 'System::IParsable' from assembly 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

@gewarren
Copy link
Contributor

@tannergooding Can you take a look at @DerekSMorin's situation and advise?

@tannergooding
Copy link
Member

This is expected. C++/CLI changed what was a hard error into a warning. You likely have /warnaserror or similar enabled (as per the following warning is treated as an error) and so you'll need to disable C2220.

@DerekSMorin
Copy link

Thanks @tannergooding - I ended up having to disable 4679 and thanks to your help I managed to get things compiling.

image

@mo-russo
Copy link

mo-russo commented Apr 12, 2023

Visual Studio = Version 17.5.3
Microsoft.NET SDK 7.0.202

I'm getting a bunch of of errors like this one when trying to compile my C++/CLI project with .NET 7:

error C2253: 'System::IParsable::Parse': pure specifier or abstract override specifier only allowed on virtual function
message : This diagnostic occurred while importing type 'System::IParsable ' from assembly 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
message : This diagnostic occurred while importing type 'System::Int32 ' from assembly 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Here's the line on which the error above occurs:
var myList = gcnew List<MyObject^>();

I read the post here: https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/7.0/cpluspluscli-compiler-version

I thought that using the latest VS2022 would fix this issue, but it didn't. And in my case, it's not warning considered as error type thing like @DerekSMorin so I can't disable any warning to make it compile.

Any advice?

UPDATE
For some reason the Platform Toolset was set to v142. Setting it to v143, I got the same as Derek and was able to disable the same warning code.

@bouchraRekhadda
Copy link

bouchraRekhadda commented Dec 6, 2023

Hello,

We are getting similar error (not a warning) on our C++/CLI projects moving from .NET 6 to .NET 8.

  • Visual Studio: 17.8
  • Platform Toolset: v142
  • SDK: 8.0.100

The article pointed by @mo-russo doesn't seem to explicitly suggest to move to Platform Toolset v143. Is this the case ?

@tannergooding
Copy link
Member

tannergooding commented Dec 6, 2023

In general each new version of .NET requires the latest version of VS, VSCode, Rider, etc and the latest version of various other toolchains, such as C++.

It's entirely possible they partially work on older versions, but the experience will often be subpar or may break down when encountering various edges or newly introduced APIs, language or runtime features, etc (if you're on an older IDE, then IntelliSense may not be up to date with the actual build for example).

.NET 8 requires C++/CLI v143 and VS 2022 v17.8.0 or later core types, such as Int32 are continuing to take advantage of the latest features, such as by expanding the generic math support via default interface members (DIMs).

@bouchraRekhadda
Copy link

Thanks @tannergooding for your explanation.
Is there currently any workaround for those stuck on PlatformToolset v142 that wan't to upgrade to .NET 8 quickly?

@tannergooding
Copy link
Member

I am not aware of any workaround. C++/CLI required changes to support newer runtime features, such as static virtuals on interfaces and default interface members. These changes were only implemented on newer platform toolsets. Since these features are used on types such as System.Int32, which is used in every single C++/CLI application, there is no workaround except to update to the latest toolset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Indicates a .NET Core breaking change 🏁 Release: .NET 7 Work items for the .NET 7 release doc-idea Indicates issues that are suggestions for new topics [org][type][category] Pri1 High priority, do before Pri2 and Pri3 source incompatible Source code may encounter a breaking change in behavior when targeting the new version.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants