Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest CsWin32 generates code that fail to compile (and unnecessary methods) #1332

Closed
Sergio0694 opened this issue Jan 20, 2025 · 4 comments · Fixed by #1337
Closed

Latest CsWin32 generates code that fail to compile (and unnecessary methods) #1332

Sergio0694 opened this issue Jan 20, 2025 · 4 comments · Fixed by #1337
Assignees
Labels
bug Something isn't working

Comments

@Sergio0694
Copy link
Member

Actual behavior

I've updated to the latest version (0.3.162) and my project is now failing to compile. Upon inspecting the generated code, it seems CsWin32 is generating a bunch of invalid code in the QueryInterface methods it's emitting. It's also not clear why these methods are generated in the first place, given I've disabled the friendly overloads. I expect (and want) literally only the vtable methods to be generated, nothing else.

Image

You can see this generated call has invalid arguments. Also, this whole method shouldn't be generated at all, really.

Expected behavior

The code should be valid and compile, and no additional "helper methods" should be generated.

Repro steps

  1. NativeMethods.txt content:
ID3D11ShaderReflection
IUnknown
  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
@Sergio0694 Sergio0694 added the bug Something isn't working label Jan 20, 2025
@Sergio0694
Copy link
Member Author

The codegen with 0.3.106 is correct. It's 0.3.162 (the latest) that's all wrong:

  • It produces invalid code
  • It adds a whole lot of random helper methods and unnecessary stuff I never asked for

Eg. why is it even trying to emit ComWrappers marshalling code if I specifically asked for no marshalling? I only want blittable stuff.

@Sergio0694
Copy link
Member Author

Sergio0694 commented Jan 20, 2025

@AArnott the build break was caused by #1290. That new method is:

  • Wrong for when blittable mode is used, as the parameter types don't match
  • It shouldn't be generated in the first place when friendly overloads are disabled

Same for other random helper methods that should be removed, but at least those are not breaking 😅

@AArnott
Copy link
Member

AArnott commented Jan 22, 2025

@Sergio0694 Thank you for your report.

I couldn't readily identify any methods besides the faulty QueryInterface method itself that should be omitted when friendly overloads are turned off. Please open a separate bug listing any other methods you feel are being generated inappropriately.

@Sergio0694
Copy link
Member Author

I opened #1338 as a follow up 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants