Question

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.

Was it helpful?

Solution 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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top