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

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