msbuild: Non-string resources require the System.Resources.Extensions assembly at runtime, but it was not found in this project's references.
This issue has been reported before, I believe here : https://github.com/dotnet/msbuild/issues/2221
However unlike presented in this thread, it still appears past versions 16.3+ of MSBuild. I’m personally running Microsoft (R) Build Engine version 16.7.0+7fb82e5b2 for .NET
Issue Description
My windows form app can be built successfully using Visual Studio 2019, but:
- Cannot be built with dotnet msbuild from command line
- Cannot be built with dotnet publish from command line
- Cannot be built with “C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe” from command line.
Steps to Reproduce
Here are the arguments I used for all three of them:
-target:Publish /p:Configuration=Release /p:GenerateResourceUsePreserializedResources=True /p:OutDir="../Build"
Expected Behavior
The app builds successfully to the target folder.
Actual Behavior
All three of them output some version of the following text:
error MSB3822: Non-string resources require the System.Resources.Extensions assembly at runtime, but it was not found in this project's references. [my.csproj]
However, none of my .resx in my windows form project have any image. Only one contains non-string content, of the following nature:
The other .resx i have seems to be doing fine without any non-string resource, but not this one - deleting these elements lead to malfunction.
Moreover, if I do try to embed the “System.Resources.Extensions” that is being mentioned here, my app does build, but said window cannot be opened.
<PackageReference Include="System.Resources.Extensions" Version="4.7.1" />

Analysis
Tried every version of System.Resources.Extensions from the top, the application seems to work correctly with <PackageReference Include="System.Resources.Extensions" Version="4.6.0" /> for reasons unknown to me.
This is still not a good solution. I feel like I shouldn’t have to include this undesired library.
Versions & Configurations
Microsoft (R) Build Engine version 16.7.0+7fb82e5b2 for .NET
Windows 10 running Microsoft Visual Studio 2019
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 29 (17 by maintainers)
Hi used NuGet Package Manager GUI in Visual Studio 2022.
@DaveCousineau
This isn’t correct; the package reference is required when building for .NET 4.
There are two aspects of non-string resources:
The problems here arise because of differences in serialization/deserialization between .NET Core/5.0+ and .NET Framework 4.x.
In .NET Framework 4.x, non-string resources are serialized and deserialized using
BinaryFormatter, which cannot be made secure.In .NET Core/5.0+, we use different techniques. But that means that we cannot write .NET 4.x-compatible resources from a .NET 5.0 build process, because we don’t use BinaryFormatter. We can easily serialize resources using the new serialization techniques, but they can’t be read in the usual way at runtime.
Fortunately, the new more secure deserialization techniques can work on .NET 4.x with the addition of a new assembly that teaches the older framework how to handle them. That’s why the new reference is required when targeting .NET 4.x from a
dotnet buildprocess.I must have found myself here a dozen times or more by now.
I think there is a bug when building using
dotnetwhere this error is generated even when building a .NET Framework project.My command is:
and I have conditional
ItemGroupandPropertyGrouptags that have the necessary tags:<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>and
<PackageReference Include="System.Resources.Extensions" Version="4.7.0" />when building for .netcoreapp3.1
but I get the error even when building for .NET 4, where these shouldn’t be required afaik (and in fact, can’t be used I think).