Skip to content

Support dual comhost.dll (x86, x64) generation for .NET Core assemblies using "Any CPU" #32493

Open

Description

@carlos-quintero

Currently:

  • If the .NET Core assembly uses architecture "x86" the generated .comhost.dll is for 32-bit.
  • If the .NET Core assembly uses architecture "x64" the generated .comhost.dll is for 64-bit
    So far so good.
  • If the .NET Core assembly uses architecture "Any CPU" the generated .comhost.dll is for 64-bit. This case is problematic. If you try to register it as 32-bit COM component, the client gets 0x800700C1 ("not a valid Win32 application").

If an assembly targets the architecture Any CPU then two .comhost.dll files
should be generated, because the autor may want to create both x64 and x86 COM servers from the same .NET "Any CPU" assembly (ex: consider a .NET-based add-in for Office 64-bit and Office 32-bit). That was possible with .NET Framework with a single build, but it is not possible with .NET Core: two builds are required, one for architecture x86 and another for architecture x64, and you need to move the output files before the second build.

I suggest the following approach:

  • If the .NET Core assembly uses architecture x86 a .comhost32.dll file is generated for 32-bit
  • If the .NET Core assembly uses architecture x64 a .comhost64.dll file is generated for 64-bit
  • If the .NET Core assembly uses architecture Any CPU, both .comhost32.dll and .comhost64.dll files are generated.

Activity

  1. added
    untriaged
    on Feb 18, 2020
  2. vitek-karas commented on Feb 18, 2020

    @vitek-karas
    Member
  3. added
    enhancement
    and removed
    untriaged
    on Apr 3, 2020
  4. added this to the Future milestone on Apr 3, 2020
  5. DHowett commented on Dec 1, 2020

    @DHowett

    This is also important for ARM64 for projects that want 3-architecture builds, like WinAppDriver.

  6. jozefizso commented on Dec 17, 2023

    @jozefizso

    I created new issue at dotnet/sdk#37570 as the build scripts for COM hosting are in the SDK repository.

  7. claudiudc commented on Mar 9, 2026

    @claudiudc

    With .NET Framework, a single AnyCPU assembly registered via regasm worked seamlessly for both 32-bit and 64-bit COM clients. Migrating to modern .NET (.NET 5+) breaks this workflow entirely.
    We're now forced to produce two separate builds (x86 and x64) just because the comhost shim is architecture-specific, even though the managed assembly itself is perfectly capable of running in both bitnesses. This has a cascading impact: other assemblies that previously held a single reference to our AnyCPU COM library now need to deal with two architecture-specific outputs, complicating the build pipeline, deployment, and registration process significantly.
    This feels like a regression from .NET Framework's behavior, where regasm handled dual registration transparently. Forcing an architecture on a library that genuinely doesn't need one is a real pain point for anyone maintaining COM interop in modern .NET.
    Our DLL is a library consumed by external clients. Until now we shipped a single AnyCPU binary and everything just worked. Now we're supposed to tell our clients that instead of one DLL, they need to pick from two or three depending on their target architecture? That's a serious usability regression and a hard sell for anyone distributing COM libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Hostenhancement

    Type

    No type

    Projects

    • Status
      No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions