How to suppress compiler warnings from using COM references in a .NET project

We use the Windows COM + service type library (located in C: \ Windows \ system32 \ COMSVCS.dll) to track COM + processes on a remote computer using a service written in C # 3.0 / .NET 3.5. The problem I'm facing is that I get a whole bunch of warnings from the compiler that look something like this:

At least one of the arguments for "IGetAppData.GetApps" cannot be a marshaled runtime marshaler. Thus, such arguments will be passed as a pointer and may require unsafe code to control.

The generated signature of the interaction function for the above method:

void IGetAppData.GetApps(out uint nApps, IntPtr aAppData) 

Since the output is already done manually in the calling code (i.e. using Marshall.ReadInt32 and Marshall.PtrToStructure ), is there a way to suppress these warnings?

+4
source share
5 answers

since this warning has no number, you cannot suppress it with #pragma, but you can use tlbimp to import the dll outside of Visual Studio and use the generated link instead of letting Visual Studio create it.

+2
source

Add this line to the first group of properties of your project file:

 <ResolveComReferenceSilent>True</ResolveComReferenceSilent> 
+4
source

You can try using the advanced custom Import type library in managed code to configure method signatures. Then reference this shell instead of the original COM library in your project.

+1
source

I was able to solve this by specifying a link to Interop.xxxx.dll instead of the main dll. In my case, using Interop.TaskScheduler.dll works, and taskschd.dll gives me a warning. I checked the use of Rebuild All and the warning disappeared.

0
source

If everything you want to hide warnings from showing, you can use the # pragma warning directive. This allows you to selectively enable / disable specific alerts.

-1
source

All Articles