Continuing to play around with .Net C#.
Ran into an error I could not get beyond.
error CS0246: The type or namespace name '[interface]<>' could not be found (are you missing a using directive or an assembly reference?)
var incr = new Increment<ClassA>();
Preface usage by indicating the code uses classes in the System.Collections.Generic namespace.
Compiled and got an error that reads:-
error CS0144: Cannot create an instance of the abstract class or interface 'Increment<ClassA>'
Add Third-Party Namespaces
Went back and added “using System.Collections.Generic”.
Compiled and ended with a new error message.
error CS0104: 'Increment<>' is an ambiguous reference between 'System.Collections.Generic.Increment<T>' and 'thirdPartyPackage.Increment<T>'
To fix the ambiguity error, please prefix the interface name with the namespace.
var incr = new <namespace>.Increment<ClassA>();
- As you learn things a bit and use things such as Generics, the language parser sometimes stumbles a bit.
- One quick fix is to quickly add in “using System.Collections.Generic;“
- Unfortunately in my particular case got an error that reads:-
- CS0144: Cannot create an instance of the abstract class or interface ‘Increment<ClassA>’
- Removed “using System.Collections.Generic;“
- And, added the specific third party namespace that defines the applicable interface
Though object-oriented programming is very helpful with avoiding name collision, one is not completely out of the woods.
Intentionally I obtused the name of the actual package that I was exploring.
Also, the actual method name.
When writing a post, one can come at it from different angles.
I did not want to draw focus away from the error message.
The error message itself was a bit more interesting than the package itself.