Skip to content

Commit 1ab8309

Browse files
Merge pull request #6628 from MicrosoftDocs/jken/csharp-winrt-review
C#/WinRT docs: fix stale content, typos, and code errors
2 parents 9a8ddc5 + c5c072f commit 1ab8309

7 files changed

Lines changed: 31 additions & 31 deletions

hub/apps/develop/platform/csharp-winrt/agile-objects.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: An agile object is one that can be accessed from any thread. C#/WinRT provides support for agile references if you need to marshal a non-agile object across apartments in a safe way.
33
title: Agile objects with C#/WinRT
4-
ms.date: 11/17/2020
4+
ms.date: 04/13/2026
55
ms.topic: article
66
ms.localizationpriority: medium
77
---
@@ -40,6 +40,6 @@ You can now pass `agileReference` to a thread in a different apartment, and use
4040

4141
```csharp
4242
await Task.Run(() => {
43-
Windows.UI.Popups.PopupMenu nonAgileObjAgain = agileReference.Get()
43+
Windows.UI.Popups.PopupMenu nonAgileObjAgain = agileReference.Get();
4444
});
4545
```

hub/apps/develop/platform/csharp-winrt/authoring.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Author Windows Runtime components with C#/WinRT
33
description: Overview of authoring Windows Runtime Components with C#/WinRT
4-
ms.date: 03/15/2022
4+
ms.date: 04/13/2026
55
ms.topic: article
66
ms.localizationpriority: medium
77
---
@@ -11,11 +11,11 @@ ms.localizationpriority: medium
1111
> [!NOTE]
1212
> Authoring Windows Runtime components with C#/WinRT is supported on .NET 6 and later.
1313
14-
The C#/WinRT NuGet package provides support for authoring your own Windows Runtime types and components in C#, and consuming them from any Windows Runtime-compatible language such as [C++/WinRT](/windows/uwp/cpp-and-winrt-apis/) or [Rust](../../../../dev-environment/rust/rust-for-windows.md). C#/WinRT authoring and hosting support requires .NET 6 and Visual Studio 2026, and it is intended to support desktop application scenarios including the [Windows App SDK](../../../windows-app-sdk/index.md), and [WinUI3](../../../winui/winui3/index.md).
14+
The C#/WinRT NuGet package provides support for authoring your own Windows Runtime types and components in C#, and consuming them from any Windows Runtime-compatible language such as [C++/WinRT](/windows/uwp/cpp-and-winrt-apis/) or [Rust](../../../../dev-environment/rust/rust-for-windows.md). C#/WinRT authoring and hosting support requires .NET 6 or later and Visual Studio 2022 or later, and it is intended to support desktop application scenarios including the [Windows App SDK](../../../windows-app-sdk/index.md), and [WinUI3](../../../winui/winui3/index.md).
1515

16-
For a walkthrough showing how to author a Windows Runtime component with .NET 6, and how to consume it from a C++/WinRT console application, see [Walkthrough: Create a C#/WinRT component and consume it from C++/WinRT](./create-windows-runtime-component-cswinrt.md).
16+
For a walkthrough showing how to author a Windows Runtime component with .NET 6 or later, and how to consume it from a C++/WinRT console application, see [Walkthrough: Create a C#/WinRT component and consume it from C++/WinRT](./create-windows-runtime-component-cswinrt.md).
1717

18-
For more details, and to search for or file any issues, refer to the [C#/WinRT Github repo](https://github.com/microsoft/CsWinRT) and [Authoring C#/WinRT Components](https://github.com/microsoft/CsWinRT/blob/master/docs/authoring.md).
18+
For more details, and to search for or file any issues, refer to the [C#/WinRT GitHub repo](https://github.com/microsoft/CsWinRT) and [Authoring C#/WinRT Components](https://github.com/microsoft/CsWinRT/blob/master/docs/authoring.md).
1919

2020
## Declaring types in Windows Runtime components
2121

hub/apps/develop/platform/csharp-winrt/create-windows-runtime-component-cswinrt.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Walkthrough—Create a C#/WinRT component, and consume it from C++/WinRT
33
description: Author a Windows Runtime component with C#/WinRT, and consume it from a native application.
4-
ms.date: 03/15/2022
4+
ms.date: 04/13/2026
55
ms.topic: article
66
ms.localizationpriority: medium
77
---
@@ -18,8 +18,8 @@ For a walkthrough on authoring WinUI 3 controls with C#/WinRT specifically for u
1818

1919
This walkthrough requires the following tools and components:
2020

21-
- [Visual Studio 2022](/visualstudio/releases/2022/release-notes)
22-
- [.NET 6.0 SDK](https://dotnet.microsoft.com/download/dotnet) or later
21+
- [Visual Studio 2022 or later](/visualstudio/releases/2022/release-notes)
22+
- [.NET 8.0 SDK (LTS)](https://dotnet.microsoft.com/download) or later
2323
- [C++/WinRT VSIX](https://marketplace.visualstudio.com/items?itemName=CppWinRTTeam.cppwinrt101804264) for C++/WinRT project templates
2424

2525
## Create a simple Windows Runtime Component using C#/WinRT
@@ -41,7 +41,7 @@ Begin by creating a new project in Visual Studio. Select the **Class Library** p
4141

4242
a. In Solution Explorer, right click on the project node and select **Manage NuGet Packages**.
4343

44-
b. Search for the **Microsoft.Windows.CsWinRT** NuGet package and install the latest version. This walkthrough uses C#/WinRT version 1.4.1.
44+
b. Search for the **Microsoft.Windows.CsWinRT** NuGet package and install the latest version.
4545

4646
3. Add a new `PropertyGroup` element that sets the `CsWinRTComponent` property. This specifies that your project is a Windows Runtime component so that a `.winmd` file is generated when you build the project.
4747

@@ -95,7 +95,7 @@ When you build the package, the **Build** window should indicate that the NuGet
9595
C#/WinRT authored Windows Runtime components can be consumed from any Windows Runtime (WinRT)-compatible language. The following steps demonstrate how to call the authored component above in a C++/WinRT console application.
9696

9797
> [!NOTE]
98-
> Consuming a C#/WinRT component from C#/.NET apps is supported by both package reference or project reference. This scenario is equivalent to consuming any ordinary C# class library and does not involve WinRT activation in most cases. Starting with C#/WinRT 1.3.5, project references for C# consumers require .NET 6.
98+
> Consuming a C#/WinRT component from C#/.NET apps is supported by both package reference or project reference. This scenario is equivalent to consuming any ordinary C# class library and does not involve WinRT activation in most cases. Starting with C#/WinRT 1.3.5, project references for C# consumers require .NET 6 or later.
9999

100100
1. Add a new **C++/WinRT Console Application** project to your solution. Note that this project can also be part of a different solution if you choose so.
101101

hub/apps/develop/platform/csharp-winrt/create-winrt-component-winui-cswinrt.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Walkthrough—Create a C# component with WinUI controls, and consume it from a C++/WinRT app that uses the Windows App SDK
33
description: Author a Windows Runtime component with C#/WinRT with WinUI controls, and consume it from any Windows App SDK app.
4-
ms.date: 03/15/2022
4+
ms.date: 04/13/2026
55
ms.topic: article
66
ms.localizationpriority: medium
77
---
@@ -18,8 +18,8 @@ This walkthrough demonstrates how to author a C# component with a custom WinUI c
1818

1919
This walkthrough requires the following tools and components:
2020

21-
- [Visual Studio 2026](/visualstudio/releases/2026/release-notes)
22-
- [.NET 6.0 SDK](https://dotnet.microsoft.com/download/dotnet/6.0)
21+
- [Visual Studio 2022 or later](/visualstudio/releases/2022/release-notes)
22+
- [.NET 8.0 SDK (LTS)](https://dotnet.microsoft.com/download) or later
2323
- [Windows App SDK VSIX](../../../windows-app-sdk/downloads.md) (1.1 from the stable channel)
2424

2525
## Author your C#/WinRT component using the Windows App SDK
@@ -104,7 +104,7 @@ This walkthrough requires the following tools and components:
104104
1. You can now build the **WinUIComponentCs** project to generate a `.winmd` file for the component.
105105

106106
> [!NOTE]
107-
> You can also package the component as a NuGet package for end app consumers to reference. For more details, see [Authoring C#/WinRT components](https://github.com/microsoft/CsWinRT/blob/master/docs/authoring.md) on the C#/WinRT Github repo.
107+
> You can also package the component as a NuGet package for end app consumers to reference. For more details, see [Authoring C#/WinRT components](https://github.com/microsoft/CsWinRT/blob/master/docs/authoring.md) on the C#/WinRT GitHub repo.
108108

109109
## Reference the component from a Windows App SDK C++/WinRT app
110110

@@ -177,8 +177,8 @@ Consumption from packaged apps that use a separate **Windows Application Packagi
177177

178178
## Known issues
179179

180-
- Consuming a C# component as a project reference requires `PublishReadyToRun` to be set to `False`. See [Github Issue #1151](https://github.com/microsoft/CsWinRT/issues/1151) for more details.
181-
- Consuming a C# component built for `AnyCPU` from C++ is supported only from `x86` applications currently. `x64` and `Arm64` apps result in a runtime error similar to: *%1 is not a valid Win32 application.* See [Github Issue #1151](https://github.com/microsoft/CsWinRT/issues/1093) for more details.
180+
- Consuming a C# component as a project reference requires `PublishReadyToRun` to be set to `False`. See [GitHub Issue #1151](https://github.com/microsoft/CsWinRT/issues/1151) for more details.
181+
- Consuming a C# component built for `AnyCPU` from C++ is supported only from `x86` applications currently. `x64` and `Arm64` apps result in a runtime error similar to: *%1 is not a valid Win32 application.* See [GitHub Issue #1093](https://github.com/microsoft/CsWinRT/issues/1093) for more details.
182182

183183
## Related topics
184184

hub/apps/develop/platform/csharp-winrt/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: C#/WinRT is a tool set that provides WinRT projection support for C# code.
33
title: C#/WinRT
4-
ms.date: 05/19/2020
4+
ms.date: 04/13/2026
55
ms.topic: article
66
keywords: windows 10, uwp, standard, c#, winrt, cswinrt, projection
77
ms.localizationpriority: medium
@@ -13,7 +13,7 @@ C#/WinRT is a NuGet-packaged toolkit that provides Windows Runtime (WinRT) proje
1313

1414
C#/WinRT currently provides support for consuming WinRT APIs through the use of [Target Framework Monikers](../../../desktop/modernize/desktop-to-uwp-enhance.md) (TFMs) in .NET. Setting the TFM with a specific Windows SDK version adds references to the Windows SDK projection and runtime assemblies generated by C#/WinRT.
1515

16-
The [C#/WinRT NuGet package](https://www.nuget.org/packages/Microsoft.Windows.CsWinRT/) enables you to [create](#generate-and-distribute-an-interop-assembly) and [reference](#reference-an-interop-assembly) your own WinRT interop assemblies for .NET consumers. The latest C#/WinRT version also includes a [preview of authoring](create-windows-runtime-component-cswinrt.md) WinRT types in C#.
16+
The [C#/WinRT NuGet package](https://www.nuget.org/packages/Microsoft.Windows.CsWinRT/) enables you to [create](#generate-and-distribute-an-interop-assembly) and [reference](#reference-an-interop-assembly) your own WinRT interop assemblies for .NET consumers. The latest C#/WinRT version also supports [authoring](create-windows-runtime-component-cswinrt.md) WinRT types in C#.
1717

1818
For additional information, see the [C#/WinRT GitHub repo](https://aka.ms/cswinrt/repo).
1919

@@ -29,7 +29,7 @@ Finally, C#/WinRT is a general toolkit and is intended to support other scenario
2929

3030
## What's new
3131

32-
The latest C#/WinRT releases can be found on our [release notes](https://github.com/microsoft/CsWinRT/releases) page in the Github repo.
32+
The latest C#/WinRT releases can be found on our [release notes](https://github.com/microsoft/CsWinRT/releases) page in the GitHub repo.
3333

3434
## Usage
3535

@@ -47,7 +47,7 @@ Typically, C#/WinRT interop assemblies are referenced by application projects. B
4747

4848
If you distribute a third-party WinRT component without an official interop assembly, an application project may follow the procedure for [generating an interop assembly](#generate-and-distribute-an-interop-assembly) to generate its own private projection sources. We don't recommend this approach, because it can produce conflicting projections of the same type within a process. NuGet packaging, following the [Semantic Versioning](https://semver.org) scheme, is designed to prevent this. An official third-party interop assembly is preferred.
4949

50-
### Embedded support for WinRT types (Preview)
50+
### Embedded support for WinRT types
5151

5252
Starting with C#/WinRT version 1.4.1, support is included for embedding Windows SDK projection and runtime sources for both .NET and .NET Standard 2.0 into your library or app's output. This is useful in cases where usage of Windows SDK types is self-contained. Embedded support removes dependencies on WinRT.Runtime.dll and Microsoft.Windows.SDK.NET.dll which reduces the library or app output size. It also allows library developers to provide downlevel support and removes the need for multi-targeting.
5353

hub/apps/develop/platform/csharp-winrt/net-mappings-of-winrt-types.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: .NET mappings of WinRT types in C#/WinRT
33
description: The following table lists the mappings that C#/WinRT makes between Windows Runtime types and .NET types.
4-
ms.date: 04/19/2020
4+
ms.date: 04/13/2026
55
ms.topic: article
66
keywords: windows 10, uwp
77
ms.localizationpriority: medium
@@ -18,7 +18,7 @@ The C#/WinRT custom type mappings are categorized by types in the Windows SDK or
1818
- **WinRT types that map to .NET types with the same name and namespace.** These custom mappings are generally for performance or enhancement reasons, and are implemented directly in C#. Most of the types that have the same namespace name and type name in WinRT and .NET are structures (or types associated with structures, such as enumerations). In WinRT, structures have no members other than fields, and require helper types, which .NET hides. The .NET versions of these structures have properties and methods that provide the functionality of the hidden helper types (for example, **Windows.UI.Color**).
1919

2020
> [!NOTE]
21-
> For a list of mappings between WinRT and .NET types in the context of UWP apps, see [.NET mappings of WinRT types in UWP](/windows/apps/develop/platform/csharp-winrt/net-mappings-of-winrt-types).
21+
> For a list of mappings between WinRT and .NET types in the context of UWP apps, see [.NET mappings of Windows Runtime types](/windows/uwp/winrt-components/net-framework-mappings-of-windows-runtime-types).
2222
2323
## Mappings for WinRT types in the Windows SDK
2424

@@ -99,4 +99,4 @@ The C#/WinRT custom type mappings are categorized by types in the Windows SDK or
9999
| KeyTime | Microsoft.UI.Xaml.Media.Animation |
100100
| RepeatBehavior | Microsoft.UI.Xaml.Media.Animation |
101101
| RepeatBehaviorType | Microsoft.UI.Xaml.Media.Animation |
102-
| Matrix3D |(Microsoft.UI.Xaml.Media.Media3D |
102+
| Matrix3D | Microsoft.UI.Xaml.Media.Media3D |

hub/apps/develop/platform/csharp-winrt/net-projection-from-cppwinrt-component.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Generate a C# projection from a C++/WinRT component, distribute as a NuGet for .NET apps
33
description: In this topic, we walk through using [C#/WinRT](/windows/uwp/csharp-winrt/) to generate a C# .NET projection (or interop) assembly from a C++/WinRT Windows Runtime component, and distribute it as a NuGet package for .NET applications.
4-
ms.date: 03/23/2023
4+
ms.date: 04/13/2026
55
ms.topic: how-to
66
keywords: windows 10, c#, winrt, cswinrt, projection
77
ms.localizationpriority: medium
@@ -21,10 +21,10 @@ In .NET 6 and later, consumption of Windows metadata (WinMD) files is no longer
2121

2222
This walkthrough and the corresponding sample require the following tools and components:
2323

24-
* [Visual Studio 2026](https://visualstudio.microsoft.com/downloads/) with the Universal Windows Platform development workload installed. In **Installation Details** > **Universal Windows Platform development**, check the **C++ (v14x) Universal Windows Platform tools** option.
25-
* [.NET 6.0 SDK](https://dotnet.microsoft.com/download/) or later.
24+
* [Visual Studio 2022 or later](https://visualstudio.microsoft.com/downloads/) with the Universal Windows Platform development workload installed. In **Installation Details** > **Universal Windows Platform development**, check the **C++ (v14x) Universal Windows Platform tools** option.
25+
* [.NET 8.0 SDK (LTS)](https://dotnet.microsoft.com/download) or later.
2626

27-
We'll be using Visual Studio 2026 and .NET 6 in this walkthrough.
27+
We'll be using Visual Studio 2022 or later and .NET 8 in this walkthrough.
2828

2929
> [!IMPORTANT]
3030
> Also, you'll need to download or clone the sample code for this topic from the [C#/WinRT projection sample](https://github.com/microsoft/CsWinRT/tree/master/src/Samples/NetProjectionSample) on GitHub. Visit [CsWinRT](https://github.com/microsoft/CsWinRT), and click the green **Code** button to get the `git clone` url. Be sure to read the [README.md](https://github.com/microsoft/CsWinRT/blob/master/src/Samples/NetProjectionSample/README.md) file for the sample.
@@ -33,7 +33,7 @@ We'll be using Visual Studio 2026 and .NET 6 in this walkthrough.
3333

3434
To follow this walkthrough, you must first have a C++/WinRT Windows Runtime component (WRC) from which to generate the C# projection assembly.
3535

36-
This walkthrough uses the **SimpleMathComponent** WRC from the [C#/WinRT projection sample](https://github.com/microsoft/CsWinRT/tree/master/src/Samples/NetProjectionSample) on GitHub, which you already downloaded or cloned. **SimpleMathComponent** was created from the **Windows Runtime Component (C++/WinRT)** Visual Studio project template (which comes with Visual Studio 2026).
36+
This walkthrough uses the **SimpleMathComponent** WRC from the [C#/WinRT projection sample](https://github.com/microsoft/CsWinRT/tree/master/src/Samples/NetProjectionSample) on GitHub, which you already downloaded or cloned. **SimpleMathComponent** was created from the **Windows Runtime Component (C++/WinRT)** Visual Studio project template.
3737

3838
To open the **SimpleMathComponent** project in Visual Studio, open the `\CsWinRT\src\Samples\NetProjectionSample\CppWinRTComponentProjectionSample.sln` file, which you'll find in your download or clone of the repo.
3939

@@ -73,7 +73,7 @@ First, with the **CppWinRTComponentProjectionSample** solution still open in Vis
7373
1. In **Solution Explorer**, right-click your solution node and click **Add** > **New Project**.
7474
2. In the **Add a new project** dialog box, type **Class Library** in the search box. Choose **C#** from the language list, and then choose **Windows** from the platform list. Choose the C# project template that's called simply **Class Library** (with no prefixes nor suffixes), and click **Next**.
7575
3. Name the new project *SimpleMathProjection*. The location should already be set to the same `\CsWinRT\src\Samples\NetProjectionSample` folder that the **SimpleMathComponent** folder is in; but confirm that. Then click **Next**.
76-
4. On the **Additional information** page, select **.NET 6.0 (Long-term support)**, and then choose **Create**.
76+
4. On the **Additional information** page, select **.NET 8.0 (Long-term support)**, and then choose **Create**.
7777

7878
2. Delete the stub **Class1.cs** file from the project.
7979

@@ -235,7 +235,7 @@ To consume **SimpleMathComponent** from a .NET project, you can simply add to a
235235
1. In a new instance of Visual Studio, select **File** > **New** > **Project**.
236236
2. In the **Create a new project** dialog box, search for the **Console App** project template. Choose the C# project template that's called simply **Console App** (with no prefixes nor suffixes), and click **Next**. If you're using Visual Studio 2019, then the project template is **Console Application**.
237237
3. Name the new project **SampleConsoleApp**, set its location to the same `\CsWinRT\src\Samples\NetProjectionSample` folder that the **SimpleMathComponent** and **SimpleMathProjection** folders are in, and click **Next**.
238-
4. On the **Additional information** page, select **.NET 6.0 (Long-term support)**, and then choose **Create**.
238+
4. On the **Additional information** page, select **.NET 8.0 (Long-term support)**, and then choose **Create**.
239239

240240
2. In **Solution Explorer**, double-click the **SampleConsoleApp** node to open the **SampleConsoleApp.csproj** project file, and edit the `TargetFramework` and `Platform` properties so that they look as shown in the following listing. Add the `Platform` element if it's not there.
241241

0 commit comments

Comments
 (0)