C# Error CS0404 – ‘<' unexpected : attributes cannot be generic

C# Compiler Error

CS0404 – ‘<‘ unexpected : attributes cannot be generic

Reason for the Error

You’ll get this error in your C# code you are trying to use the generic type parameters in attributes.

For example, lets try to compile the below code snippet.

using System;

namespace DeveloperPublishNamespace
{
    [Attribute1<int>]    
    public class Employee
    {
        public int this[int input]   
        {
            get { return input; }
            set { }
        }
    }

    internal class Attribute1Attribute<T> : Attribute
    {
    }

    class Program
    {      
        static void Main(string[] args)
        {           
            Console.WriteLine("Hello World!");
        }
    }
}

You’ll receive the error code CS0404 because you are using the generic parameter type on the attribute class “Attribute1”.

Error CS0404 Cannot apply attribute class ‘Attribute1Attribute’ because it is generic DeveloperPublish C:\Users\Senthil\source\repos\ConsoleApp4\ConsoleApp4\Program.cs 5 Active

C# Error CS0404 – '<' unexpected : attributes cannot be generic

Solution

You can fix this error in your C# program by removing the type parameter that is generic and the angle brackets.

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