ā” Cannot find .dll in referenced project

I have a class library targetting .NET Standard 2.0. This library references two nuget packages: NETStandard.Library (2.0.3) and NetTopologySuite.IO.Esri.Shapefile (1.0.0). The class library builds fine. I then have a console app project in the same solution that targets .NET Framework 4.8.1. This project references the class library project. The console ap builds without warnings or errors. However, when running the app, as soon as I hit the first line that references the class library, I get the following error: "Exception thrown: 'System.IO.FileNotFoundException' in NetFrameworkTestApp.exe An unhandled exception of type 'System.IO.FileNotFoundException' occurred in NetFrameworkTestApp.exe Could not load file or assembly 'NetTopologySuite.Features, Version=2.0.0.0, Culture=neutral, PublicKeyToken=f580a05016ebada1' or one of its dependencies. The system cannot find the file specified." Looking in the bin folder of the console app, I see the class library dll but not the two nuget packages' dlls. The dlls do exist in the bin of the class library. What am I missing here?
16 Replies
mtreit
mtreitā€¢8mo ago
What does your program's csproj look like? BTW you probably shouldn't need to reference this thing:
NETStandard.Library
NETStandard.Library
Also does this file exist anywhere?
NetTopologySuite.Features.dll
NetTopologySuite.Features.dll
Nacho Man Randy Cabbage
Do you want the whole csproj file? Here's the part referencing my class library: <ItemGroup> <ProjectReference Include="..\HuginFileProcessor\ShapefileTestingLib.csproj"> <Project>{0334C783-9937-4C44-824D-624CD0362332}</Project> <Name>ShapefileTestingLib</Name> </ProjectReference> </ItemGroup> And here is what the dependencies looks like for my ShapefileTestingLib class library:
No description
mtreit
mtreitā€¢8mo ago
Oh god, is that the old csproj format? šŸ˜± Change to the new SDK format
Nacho Man Randy Cabbage
I have no idea lol. It's just what vs 2022 made when I picked to create a class library project
mtreit
mtreitā€¢8mo ago
harold this a console app?
Nacho Man Randy Cabbage
yup
Nacho Man Randy Cabbage
weird how it mentions it can't find 2.0.0.0 but I don't see that referenced anywhere
No description
mtreit
mtreitā€¢8mo ago
Run dotnet new console --name MyProject in a different folder, then copy the csproj it generate over. Edit it in a text editor and change the TargetFramework to net481 or whatever. Then open it in Visual Studio and add back your project references. The old csproj format is garbage. Or send me the project on github or something and I can convert it in about 10 seconds šŸ™‚ I migrated more than 600 projects to the new SDK format, it's ingrained in my muscle memory now.
Nacho Man Randy Cabbage
hmm does net48 cover 4.8.1? don't see net481 listed https://learn.microsoft.com/en-us/dotnet/standard/frameworks
Target frameworks in SDK-style projects - .NET
Learn about target frameworks for .NET apps and libraries.
mtreit
mtreitā€¢8mo ago
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net481</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net481</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

</Project>
This builds fine for me ĀÆ\_(惄)_/ĀÆ
Nacho Man Randy Cabbage
šŸ™Œ it worked using the newer format thank youuu. I would have never thought of that
mtreit
mtreitā€¢8mo ago
When the SKD builds the new format it enables "transitive" references where dependencies of things you reference get pulled in automatically. The fact that VS is stil using the old format for newly created .NET Framework projects is deeply sad. I guess nobody is focusing on .NET Framework since it's considered a technological dead end at this point.
Nacho Man Randy Cabbage
oh wow, that is good to know because my employer is still using mostly .net framework apps (slowly moving to .net 6 though!)
mtreit
mtreitā€¢8mo ago
There are few good reasons to use .NET Framework these days. Like if it's a new project I would never target Framework. Except maybe in some very specific circumstances where you don't want to or can't install the .NET runtime on your target Windows machines.
Nacho Man Randy Cabbage
yeah apparently one of our users thought they had .net 6 installed but it was actually just esri .net 6 dlls, and it's a months long process to get anything new installed šŸ˜… oh well. thanks again šŸ™‚
Accord
Accordā€¢8mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.