Search code examples
c#.netexport-to-excel

What does "The non-generic type 'System.Web.UI.Pair' cannot be used with type arguments" mean?


 foreach (Pair<Pair<int, int>, Cell> cell in sheet.Cells)
            {
                dgvCells[cell.Left.Right, cell.Left.Left].Value = cell.Right.Value;
            }

I am working on creating a excel file from within .NET, using this Excel Library

I am getting the warning mentioned in the title. Any ideas?


Solution

  • Just for future reference, and understanding, the error message:

    The non-generic type '' cannot be used with type arguments

    is replaced with some class, indicates that within your code you are attempting to make use of a non-generic class in a generic way. More specifically you are using some syntax which is incompatible with that type, in this case the <> generic braces on the type "Pair".

    To typically solve the problem

    • Identify the types use within the file, specifically its use in a generic way. (This should find them: Ctrl + F > "SomeClass<")
    • Ensure that the type is as expected (F12 on the type should take you to its declaration)
    • If the type is different to the expected type you should make use of a using alias to point to the correct type namespace i.e.

      using Pair = Fully.Qualified.Namespace.Of.Pair;
      
    • If the type is as expected ensure that it is generic, if not you can either modify it to be generic, if you have permission/access to do so, or you could select/create a different type which is more suitable for your purpose.

    • Alternativly you could modify your use of the type to be non-generic