Can SuppressUnmanagedCodeSecurityAttribute be applied to COM Interop interfaces to improve performance, or is it only suitable for optimizing native function calls? MSDN says:

This attribute is only effective when applied to PInvoke methods (or classes that contain PInvoke methods) or the definition of an interface through which interop calls will be made. It will be ignored in all other contexts.

However, I'm not absolutely sure wether that includes COM interop.

有帮助吗?

解决方案 2

or the definition of an interface through which interop calls will be made

That talks about a COM interface. The attribute has to be applied to the interface declaration to be effective. Do note how hard that is to get, COM interfaces are normally declared in the interop library that's generated by Tlbimp.exe. Which is missing an option to auto-generate the attribute. Realistically, you can only do this if you declare the interfaces yourself.

其他提示

According to this MS page, you can have Tlbimp.exe apply the SuppressUnmanagedCodeSecurity attribute to your COM interfaces by passing the "/unsafe" switch. I can confirm that it works as advertised with a simple test TLB.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top