I'm running into an odd issue where I've developed a NuGet package. Because of the architecture of the legacy software I'm trying to write new functionality for, this is in .NET Framework 4.6.1 (I know, I know. We're working toward upgrading). The NuGet package is written in C#, while the app that will reference the NuGet package is in VB .NET that is in .NET Framework 4.6.1. The legacy app leverages three total NuGet packages I've written for this solution, but they are not appearing as errors.
The issue is in the title for this question. The public static class and methods in the NuGet package I've written are being marked as "not declared. It may be inaccessible due to its protection level." Because of this error, I obviously cannot build.
I've tried the following:
It may also be worth noting that the branch I'm on for the legacy application builds without changes, it also builds with my NuGet packages referenced. It doesn't build as soon as I added the calls into the NuGet package. I'm wondering if it's a an issue with the Wait()
function, but I can't seem to derive the actual issue at hand. The errors that come up in the output during build just say the same 'not found/inaccessible' language.
Code samples below:
Within the NuGet package, I have the following code.
public static class ClassInNugetPackage
{
public static async Task Initialize(string customerNumber, int locationId)
{
await SystemState.Instance.Initialize(customerNumber, locationId);
}
public static async Task SetApiUrl(string url)
{
await SystemState.Instance.SetApiUrl(url);
}
}
The legacy application will call this in a form constructor like this:
Public Sub New()
InitializeComponent()
Dim customerNumber = "170"
Dim customerLocationId = 2140
NamespaceInNugetPackage.ClassInNugetPackage.SetApiUrl("https://localhost:7012").Wait()
NamespaceInNugetPackage.ClassInNugetPackage.Initialize(customerNumber, customerLocationId).Wait()
If ClassInNugetPackage.BooleanValue.IsEnabled Then
MsgBox("Yes!")
End If
...
End Sub
First off, I did not come to this resolution by myself. The comments of the community really steered me in a better direction, and led to this resolution. The codebase that I'm attempted to add functionality to is older and has a lot of references to older versions of NuGet packages (again, we're working on upgrading them).
I'm able to build now because I did the following:
Thanks all for your help, and especially to Craig for giving the direction that led to the packageref and packages.config. This made me think of leveraging the Upgrade Assistant to see if the output would differ, and it did. Before the Upgrade Assistant migration to .NET SDK, I saw a singular error for each instance of calling my NuGet package, which was of the same verbiage (not found or not accessible), which is what confused me.
Thank you all for your consideration, input, and help. This got me to the next step!