Click here to Skip to main content
15,563,228 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

I had a .Net Standard 2.1 library that I tried to reference in a .Net Framework 4.8 WinForms application, which I discovered that does not work because .Net Standard 2.1 and .Net Framework 4.8 are not compatible..

So, I changed the class library to reference .Net Standard 2.0 and re-built and took the release dll file to the winforms application,

But I got the following exception:
Quote:
System.IO.FileNotFoundException: 'Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.'
Inner Exception:
FileNotFoundException: Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.


I made a Nuget package from the .Net standard class library, and used it in another WPF project (.Net Framework 4.8) and it worked fine,

I used it in a new winforms project (.Net Framework 4.8) and it worked fine,

I removed the reference for the .dll file from the original winforms project and used the nuget package instead, but got the same exception..

So my guess is that using the .Net Standard 2.1 reference first has somehow corrupted the project, so when trying to use the .Net Standard 2.0 nuget package I get the exception despite not having a reference to .Net Standard 2.1

So how can I find where is the .Net Standard 2.1 reference?
and how can I solve this exception?

What I have tried:

1. Unloaded the project and examined the vbproj file searching for a .Net Standard 2.1 reference, didn't find any..

2. Out of desperation, I searched the entire project for "2.1" hoping to find where is that reference, but with no avail.

3. Googled, the issue is not a problem with .Net Standard, it's about this specific situation, I just don't know how to investigate further.

4. Git reset -- hard to the commit before adding the 2.1 version, then added the 2.0 version.. still got the same exception..
Posted
Updated 14-Jun-22 17:30pm
v2
Comments
Sandeep Mewara 22-Aug-20 2:03am    
1. Deleted the bin & obj folders?
2. Deleted old 2.1 nuget downloaded that could be sitting on your system?
Ahmad_kelany 22-Aug-20 2:37am    
1. yes, I did.. same exception.

2. 2.1 was a .dll file not a nuget, the nuget package is 2.0 from the start, and I deleted that .dll file.
Gerry Schmitz 22-Aug-20 10:53am    
Try it with a new "minimal" Windows Forms VS project.

WPF, Windows Forms, UWP, the various Frameworks, are all "works in progress"; and not always / ever in sync.

(And the reason one uses the latest release of everything is because one wants those features, not just "because"; if you want stability)
Ahmad_kelany 22-Aug-20 17:16pm    
I tried it with a complete WPF project, and with a new Winforms project, and it worked fine in both cases, as I stated in the question,

As I said, probably the problem is not in the frameworks, but in the project's specific situation,

And I totally agree with your last line, I used 2.1 standard for a certain feature, but as it was incompatible with 4.8 framework, I foregone that feature and went back to 2.0..

My main question is how to investigate that exception and what causes it..
Gerry Schmitz 23-Aug-20 12:41pm    
The issue seems to be you trying to use a "Nuget package" (for your dll) instead of simply referencing your dll. It would seem you need to look at similar Nuget packages and figure out why yours doesn't work.

You need to check the compatibility table for net core , net framework and net standard frameworks. for instance application targeting net core 3.0 has backward compatibility for net framework 2.0 and lower, so if you include a package version more then 2.1 in app targeting 3.0 you will get this issue

compatibility check can be done on MSN website.

In such an environment, code sharing becomes a major challenge. You need to understand where APIs are available and make sure that shared components only use APIs that are available across all .NET implementations you’re using
 
Share this answer
 
Comments
Richard Deeming 10-Nov-20 6:41am    
The OP already knows that .NET Standard 2.1 is not compatible with .NET Framework 4.8; the question was about how to fix the broken references in their project after removing the reference to the .NET Standard 2.1 package.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900