Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

dotnet build stops on a .NET Framework project with image resources

Your error

error MSB3822: Non-string resources require the System.Resources.Extensions assembly at runtime, but it was not found in this project's references.1 more line it can show

Fix it fast

Most common cause, 1 of 3

dotnet build meets image resources with neither setting in place

Turn on preserialized resources and reference the package in the .csproj that owns the .resx file.

Fix
<PropertyGroup>
  <GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
</PropertyGroup>
<ItemGroup>
  <PackageReference Include="System.Resources.Extensions" Version="11.0.0" />
</ItemGroup>
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

MSB3822 means dotnet build met a .resx file with non-string data, such as WinForms images or icons, in a .NET Framework project. The .NET SDK's MSBuild can only embed that data preserialized, which needs System.Resources.Extensions at runtime. Set GenerateResourceUsePreserializedResources to true and reference the package, or build with Visual Studio's MSBuild.exe instead.

  • Applies to .NET SDK 10.0.404 and 11.0.100, System.Resources.Extensions 11.0.0, .NET Framework 4.6.2 and later targets
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Save one build log and look at which resource errors it holds, then look for the property, the package and a packages.config file. MSB3823 next to MSB3822 points to cause 1, MSB3822 on its own to cause 2, and a packages.config file to cause 3.

Run this first
dotnet build 2>&1 | tee build.log
grep -nE "MSB382[23]|MSB3245" build.log
grep -rnE "GenerateResourceUsePreserializedResources|System.Resources.Extensions" --include=*.csproj .
ls packages.config

Then find the line you see in this list and open its fix:

  1. 1dotnet build meets image resources with neither setting in placeMSB3823 and MSB3822 both appear for the same .resx file
  2. 2The property is on, but the package never reaches this projectMSB3823 is gone and MSB3822 remains
  3. 3An old-style project lists the package in packages.configpackages.config sits next to the .csproj, and the log also shows MSB3245 for System.Resources.Extensions

What does the error look like?

  • error MSB3822: Non-string resources require the System.Resources.Extensions assembly at runtime, but it was not found in this project's references.
  • error MSB3823: Non-string resources require the property GenerateResourceUsePreserializedResources to be set to true.

Cause 1 of 3

dotnet build meets image resources with neither setting in place

You seeMSB3823 and MSB3822 both appear for the same .resx file

Check

MSB3822 together with MSB3823 means the SDK's MSBuild found non-string data in a .resx file and the project has neither the preserialized property nor the package. Only Visual Studio's MSBuild.exe can still embed such data the old way; MSBuild running on .NET supports the preserialized method alone.

Check
grep -rn "GenerateResourceUsePreserializedResources" --include=*.csproj .

Fix

Turn on preserialized resources and reference the package in the .csproj that owns the .resx file. If you would rather not ship an extra DLL, leave the property out and build that project with Visual Studio or MSBuild.exe instead of dotnet build.

Fix
<PropertyGroup>
  <GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
</PropertyGroup>
<ItemGroup>
  <PackageReference Include="System.Resources.Extensions" Version="11.0.0" />
</ItemGroup>

Verify

The build log has no MSB382x lines, and System.Resources.Extensions.dll lands in the output folder, ready for the app to load at runtime.

Verify
dotnet build
find bin -name "System.Resources.Extensions.dll"

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 3

The property is on, but the package never reaches this project

You seeMSB3823 is gone and MSB3822 remains

Check

A lone MSB3822 says the preserialized path is switched on, yet no assembly named System.Resources.Extensions sits in the references given to the GenerateResource task. MSBuild compares the resolved references by assembly name, so the package has to resolve for the very project that compiles the .resx file.

Check
dotnet package list --include-transitive | grep -i Resources.Extensions

Fix

Add the PackageReference to that project's .csproj and build again. On a .NET 9 SDK or older, the list command above is spelled dotnet list package.

Fix
<ItemGroup>
  <PackageReference Include="System.Resources.Extensions" Version="11.0.0" />
</ItemGroup>

Verify

The package list now shows System.Resources.Extensions for the project, and the build ends without MSB3822.

Verify
dotnet build 2>&1 | grep -c MSB3822

Confirmed by learn.microsoft.com

Did this fix it?

Cause 3 of 3

An old-style project lists the package in packages.config

You seepackages.config sits next to the .csproj, and the log also shows MSB3245 for System.Resources.Extensions

Check

With a packages.config project, MSB3822 can stay after you install the package, because dotnet restore only reads PackageReference items. The .csproj then points with a HintPath into a packages folder that nothing restored, MSB3245 reports the reference as unresolved, and GenerateResource still finds no System.Resources.Extensions.

Check
grep -n "System.Resources.Extensions" packages.config

Fix

Move the project to PackageReference: in Visual Studio, right-click packages.config and choose Migrate packages.config to PackageReference. If it has to stay on packages.config for now, restore it with MSBuild before each dotnet build.

Fix
msbuild -t:restore -p:RestorePackagesConfig=true
dotnet build

Verify

The packages folder holds System.Resources.Extensions, the MSB3245 warning is gone, and the build succeeds.

Verify
dotnet build 2>&1 | grep -E "MSB3245|MSB3822"

Confirmed by learn.microsoft.com

Did this fix it?

How do I stop it coming back?

  • Put the property and the PackageReference next to each other in the same .csproj, so a copy of one never travels without the other.
  • Convert packages.config projects to PackageReference before you move their CI builds from MSBuild.exe to the dotnet CLI.
  • Make the CI build use the same engine as your developers, so a resource that builds in Visual Studio cannot fail only on the build agent.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: Raheeb, Loade Driver, Dhero.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.