Sometime things don’t always go as planned. I was making some nice progress with the process of mapping a database and all of a sudden I get the following compile time error message.
- Ambiguous type reference. A type named “Attribute” occurs in at least two namespaces.
- “Attribute” ist ein mehrdeutiger Verweis und kann “System.Attribute” oder “NAMESPACE.Attribute” sein.
There was a database table named Attribute and I simply created the Attribute.cs file and class and then referenced the Attribute via a many-to-one mapping and the error was generated.
The error was rightly generated because the compiler was not able to determine which Attribute class I was referring to.
I wrote about an issue I had using reserved words as variables within code here. It causes some problems later and doing it should be avoided. But of course, you need to know it’s a reserved word before you know not to use it, that comes with time.
To resolve the error I provided the NAMESPACE.Attribute from the reference within the class.cs file. Then the compiler know I didn’t want System.Attribute and instead wanted the custom Attribute class created within my program.