A sample demonstrates both in-process and out-of-process WinRT server with C# + CsWinRT.
The Windows Runtime (WinRT) supports the concept of In Process Servers, which allows for using objects that are in a different dlls with super-fast performance and easy-to-use ABI.
The Windows Runtime (WinRT) supports the concept of Out Of Process (OOP) Servers, which allows for using objects that are in a different process (or even a different machine) as though they were in the local process.
It uses WinRT for communication so that any language that can use WinRT is able to be a WinRT server or serve as a client of a WinRT server.
With built-in support for async primitives such as IAsyncAction, IAsyncOperation<T> and etc., it is easy to work with async code.
Most RPC/ICP systems are just sending messages between the two processes. At most they can serialize and deserialize an object.
WinRT allows for more complicated objects, where the returned types can have methods, events, and properties. If you could do it with a local object, you can do it with a remote object.
Use Visual Studio 2026 with the .NET desktop development and Windows application development workloads, the .NET 10 SDK, and the Windows 11 SDK (10.0.26100.0).
WinRTServerTest owns the MSIX manifest and package assets and includes the WinRT server in its package. Set WinRTServerTest as the startup project, select x86, x64, or ARM64, and run the WinRTServerTest launch profile to deploy and launch the packaged client.
To create an unsigned MSIX package from the command line:
dotnet build WinRTServer.sln -c Release -p:Platform=x64 -p:GenerateAppxPackageOnBuild=truePackages are written under WinRTServerTest\AppPackages. Sign the package with a trusted certificate before installing it outside Visual Studio.
Install the Desktop development with C++ workload in Visual Studio to provide the native compiler and linker. Add the ARM64 C++ build tools when targeting ARM64.
To compile both the client and server with NativeAOT and create an unsigned MSIX package:
dotnet publish WinRTServerTest\WinRTServerTest.csproj -c Release -p:Platform=x64 -p:PublishAot=true -p:PublishAppxPackage=trueUse x86 or ARM64 for the corresponding platform. NativeAOT packages include the native executables and do not require an installed .NET runtime.
The server project needs to provide the implementation of types, and it uses CsWinRT to automatically generate interop code and winmd file, where the winmd file is served as a contract to be used between server and clients.
Structs, classes and delegates are supported, to add a type in the WinRT server:
- If you are adding a class, it must be sealed, and make sure you also add the type as an
ActivatableClassinPackage.appxmanifestunderOutOfProcessServer(orInProcessServerif you are using the in-proc server), and if you are using the out-of-proc WinRT server, you also need to register an activation factory for it in theRoRegisterActivationFactoriescall. - Methods, properties and events for both static and non-static are supported, but the type must have a projection (primitive types, types that have a .NET/WinRT mapping, WinRT types and types defined in the server project) before it can be used in the signature.
The client project only needs to consume the winmd file generated by the server project, all the server activation, type instantiation and marshaling things will be automatically done by CsWinRT.
To switch the out-of-process WinRT server to in-process WinRT server:
- Change the OutputType of the server project to
Library. - Open
WinRTServerTest\Package.appxmanifest, uncomment the in-process server manifest, and comment the out-of-process server manifest.
For NativeAOT publishing, set the in-process server's manifest path to WinRTServer\WinRTServer.dll. For managed publishing, use WinRTServer\WinRT.Host.dll.