C# Error CS0596 – The Guid attribute must be specified with the ComImport attribute

C# Error

CS0596 – The Guid attribute must be specified with the ComImport attribute

Reason for the Error & Solution

The Guid attribute must be specified with the ComImport attribute

The Guid attribute must be present when using the ComImport attribute.

The following sample generates CS0596:

// CS0596.cs  
using System.Runtime.InteropServices;  
  
namespace x  
{  
   [ComImport]   // CS0596  
   // try the following line to resolve this CS0596  
   // [ComImport, Guid("00000000-0000-0000-0000-000000000001")]  
   public class a  
   {  
   }  
  
   public class b  
   {  
      public static void Main()  
      {  
      }  
   }  
}  

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...