C# Error CS0643 – ‘{0}’ duplicate named attribute argument

C# Error

CS0643 – ‘{0}’ duplicate named attribute argument

Reason for the Error & Solution

‘arg’ duplicate named attribute argument

A parameter, arg, on a user-defined attribute was specified twice. For more information, see .

Example

The following sample generates CS0643:

// CS0643.cs  
using System;  
using System.Runtime.InteropServices;  
  
[AttributeUsage(AttributeTargets.Class)]  
public class MyAttribute : Attribute  
{  
    public MyAttribute()  
    {  
    }  
  
    public int x;  
}  
  
[MyAttribute(x = 5, x = 6)]   // CS0643, error setting x twice  
// try the following line instead  
// [MyAttribute(x = 5)]  
class MyClass  
{  
}  
  
public class MainClass  
{  
    public static void Main ()  
    {  
    }  
}  

Leave A Reply

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

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...