HomeCSharpC# Error CS0617 – ‘{0}’ is not a valid named attribute argument. Named attribute arguments must be fields which are not readonly, static, or const, or read-write properties which are public and not static.

C# Error CS0617 – ‘{0}’ is not a valid named attribute argument. Named attribute arguments must be fields which are not readonly, static, or const, or read-write properties which are public and not static.

C# Error

CS0617 – ‘{0}’ is not a valid named attribute argument. Named attribute arguments must be fields which are not readonly, static, or const, or read-write properties which are public and not static.

Reason for the Error & Solution

‘reference’ is not a valid named attribute argument because it is not a valid attribute parameter type

An attempt was made to access a member of an attribute class.

Example

The following sample generates CS0617.

// CS0617.cs  
using System;  
  
[AttributeUsage(AttributeTargets.Struct |
                AttributeTargets.Class |  
                AttributeTargets.Interface)]  
public class MyClass : Attribute  
{  
   public int Name;  
  
   public MyClass (int sName)  
   {  
      Name = sName;  
      Bad = -1;  
      Bad2 = -1;  
   }  
  
   public readonly int Bad;  
   public int Bad2;  
}  
  
[MyClass(5, Bad=0)] class Class1 {}   // CS0617  
[MyClass(5, Bad2=0)] class Class2 {}  

Leave a Reply

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...