5

We're using the Windows COM+ Services Type Library (located at C:\Windows\system32\COMSVCS.dll) to track COM+ processes on a remote machine using a service that is written in C# 3.0/.NET 3.5. The problem that I am encountering is that I am getting a whole slew of warnings from the compiler that look something like the following:

At least one of the arguments for 'IGetAppData.GetApps' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

The generated interop function signature for the method mentioned above is:

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

As the output is already being marshalled manually in the calling code (i.e. using Marshall.ReadInt32 and Marshall.PtrToStructure), is there a way to suppress these type of warnings?

jpoh
  • 4,536
  • 4
  • 35
  • 60
  • Possible duplicate of http://stackoverflow.com/questions/269063/lots-of-build-warnings-when-com-objects-activeds-or-msxml2-are-referenced/1402834#1402834 – Ed Bayiates Jul 06 '16 at 20:10

5 Answers5

9

Add this line in first property group of your project file:

<ResolveComReferenceSilent>True</ResolveComReferenceSilent>
Igor Tkachenko
  • 468
  • 7
  • 13
2

since that warning don't have a number you cannot suppress it using #pragma but you can use tlbimp to import the dll outside Visual Studio and use the generated reference instead of letting Visual Studio creating it.

Shay Erlichmen
  • 31,691
  • 7
  • 68
  • 87
1

You can try using the vastly improved, customizable Type Library Importer in Managed Code to customize the method signatures. Then reference this wrapper instead of the original COM library in your project.

Sam Harwell
  • 97,721
  • 20
  • 209
  • 280
0

I was able to solve this by pointing the reference to Interop.xxxx.dll instead of the main dll. In my case using Interop.TaskScheduler.dll works whereas taskschd.dll gives me the warning. I verified using a Rebuild All and the warning is gone.

  • 1
    I think this is because the conversion to the interop has already taken place, so there's no more warnings. There's methods out there that show you how to build these interops yourself using tlbimp directly, with the same effect. – Jon Marnock Sep 17 '12 at 22:42
-1

If all you want is to hide the warnings from showing up, you can use the #pragma warning directive. That allows you to selectively enable/disable specific warnings.

Senthil Kumar
  • 479
  • 2
  • 5