C# Error CS1016 – Named attribute argument expected

C# Error

CS1016 – Named attribute argument expected

Reason for the Error & Solution

Named attribute argument expected

Unnamed attribute arguments must appear before the named arguments.

Example

The following sample generates CS1016:

// CS1016.cs  
using System;  
  
[AttributeUsage(AttributeTargets.Class)]  
public class HelpAttribute : Attribute  
{  
    public HelpAttribute(string url)   // url is a positional parameter  
    {  
        m_url = url;  
    }  
  
    public string Topic = null;      // Topic is a named parameter  
    private string m_url = null;  
}  
  
[HelpAttribute(Topic="Samples", "http://intranet/inhouse")]   // CS1016  
// try the following line instead  
//[HelpAttribute("http://intranet/inhouse", Topic="Samples")]  
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

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