You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
COM interfaces are not declared with the partial keyword #324
Using partial on a COM interface would lead to undefined member ordering inside the interface, which would be disastrous. I get it in your case you just want to add attributes, but that's a very narrow case for using partial and IMO the risk that folks might use it for other purposes and end up corrupting the vtable would be huge.
Let's keep your other issue to track adding the attributes you want on the interface within the generated code.
I think the entire risk could be mitigated with a new source generator error if any user-defined parts contain (non-type) members. But maybe the use case of adding attributes is too niche to be worth it.
Honestly, a C# compiler-level warning when methods are added to two parts of a partial interface that includes interop attributes would probably be appropriate, IMO. If the compiler emits one (maybe it already does), then I wouldn't object to this suggestion. Can you test whether it already does, and if it doesn't, maybe file a bug at https://github.com/dotnet/csharplang?
Since this affects existing C#, I expect they will only want to add this in a warning wave. Things like this tend to be designed at dotnet/roslyn rather than dotnet/csharplang, which is good news because only a few things that require a spec change ever ship and it's usually years out.
Andrii Kurdiumov (@kant2002) does your COM Wrapper work in winforms need a partial interface at all? I believe winforms is going to use cswin32 without marshalling, so the interfaces will not be generated? Just making sure this doesn't end up blocking your work.
I’m was not able to properly check current state of CsWin32 , but in general I never use partials for COM interface declaration so I’m fine with that. What’s important is that DllImport gives IntPtr for interface parameters. All I need is control of how COM proxy is created.
With DllImport + IntPtr parameter I do that manually. With LibraryImport + IComInterface I think it’s possible to provide marshalers so I can control that part.
Need more time to properly get context to answer you more targeted
DllImport and not LibraryImport (given how DllImport used, I think switch to LibraryImport when allowMarshaling = false is quite possible. Without that it indirectly affects WinForms or any app who want trim.
comInterop.useIntPtrForComOutPointers is interesting. With comInterop.useIntPtrForComOutPointers = true I see how current codegen can be used almost identically for current approach, but then we need additional comInterop.useIntPtrForComInPointers, or is there assumption that IntPtr returned by ComWrappers.GetOrCreateComInterfaceForObject should be blindly converted to, for example, winmdroot.System.Com.IUnknown*?
struct + Vtbl as interfaces. I do remember that I was suggested by Jan Kotas or Aaron that instead of creatin VTBL structures I directly operate on pointers. Otherwise it produce a lot of metadata. Maybe recent changes in P7 by @MichalStrechovsky trim that out, but otherwise it looks like additional bloat.
So basically for one scenario I need structs, for another interface.
Maybe instead of structs if allowMarshaling = true, can be generated just Vtbl part that way I can write code for RCW like this.
I re-read this whole thread. I'm not clear on whether the partial modifier added to the interface or the struct code for a COM interface is useful or not, as it seems Andrii Kurdiumov (@kant2002) was making the case both for and against. As that seems to be the last request uniquely described by this issue, can anyone clarify on requirements here? Otherwise, I'll close the issue as Won't Fix in a few days. Of course feedback after that on this issue would be welcome and we could reactivate if needed.
I never need the partial on codegen. My ask onlly Until .NET 8 have COM source generators provide ability to use IntPtr instead of interfaces. That allow supply ComWrappers manually.
Interop team plans to add source generators which would works with LibraryImportGenerator . I do not sure if happens for sure, but plans are really here.
Activity
AArnott commentedon Jul 11, 2021
Using
partialon a COM interface would lead to undefined member ordering inside the interface, which would be disastrous. I get it in your case you just want to add attributes, but that's a very narrow case for using partial and IMO the risk that folks might use it for other purposes and end up corrupting the vtable would be huge.Let's keep your other issue to track adding the attributes you want on the interface within the generated code.
jnm2 commentedon Jul 11, 2021
I think the entire risk could be mitigated with a new source generator error if any user-defined parts contain (non-type) members. But maybe the use case of adding attributes is too niche to be worth it.
AArnott commentedon Jul 17, 2021
Honestly, a C# compiler-level warning when methods are added to two parts of a
partialinterface that includes interop attributes would probably be appropriate, IMO. If the compiler emits one (maybe it already does), then I wouldn't object to this suggestion. Can you test whether it already does, and if it doesn't, maybe file a bug at https://github.com/dotnet/csharplang?jnm2 commentedon Jul 17, 2021
There is no warning (sharplab).
Since this affects existing C#, I expect they will only want to add this in a warning wave. Things like this tend to be designed at dotnet/roslyn rather than dotnet/csharplang, which is good news because only a few things that require a spec change ever ship and it's usually years out.
jnm2 commentedon Jul 21, 2021
I checked on the repo contribution Discord channel and Fred confirmed that this would probably be a feature request for the Roslyn repo. https://github.com/dotnet/roslyn/issues/55006
elachlan commentedon Aug 19, 2022
Andrii Kurdiumov (@kant2002) does your COM Wrapper work in winforms need a partial interface at all? I believe winforms is going to use cswin32 without marshalling, so the interfaces will not be generated? Just making sure this doesn't end up blocking your work.
kant2002 commentedon Aug 22, 2022
I’m was not able to properly check current state of CsWin32 , but in general I never use partials for COM interface declaration so I’m fine with that. What’s important is that DllImport gives IntPtr for interface parameters. All I need is control of how COM proxy is created.
With DllImport + IntPtr parameter I do that manually. With LibraryImport + IComInterface I think it’s possible to provide marshalers so I can control that part.
Need more time to properly get context to answer you more targeted
elachlan commentedon Aug 23, 2022
Thanks, we should know more when they start to look at it.
kant2002 commentedon Aug 23, 2022
Quick glance
From what I see on
feature/wincs32allowMarshaling = falseis quite possible. Without that it indirectly affects WinForms or any app who want trim.comInterop.useIntPtrForComOutPointersis interesting. WithcomInterop.useIntPtrForComOutPointers = trueI see how current codegen can be used almost identically for current approach, but then we need additionalcomInterop.useIntPtrForComInPointers, or is there assumption thatIntPtrreturned byComWrappers.GetOrCreateComInterfaceForObjectshould be blindly converted to, for example,winmdroot.System.Com.IUnknown*?RCW
Currently RCW build like this.
With current autogenerated structs
or
Still require manual passing all parameters. AddRef/Release/QI function is pointless because they never would be used.
CCW
Currently CCW build like this
if
allowMarshaling = truethen this can be used like this. Also here the reason whypartialis not needed.not much of a difference.
Additional comments
So basically for one scenario I need structs, for another interface.
Maybe instead of structs if
allowMarshaling = true, can be generated just Vtbl part that way I can write code for RCW like this.I may screw with * here, but that's for illustrative purposes for now.
AArnott commentedon Aug 25, 2022
Andrii Kurdiumov (@kant2002), thank you for your write-up.
IntPtrfor input parameters in lieu of COM interfaces should be possible. If that's important to you, can you file a new issue to track that? Please comment on Offer option to generate IntPtr input parameters instead of COM interfaces #669 to carry on this discussion.I think I'll need more time to study the rest of your comments.
AArnott commentedon Oct 4, 2022
I re-read this whole thread. I'm not clear on whether the
partialmodifier added to the interface or the struct code for a COM interface is useful or not, as it seems Andrii Kurdiumov (@kant2002) was making the case both for and against. As that seems to be the last request uniquely described by this issue, can anyone clarify on requirements here? Otherwise, I'll close the issue as Won't Fix in a few days. Of course feedback after that on this issue would be welcome and we could reactivate if needed.kant2002 commentedon Oct 4, 2022
I never need the partial on codegen. My ask onlly Until .NET 8 have COM source generators provide ability to use IntPtr instead of interfaces. That allow supply ComWrappers manually.
elachlan commentedon Oct 4, 2022
Andrii Kurdiumov (@kant2002) what changes in .NET8? Do ComWrappers get easier?
kant2002 commentedon Oct 4, 2022
Interop team plans to add source generators which would works with LibraryImportGenerator . I do not sure if happens for sure, but plans are really here.
elachlan commentedon Oct 5, 2022
Could you please link the associated issue?
kant2002 commentedon Oct 5, 2022
Do not know the issue, but plans are present https://twitter.com/mstrehovsky/status/1573203145236582403?s=46&t=mSvL8EQaVWZs8crDDX4qtg Interop team usually rock solid when they implement something.
AArnott commentedon Oct 5, 2022
I'll close this based on this feedback. We can reactivate if anyone decides this is important.
Merge pull request #324 from AArnott/publishArtifactsOnCancel