Can SuppressUnmanagedCodeSecurityAttribute be applied to COM Interop interfaces?

StackOverflow https://stackoverflow.com/questions/19253484

  •  30-06-2022
  •  | 
  •  

سؤال

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