-
Notifications
You must be signed in to change notification settings - Fork 114
Closed
Description
Actual behavior
The new source-generator based COM (useComSourceGenerators: true) generates a class with a (traditional) "ComImport" attribute for a cocreateable class like ShellLink. This class is incompatible with the interfaces generated with the same configuration.
Expected behavior
The class and the interface are compatible with each other, both using the same technique.
Repro steps
NativeMethods.txtcontent:
IPersistFile
IShellLinkW
ShellLinkNativeMethods.jsoncontent (if present):
{
"$schema": "https://aka.ms/CsWin32.schema.json",
"comInterop": {
"useComSourceGenerators": true
}
}- Any of your own code that should be shared?
var shellLink = new ShellLink();
var shellLinkW = (IShellLinkW)shellLink;
shellLinkW.SetPath("explorer.exe");
// some more calls
var persistFile = (IPersistFile)shellLink;
persistFile.Save(shortcut, true);Both casts in that code snippet create this warning: SYSLIB1099 Casting between a ComImport type and a source-generated COM type is not supported
And the warning looks to be accurate the generated ShellLink:
[Guid("00021401-0000-0000-C000-000000000046"),ComImport()]
[global::System.CodeDom.Compiler.GeneratedCode("Microsoft.Windows.CsWin32", "0.3.217+533aa1bddf.RR")]
internal partial class ShellLink
{
}the generated IShellLinkW:
[Guid("000214F9-0000-0000-C000-000000000046"),InterfaceType(ComInterfaceType.InterfaceIsIUnknown),GeneratedComInterface()]
[SupportedOSPlatform("windows5.1.2600")]
[global::System.CodeDom.Compiler.GeneratedCode("Microsoft.Windows.CsWin32", "0.3.217+533aa1bddf.RR")]
internal unsafe partial interface IShellLinkW
{I believe that this line is responsible:
| .AddAttributeLists(AttributeList().AddAttributes(GUID(guid), ComImportAttributeSyntax)); |
But I do not know how to fix it.
For further context, I believe this issue created these classes: #453
Context
- CsWin32 version: 0.3.217
- Win32Metadata version (if explicitly set by project): not set
- Target Framework: net9.0-windows10.0.26100.0
LangVersion(if explicitly set by project): [e.g.9] not set
Metadata
Metadata
Assignees
Labels
No labels