BUG: PInvoke method with System.GUID return type raises exception error (318765)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2002), Professional Edition

This article was previously published under Q318765

SYMPTOMS

When you run Platform Invocation Services (PInvoke) with System.GUID as the return type, the process is unsuccessful and you receive the following exception error message:
An unhandled exception of type 'System.Runtime.InteropServices.MarshalDirectiveException' occurred in TestPInvoke.exe Additional information: Method's type signature is not PInvoke compatible.

STATUS

Microsoft has confirmed that this is a problem in Visual Studio .NET.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. In Visual Studio .NET, create a new Visual C# Console Application project named TestPInvoke.
  2. Add the following code to Class1 of the Class1.cs file:
    [System.Runtime.InteropServices.DllImport("xyz.dll")]
    public static extern System.Guid returnGUID();
    public static void Main(string [] args)
    {
      System.Guid aguid = returnGUID();
    }
    					
    NOTE: The Xyz.dll file may be anything because the exception error occurs at the marshalling layer, during the validation of the PInvoke parameters before the .NET Framework calls the native method. To reproduce the problem, you do not have to add a reference, and the argument to DllImport can be any string (including an empty string) instead of an actual dynamic-link library (DLL).

  3. Build and run the project. The exception appears at the following line of code:
    System.Guid aguid=returnGUID();

Modification Type:MinorLast Reviewed:9/13/2005
Keywords:kbvs2002sp1sweep kbbug kbCOMInterop kbCOMServices KB318765 kbAudDeveloper