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
Review COM interface declarations for conflicting ComImport/ComVisible attributes #1878
📚 documentationOpen issue here - https://github.com/dotnet/dotnet-api-docs/issuesarea-COMenhancementProduct code improvement that does NOT require public API changes/additions
During review of PR #1868 I noticed IOleInPlaceActiveObject was declared with both [ComImport] and [ComVisible(true)]. This is wrong, ComVisible(true) is for interfaces owned by the assembly, ComImport is for external interfaces.
In desktop framework this probably has little consequence since the assemblies come preinstalled, but now that its possible to deploy WinForms with an application it may more likely be processed by tools like regasm or TLB generators, which attempt to register COM interop owned by the assembly.
When ComVisible(true) is present this will cause registry corruption by overwriting the true owners registry entries (usually owned by Windows OS) and replacing them by .NET based values. For interfaces I believe this mostly replaces the ProxyStubClsid32 pointing to another implementation than the original entries used to have.
There should be a review for conflicting ComImport/ComVisible(true) entries, or better, just review ComVisible(true) in general and make sure it is only placed on classes/interfaces owned by WinForms.
a quick search for ComVisible(true) yields 238 matches in 182 files, not all of them technically wrong (for example it is placed on control classes which are certainly implemented and owned by WinForms)
However considering that the codebase comes from Desktop Framework I wonder if there should be any ComVisible(true) attributes left in place at all, even for classes and interfaces actually owned by WinForms. The ComVisible WinForms GUIDs registered globally always used to be Desktop Framework, I wonder how many of the ComVisible classes/interfaces owned by WinForms actually need to be ComVisible in .NET Core for supported interop scenarios. Maybe most (or all) of them can be removed?
@hughbe@RussKie I don't think this is fixed, I still find plenty of wrong [ComVisible(true)] attributes. Needs to be reopened or creating a follow-up issue for proper cleanup. I also noticed new [ComVisible(true)] attributes were being added in accessibility PRs, flagged them, but I think this needs a bit care in reviews, at least for the current time being.
However considering that the codebase comes from Desktop Framework I wonder if there should be any ComVisible(true) attributes left in place at all, even for classes and interfaces actually owned by WinForms. The ComVisible WinForms GUIDs registered globally always used to be Desktop Framework, I wonder how many of the ComVisible classes/interfaces owned by WinForms actually need to be ComVisible in .NET Core for supported interop scenarios. Maybe most (or all) of them can be removed?
If classes had [ComVisible] on Framework I'd prefer to keep the attribute unless we can clearly document that it has some negative impact.
The auditing is a must for 5.0, I don't want to see us inadvertently exposing this attribute in unintended places.
If classes had [ComVisible] on Framework I'd prefer to keep the attribute
I scrolled through all remaining ComVisible which can be found by "search references" in VS and they all (except one) are specified without GUID, meaning they get a generated GUID. I don't remember if I checked previously, but the generated GUID seems to be different from Desktop Framework, so having these ComVisible left over is probably acceptable since they cause no conflicts, but I still think most (if not all) ComVisible attributes are redundant.
They certainly don't contribute to compatibility with Desktop Framework since there is no shared TLB (Desktop Framework has a TLB and primary interop assembly for WinForms, you'd have to be compatible with those if you wanted that level of compatibility). So users of WinForms via COM have to rewrite all their interop code anyways and this time they don't have a TLB to import either. So while I don't think its harmful it also doesn't seem to provide any value, and it will make AOT efforts like corert potentially more complicated if they have to predeclare CCWs for objects never intended to be accessible from COM.
That said its probably still good to remove ComVisible later if you don't feel confident doing it for 5.0 - unless people start taking a dependency on them, but I don't know why anyone would be doing that.
unless we can clearly document that it has some negative impact.
The only negative impacts I currently can think of involve sharing a CLSID/IID with Desktop Framework, those cases should definitely be fixed.
There is one ComVisible + GUID remaining on IWin32Window which is shared with Desktop Framework, the registry has a TLB entry pointing to the Desktop Framework version. .NET Core should probably have its own GUID or switch to ComImport, .NET Core is not the owner of that IID.
Given that most AccessibleObject implementations are not createable from COM
I'd prefer removing the [ComVisible] attributes on these accessibility objects. I'd rather try and shed this and consider pulling it back if someone genuinely has a need for it (highly unlikely). If we can't come up with a semi-plausible use case for things with [ComVisible] I'd rather see us remove the attribute. It is likely to save us more time in the long run by not having to keep analyzing it- or surface use cases we're totally not aware of (again, highly unlikely).
We had a private discussion with Jeremy, and concluded that we should remove all [ComVisible] decorations.
If/when we hear from our customers that some use-case requires the decoration - we'll add it back, and have the use-case documented.
@weltkante please let me know if you want to do it, or I'll set it up for grabs.
Thank you
//创建地纬嵌入式接口对象,调用com组件
int vi Oleobject sei
sei =create Oleobject //创建ole对象seiproxy
vi= sei.connecttonewobject('sei3') //连接com组件 if vi <> 0 then
messagebox('错误','创建地纬嵌入式接口sei对象失败!')
return end if
我们使用.NetFramework4.6.1调用方式:
Type type = Type.GetTypeFromProgID("sei3", true);
dynamic COM = Activator.CreateInstance(type);
使用同样的方式,在.NetCore3.1.4上运行返回异常:
Creating an instance of the COM component with CLSID {D5D8D5B2-CCD5-4EEC-BE61-0CA13A1940C7} from the IClassFactory failed due to the following error: ffffdf8f 0xFFFFDF8F.
Example 1: com interoperability of medical insurance system docking:
The insurance system interface specification provides Pb call examples:
//Create the ground latitude embedded interface object and call COM component
int vi Oleobject sei
SEI = create oleobject / / create OLE object seiproxy
vi= sei.connecttonewobject ('sei3 ') / / connect COM component if VI < > 0 then
MessageBox ('error ',' failed to create SEI object of ground latitude embedded interface! ')
return end if
We use. Netframework 4.6.1 to call:
Type type = Type.GetTypeFromProgID ("sei3", true);
dynamic COM = Activator.CreateInstance (type);
Using the same method, run return exception on. NETCORE 3.1.4:
Creating an instance of the COM component with CLSID {D5D8D5B2-CCD5-4EEC-BE61-0CA13A1940C7} from the IClassFactory failed due to the following error: ffffdf8f 0xFFFFDF8F.
📚 documentationOpen issue here - https://github.com/dotnet/dotnet-api-docs/issuesarea-COMenhancementProduct code improvement that does NOT require public API changes/additions
Activity
weltkante commentedon Sep 12, 2019
a quick search for
ComVisible(true)yields 238 matches in 182 files, not all of them technically wrong (for example it is placed on control classes which are certainly implemented and owned by WinForms)However considering that the codebase comes from Desktop Framework I wonder if there should be any ComVisible(true) attributes left in place at all, even for classes and interfaces actually owned by WinForms. The ComVisible WinForms GUIDs registered globally always used to be Desktop Framework, I wonder how many of the ComVisible classes/interfaces owned by WinForms actually need to be ComVisible in .NET Core for supported interop scenarios. Maybe most (or all) of them can be removed?
weltkante commentedon May 6, 2020
@hughbe @RussKie I don't think this is fixed, I still find plenty of wrong [ComVisible(true)] attributes. Needs to be reopened or creating a follow-up issue for proper cleanup. I also noticed new [ComVisible(true)] attributes were being added in accessibility PRs, flagged them, but I think this needs a bit care in reviews, at least for the current time being.
JeremyKuhne commentedon May 11, 2020
If classes had
[ComVisible]on Framework I'd prefer to keep the attribute unless we can clearly document that it has some negative impact.The auditing is a must for 5.0, I don't want to see us inadvertently exposing this attribute in unintended places.
weltkante commentedon May 11, 2020
I scrolled through all remaining ComVisible which can be found by "search references" in VS and they all (except one) are specified without GUID, meaning they get a generated GUID. I don't remember if I checked previously, but the generated GUID seems to be different from Desktop Framework, so having these ComVisible left over is probably acceptable since they cause no conflicts, but I still think most (if not all) ComVisible attributes are redundant.
They certainly don't contribute to compatibility with Desktop Framework since there is no shared TLB (Desktop Framework has a TLB and primary interop assembly for WinForms, you'd have to be compatible with those if you wanted that level of compatibility). So users of WinForms via COM have to rewrite all their interop code anyways and this time they don't have a TLB to import either. So while I don't think its harmful it also doesn't seem to provide any value, and it will make AOT efforts like corert potentially more complicated if they have to predeclare CCWs for objects never intended to be accessible from COM.
That said its probably still good to remove ComVisible later if you don't feel confident doing it for 5.0 - unless people start taking a dependency on them, but I don't know why anyone would be doing that.
The only negative impacts I currently can think of involve sharing a CLSID/IID with Desktop Framework, those cases should definitely be fixed.
There is one ComVisible + GUID remaining on IWin32Window which is shared with Desktop Framework, the registry has a TLB entry pointing to the Desktop Framework version. .NET Core should probably have its own GUID or switch to ComImport, .NET Core is not the owner of that IID.
13 remaining items
RussKie commentedon Jun 2, 2020
RussKie commentedon Jun 2, 2020
Ah found it under dotnet/runtime#37039
JeremyKuhne commentedon Jun 2, 2020
I'd prefer removing the
[ComVisible]attributes on these accessibility objects. I'd rather try and shed this and consider pulling it back if someone genuinely has a need for it (highly unlikely). If we can't come up with a semi-plausible use case for things with[ComVisible]I'd rather see us remove the attribute. It is likely to save us more time in the long run by not having to keep analyzing it- or surface use cases we're totally not aware of (again, highly unlikely).RussKie commentedon Jun 3, 2020
We had a private discussion with Jeremy, and concluded that we should remove all
[ComVisible]decorations.If/when we hear from our customers that some use-case requires the decoration - we'll add it back, and have the use-case documented.
@weltkante please let me know if you want to do it, or I'll set it up for grabs.
Thank you
199621616 commentedon Jun 3, 2020
@JeremyKuhne
示例一:医疗保险系统对接的COM互操作:
保险系统接口规范提供PB调用示例:
//创建地纬嵌入式接口对象,调用com组件
int vi Oleobject sei
sei =create Oleobject //创建ole对象seiproxy
vi= sei.connecttonewobject('sei3') //连接com组件 if vi <> 0 then
messagebox('错误','创建地纬嵌入式接口sei对象失败!')
return end if
我们使用.NetFramework4.6.1调用方式:
Type type = Type.GetTypeFromProgID("sei3", true);
dynamic COM = Activator.CreateInstance(type);
使用同样的方式,在.NetCore3.1.4上运行返回异常:
Creating an instance of the COM component with CLSID {D5D8D5B2-CCD5-4EEC-BE61-0CA13A1940C7} from the IClassFactory failed due to the following error: ffffdf8f 0xFFFFDF8F.
Example 1: com interoperability of medical insurance system docking:
The insurance system interface specification provides Pb call examples:
//Create the ground latitude embedded interface object and call COM component
int vi Oleobject sei
SEI = create oleobject / / create OLE object seiproxy
vi= sei.connecttonewobject ('sei3 ') / / connect COM component if VI < > 0 then
MessageBox ('error ',' failed to create SEI object of ground latitude embedded interface! ')
return end if
We use. Netframework 4.6.1 to call:
Type type = Type.GetTypeFromProgID ("sei3", true);
dynamic COM = Activator.CreateInstance (type);
Using the same method, run return exception on. NETCORE 3.1.4:
Creating an instance of the COM component with CLSID {D5D8D5B2-CCD5-4EEC-BE61-0CA13A1940C7} from the IClassFactory failed due to the following error: ffffdf8f 0xFFFFDF8F.
weltkante commentedon Jun 3, 2020
@RussKie I'll put a PR up later today
RussKie commentedon Jun 3, 2020
Awesome 👍
JeremyKuhne commentedon Jun 3, 2020
@199621616 I've created dotnet/runtime#37362 to follow up on your comment as it appears that you have a general COM interop issue.
cc: @AaronRobinsonMSFT