Lots of build warnings when COM objects ActiveDs or MSXML2 are referenced

gyrolf picture gyrolf · Nov 6, 2008 · Viewed 8.1k times · Source

After moving a project from .NET 1.1 to .NET 2.0, MsBuild emits lots of warnings for some COM objects.

Sample code for test (actual code doesn't matter, just used to create the warnings):

using System;
using System.DirectoryServices;
using ActiveDs;
namespace Test
{
    public class Class1
    {
        public static void Main(string[] args)
        {
            string adsPath = String.Format("WinNT://{0}/{1}", args[0], args[1]);
            DirectoryEntry localuser = new DirectoryEntry(adsPath);
            IADsUser pUser = (IADsUser) localuser.NativeObject;
            Console.WriteLine("User = {0}", pUser.ADsPath);
        }
    }
}

Warning messages look like

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'ITypeLib.RemoteGetLibAttr' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

Observations:

  • Happens for ActiveDs (11 warnings) and MSXML2 (54 warnings).
  • Not seen for our own COM objects.
  • <Reference> entry in .csproj file contains attribute WrapperTool = "tlbimp"
  • Despite of all warnings, no problems have been observed in the running system.

Any idea how to get rid of the warnings?

Answer

Hermann.Gruber picture Hermann.Gruber · Oct 19, 2015

I had experienced the same problem and fixed it by editing the project file (.csproj), following a suggestion from here:

https://social.msdn.microsoft.com/Forums/vstudio/en-US/7a7c352b-20cb-4931-b3b5-27e899016f75/turning-off-msbuild-warnings-msb3305?forum=msbuild

I added the following key to the property group of each build configuration:

<ResolveComReferenceSilent>True</ResolveComReferenceSilent>