microsoft / microsoft/CsWin32

Latest release generates a lot of unwanted code when marshalling/overloads are disabled

Open
#1,338 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
2.5k
Forks
124
Avg merge
1d 3h
Merged PRs (30d)
9

Description

Actual behavior

Follow up from https://github.com/microsoft/CsWin32/issues/1332#issuecomment-2608446584.
I'd expect all COM types to only have the direct function pointer vtable slot methods, and the blittable vtable type.

Expected behavior

Some types also get a ton of unwanted stuff, like:

  • [UnmanagedCallersOnly] methods doing CCW marshalling (??)
  • PopulateVTable method
  • A managed [ComImport] interface type (this isn't even trim/AOT compatible, nor blittable, why is it here)

None of this stuff should be emitted when specifying blittable mode with no friendly overloads.
CsWin32 should literally only emit the blittable type, the vtable definition, and the IID field.

Repro steps

  1. NativeMethods.txt content:
ID3D11ShaderReflection
  1. NativeMethods.json content (if present):
{
  "$schema": "https://aka.ms/CsWin32.schema.json",
  "allowMarshaling": false,
  "useSafeHandles": false,
  "comInterop": {
    "preserveSigMethods": [
      "*"
    ]
  },
  "friendlyOverloads": {
    "enabled": false
  }
}
Context
  • CsWin32 version: 0.3.162
  • Win32Metadata version (if explicitly set by project): n/a
  • Target Framework: netstandard2.0 and net9.0 (I can repro on both)
  • LangVersion (if explicitly set by project): n/a

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the generated output using NativeMethods.txt with ID3D11ShaderReflection and the shown NativeMethods.json settings, targeting both netstandard2.0 and net9.0. Compare the output with the expected blittable type, vtable definition, and IID field; done means the unwanted marshalling, PopulateVTable, and managed ComImport artifacts are absent.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.