This is my first foray into .NET Core. The following code works, and has worked for years in regular ASP.NET applications. But in my first .NET Core app, the extension methods are reporting undefined.
namespace CoreAPI1 {
class SQL_Data {
public SqlDataReader DBReader(string query) {
using (SqlCommand cmd = new SqlCommand(query,cn)) {
return cmd.ExecuteReader();
}
}
}
public static class SQLExtentions {
public static bool Exists(this SqlDataReader rs, bool closeAfterReading = true) {
bool hasRows = rs.HasRows;
if (closeAfterReading) {
rs.Close();
}
return hasRows;
}
}
}
But later, when I attempt to actually USE the extension:
var exists = new SQL_Data().DBReader("SELECT * FROM ...").Exists();
I get:
.SqlDataReader does not contain a definition for 'Exists'
Even though SQL_Data()
class, and it's .DBReader()
method are both found and working, the extension method is not.
Any ideas? Again, this is my first attempt at a .NET Core, so I do not know if there are peculiarities in config files, or properties dialogs that I've missed.
Both the SQL_Data()
class, and the SQLExtentions
class are in the same module: SQLClass.cs
, in the same namespace, CoreAPI1
.
As written in the comments -
check that all places has correct using
's specified, such behavior can be sign of namespace missing/mismatched.