I'm getting build time error when setting a static variable inside my database project layer, its being setting inside the Startup
method inside Startup.cs
of my ASP.NET Web API.
When this block of code is commented it compile and runs ok, just I don't get the connection string I need.
The worst part is that the error itself isn't described, there is nothing on error box that popup and it doesn't tell nothing more than there is an error.
The method is the following:
public Startup(IConfiguration configuration)
{
Configuration = configuration;
// init of bug block
string cnn = configuration.GetConnectionString("MyConnectionStringConfig");
MyProjectDataLayer.MyClassDataLayer.MyStaticMethodSettingConnectionString(strCnn);
// end of bug block
}
The MyClassDataLayer
and MyStaticMethodSettingConnectionString
are public.
Now I realize that although the "Error List" is empty there is this error description on "Output" box:
C:\MyWebApi\Startup.cs(21,21,21,31): error CS0122: 'MyClassDataLayer' is inaccessible due to its protection level
Done building project "MyWebApi.csproj" -- FAILED.
The class is the following:
namespace MyProjectDataLayer
{
public class MyClassDataLayer : DbContext
{
private static string _staticCnn = "";
public static void MyStaticMethodSettingConnectionString(string cnnParam)
{
MyClassDataLayer._staticCnn = cnnParam;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseMySql(connectionString: MyClassDataLayer._staticCnn, mySqlOptions => mySqlOptions.CharSetBehavior(CharSetBehavior.NeverAppend));
}
public DbSet<Model001> md1 { get; set; }
public DbSet<Model002> md2 { get; set; }
}
}