Out-of-process COM Server Demo

This sample demonstrates a way to create an out-of-process COM server in .NET Core 3.1 or later. The .NET SDK and runtime support exposing an in-process COM server. While there is no built-in support for exposing an out-of-process COM server, it is possible to achieve.

The projects in this sample show a way to provide an out-of-process COM server with the system-supplied DLL Surrogate or using an executable built by the developer. Since .NET Core does not support generating a type library from a .NET Core assembly, this sample uses MIDL to compile an IDL file into a type library, which the COM server then registers.

Prerequisites

This sample will only build and run on the Windows platform.

Build and Run

  1. Open a Developer Command Prompt for Visual Studio.
  2. Navigate to the root directory and build the solution:
    • msbuild OutOfProcCOM.sln -restore.
  3. Show the instructions for COM server registration:
    • DLL surrogate: dotnet msbuild -target:ServerUsage DllServer
    • Executable server: dotnet msbuild -target:ServerUsage ExeServer
  4. Follow the instructions for registering the server.
  5. Run the client:
    • Native: run the NativeClient.exe binary
      • Example: x64\Debug\NativeClient.exe
    • Managed: run the ManagedClient.exe binary
      • Example: ManagedClient\bin\Debug\netcoreapp3.1\ManagedClient.exe

The client program should output an estimated value of π:

π = 3.140616091322624

Embedded Type Library

The .NET 6.0 SDK (Preview 5 or later) supports embedding type libraries into the COM DLL. To use this functionality for the DLL surrogate (DllServer) in this sample, build with -p:EmbedTypeLibrary=true.

Note: Remember to unregister the COM server when the demo is complete.