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

C++/CLI in Visual Studio #28762

Merged
merged 3 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/core/compatibility/7.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ If you're migrating an app to .NET 7, the breaking changes listed here might aff
| Title | Binary compatible | Source compatible | Introduced |
| - | :-: | :-: | - |
| [API obsoletions with non-default diagnostic IDs](core-libraries/7.0/obsolete-apis-with-custom-diagnostics.md) | ✔️ | ❌ | Preview 1 |
| [C++/CLI projects in Visual Studio](core-libraries/7.0/cpluspluscli-compiler-version.md)
| [FullPath and OldFullPath return fully qualified path](core-libraries/7.0/filesystemeventargs-fullpath.md) | ✔️ | ❌ | Preview 1 |
| [Generic type constraint on PatternContext\<T>](core-libraries/7.0/patterncontext-generic-constraint.md) | ❌ | ❌ | Preview 3 |
| [SerializationFormat.Binary is obsolete](core-libraries/7.0/serializationformat-binary.md) | ❌ | ❌ | Preview 2 |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: ".NET 7 breaking change: Compiling C++/CLI projects in Visual Studio"
description: Learn about the .NET 7 breaking change in core .NET libraries where Visual Studio version 17.2 Preview 2 is required to compile .NET 7 Preview 3 C++/CLI projects.
ms.date: 03/21/2022
---
# C++/CLI projects in Visual Studio

.NET 7 Preview 3 includes *generic math* APIs that use `static abstract` interface members on primitive types, such as <xref: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 you don't use the generic math features directly.

Beyond C++/CLI, it's also possible that the introduction of `static abstract` interface members on primitive <xref:System> types will surface issues in other tools that aren't forward-compatible with the usage of this new language construct. If you're a tool author, you'll need to update any tools impacted by this change to accommodate the usage of `static abstract` interface members. If you need help, [file an issue in the dotnet/runtime repo](https://github.com/dotnet/runtime/issues/new) to request guidance.

## Previous behavior

Previously, compiling .NET projects using C++/CLI did not result in errors related to members on primitive <xref:System> types.

## New behavior

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

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

Other than upgrading, there's no way to work around this compiler error. It's generated because of `static abstract` interface members on primitive <xref:System> types. By upgrading to Visual Studio 2022 version 17.2 Preview 2+, the compilation errors will no longer occur.
gewarren marked this conversation as resolved.
Show resolved Hide resolved

Implicitly implemented `static abstract` interface members can be invoked, but even with Visual Studio 2022 version 17.2 Preview 2+, C++/CLI doesn't support invoking explicitly implemented `static abstract` interface members.

## Version introduced

.NET 7 Preview 3

## Type of breaking change

This change can affect [source compatibility](../../categories.md#source-compatibility).

## 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 and required you to install the `System.Runtime.Experimental` package to gain access. Starting in .NET 7 Preview 3, these generic math APIs are included "in box".

## Recommended action

To continue using C++/CLI with .NET 7 Preview 3+, upgrade to Visual Studio 2022 version 17.2 Preview 2 or a later version.

## Affected APIs

N/A

## See also

- [Visual Studio 2022 version 17.2 Preview - release notes](/visualstudio/releases/2022/release-notes-preview)
4 changes: 4 additions & 0 deletions docs/core/compatibility/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ items:
items:
- name: API obsoletions with non-default diagnostic IDs
href: core-libraries/7.0/obsolete-apis-with-custom-diagnostics.md
- name: C++/CLI projects in Visual Studio
href: core-libraries/7.0/cpluspluscli-compiler-version.md
- name: FullPath and OldFullPath return fully qualified path
href: core-libraries/7.0/filesystemeventargs-fullpath.md
- name: Generic type constraint on PatternContext<T>
Expand Down Expand Up @@ -689,6 +691,8 @@ items:
items:
- name: API obsoletions with non-default diagnostic IDs
href: core-libraries/7.0/obsolete-apis-with-custom-diagnostics.md
- name: C++/CLI projects in Visual Studio
href: core-libraries/7.0/cpluspluscli-compiler-version.md
- name: FullPath and OldFullPath return fully qualified path
href: core-libraries/7.0/filesystemeventargs-fullpath.md
- name: Generic type constraint on PatternContext<T>
Expand Down