Microsoft KB Archive/318765

= BUG: PInvoke method with System.GUID return type raises exception error =

Article ID: 318765

Article Last Modified on 9/13/2005

-

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.



Steps to Reproduce the Behavior
 In Visual Studio .NET, create a new Visual C# Console Application project named TestPInvoke.  Add the following code to Class1 of the Class1.cs file: [System.Runtime.InteropServices.DllImport(&quot;xyz.dll&quot;)] 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).

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

Keywords: kbbug kbcomservices kbcominterop kbvs2002sp1sweep KB318765

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.