Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cs7003 unexpected use of an unbound generic name

I'm getting this error in Visual Studio:

Error CS7003 Unexpected use of an unbound generic name MyProject C:\Users[myname]\documents\visual studio 2015\Projects....\Index.cshtml 1

The offending file is right here (line 1 error is the reference to the model declaration):

@model MyProject.Models.MyAccount.Details
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_PrimaryLayout.cshtml";
}
<!-- Page Content -->
<div class="container">
.... more page stuff follows from here

The model class is as follows:

namespace MyProject.Models.MyAccount
{
    public class Details
    {
        public static Details Select(Company c)
        {
            Details model = new Details();
            model.SomeProperty = "SomeValue";


            return model;
        }

        public String SomeProperty { get; set; }
    }
}

The weird thing is that cleans don't make it go away, rebuilds leave it there, and I build/debug just fine.

like image 724
Eric Avatar asked Dec 24 '15 17:12

Eric


3 Answers

It took shutting down Visual Studio and restarting for the error to clear. Subsequent rebuilds do not produce the error.

like image 175
Eric Avatar answered Sep 25 '22 22:09

Eric


Just cut the line @model and save, then paste it again and save, it should be gone.

like image 29
moaaz salem Avatar answered Sep 21 '22 22:09

moaaz salem


I made a mistake that took me quite a while to see. I created a generic method:

public static T MyMethod<T>() { ... }

By mistake, I wrote in my code

var something = MyMethod<>();

It compiled but at runtime it threw the error "unexpected use of an unbound generic name".

If ever you made the same mistake, you might try to search "<>" in your code...

like image 21
Charles HETIER Avatar answered Sep 24 '22 22:09

Charles HETIER