NET 8 WinForms project fails to find types (CS0246) from NuGet package despite clean install and all caches cleared.

Thomas Abell 20 Reputation points
2025-10-06T18:42:12.4233333+00:00

I have migrated a .NET Framework 4.8 WinForms project to .NET 8. I am using Mapsui 5.0.0-rc.2. The project fails to compile with errors like CS0246: The type or namespace name 'Shapefile' could not be found, even though the package is referenced.

Symptoms:

using statements for Mapsui.Tiling.Layers and Mapsui.Nts.Providers.Shapefile are "dimmed gray" in Visual Studio, as if unused.

The compiler cannot find types from those namespaces (e.g., Shapefile, OpenStreetMap, ThemeStyle).

This occurs even in a brand new, clean project on my machine.

Troubleshooting Steps Already Taken (None have worked):

Cleaned and rebuilt the solution multiple times.

Manually deleted all bin and obj folders.

Reinstalled all NuGet packages.

Cleared all NuGet caches using dotnet nuget locals all --clear.

Completely replaced the old .csproj file with a new, clean SDK-style project file for .NET 8.

Deleted the hidden .vs solution folder.

Performed a full "Repair" of my Visual Studio installation and rebooted.

Moved <Compile Update> tags for my Forms from a .csproj.user file to the main .csproj file.

Here is my current, clean .csproj file:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
	<OutputType>WinExe</OutputType>
	<TargetFramework>net8.0-windows</TargetFramework>
	<UseWindowsForms>true</UseWindowsForms>
	<RootNamespace>ReverewoodRadar</RootNamespace>
	<AssemblyName>ReverewoodRadar</AssemblyName>
	<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
	<PackageReference Include="Mapsui.WindowsForms" Version="5.0.0-rc.2" />
	<PackageReference Include="Mapsui.Nts" Version="5.0.0-rc.2" />
	<PackageReference Include="Mapsui.Tiling" Version="5.0.0-rc.2" />
	<PackageReference Include="Mapsui.Rendering.Skia" Version="5.0.0-rc.2" />
	<PackageReference Include="NetTopologySuite.IO.Esri.Shapefile" Version="1.2.0" />
	<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
	<PackageReference Include="SharpZipLib" Version="1.4.2" />
</ItemGroup>
<ItemGroup>
	<PackageReference Include="Microsoft.Windows.Compatibility" Version="8.0.7" />
</ItemGroup>
<ItemGroup>
	<ProjectReference Include="..\SharedLibrary\SharedLibrary.csproj" />
</ItemGroup>
<ItemGroup>
	<Compile Remove="Level3Parser.cs" />
	<Compile Remove="Level3Radar.cs" />
	<Compile Remove="Radars.cs" />
	<Compile Remove="USGSMapProvider.cs" />
</ItemGroup>
<ItemGroup>
	<None Remove="MainForm.cs.backup" />
</ItemGroup>
<ItemGroup>
	<None Update="ShapeFiles\cb_2023_us_county_500k.*">
		<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
	</None>
	<None Update="ShapeFiles\cb_2023_us_state_500k.*">
		<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
	</None>
	<None Update="ShapeFiles\cities.dat">
		<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
	</None>
	<None Update="ShapeFiles\tl_2024_us_primaryroads.*">
		<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
	</None>
</ItemGroup>
<ItemGroup>
	<Compile Update="Properties\Settings.Designer.cs">
		<DesignTimeSharedInput>True</DesignTimeSharedInput>
		<AutoGen>True</AutoGen>
		<DependentUpon>Settings.settings</DependentUpon>
	</Compile>
	<None Update="Properties\Settings.settings">
		<Generator>SettingsSingleFileGenerator</Generator>
		<LastGenOutput>Settings.Designer.cs</LastGenOutput>
	</None>
	<EmbeddedResource Update="Properties\Resources.resx">
		<Generator>ResXFileCodeGenerator</Generator>
		<LastGenOutput>Resources.Designer.cs</LastGenOutput>
	</EmbeddedResource>
</ItemGroup>
<ItemGroup>
	<Compile Update="BufferedPanel.cs">
		<SubType>Component</SubType>
	</Compile>
	<Compile Update="Form1.cs">
		<SubType>Form</SubType>
	</Compile>
	<Compile Update="MainForm.cs">
		<SubType>Form</SubType>
	</Compile>
	<Compile Update="Options.cs">
		<SubType>Form</SubType>
	</Compile>
	<Compile Update="PublishingDialog.cs">
		<SubType>Form</SubType>
	</Compile>
	<Compile Update="SettingsForm.cs">
		<SubType>Form</SubType>
	</Compile>
	<Compile Update="WarningsWindow.cs">
		<SubType>Form</SubType>
	</Compile>
</ItemGroup>
</Project>
Developer technologies | Windows Forms
0 comments No comments
{count} votes

Answer accepted by question author
  1. Danny Nguyen (WICLOUD CORPORATION) 3,500 Reputation points Microsoft External Staff
    2025-10-07T06:50:01.3933333+00:00

    Hi @Thomas Abell ,

    Thank you for posting in this forum.

    I have taken a look through your question, and I think that The CS0246 errors you’re seeing are not caused by broken NuGet references, but rather by calling the ShapeFile class wrongly.

    The shapefile provider class is now named ShapeFile (with a capital F) under the Mapsui.Nts.Providers.Shapefile namespace. Older examples or blog posts may still reference Shapefile, which will no longer resolve. Other helpers, like OpenStreetMap and ThemeStyle, were removed or replaced. For example, OSM layers are now created using BruTile’s KnownTileSources, and style/theme selectors have been updated.

    This is why the using statements appear gray in Visual Studio as there are no valid symbols from those namespaces being referenced.

    So to fix this:

    • Update your code to use the new class names and APIs, e.g., ShapefileShapeFile.
    • Adjust other outdated identifiers according to Mapsui 5’s API.

    Once these updates are made, your project should compile successfully. You can confirm that the NuGet packages are correctly referenced by checking that the Mapsui DLLs appear in your build output.I hope this helps. Please let me know if my solution works out for you and consider interact with the system accordingly if so.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.