0

I'm scratching my head on a problem that seems easy...I've published a NuGet package on my private server. This contains the SqlDb class:

public class SqlDb
{
    public void SetConnectionString(string connectionString)
    {
        // CODE
    }
}

The goal is to use this package in another solution with two projects: App.Database and App.Server. On App.Database I would like to manage all methods to MySQL and access them from App.Server.

App.Database contains:

public class Db : SqlDb
{
}

App.Server contains:

internal class Program
{
    static void Main(string[] args)
    {
        var db = new Db();
        db.SetConnectionString(args[0]);
    }
}

App.Server has a reference to App.Database (I can access Db() class) but I can't see inherited methods from SqlDb (like SetConnectionString()).

Someone can help me to understand what I'm doing wrong ? Should I rewrite each method like:

public class Db : SqlDb
{
    public void SetConnectionString(string connectionString)
    {
        base.SetConnectionString(connectionString);
    }
}

I hope not...

  • Hmm this sounds like a problem with how c# shares code between projects, even if in the same solution. Have you tried creating the DB class (and other classes you want to share ) as a library project or package it as an assembly in order to reference across the solution? – Nico Mar 09 '22 at 10:08
  • Yes, I've already done without success. App.Database is a library project (with reference to the NuGet package). When solution compiles (commenting the line with `db.SetConnectionString(args[0]);`) I can see that the compiler order is correct (first compiles App.Database, then uses the new .dll as reference for App.Server). – Mario Vaccaro Mar 09 '22 at 10:14
  • Do you see any error when you try to call your method `db.SetConnectionString`? It should work. Something like this *`Db` does not contain a definition for 'SetConnectionString' and no accessible extension method 'SetConnectionString' accepting a first argument of type 'Db' could be found (are you missing a using directive or an assembly reference?)*. As another suggestion, try to remove `internal ` keyword. – StepUp Mar 10 '22 at 20:28

0 Answers0