Assembly loading fails for Microsoft.CodeAnalysis.CSharp.resources with Culture=neutral on non-English systems
Problem
When using Roslyn 4.14.0 at runtime on systems with non-English culture settings, .NET attempts to load:
Microsoft.CodeAnalysis.CSharp.resources, Culture=neutral, PublicKeyToken=null
This assembly does not exist and should not be requested. The neutral (English) resources should be embedded in the main assembly.
Reproduction
csharp // On a system with German/French/etc Windows: using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Scripting; // This triggers the error: var script = CSharpScript.Create("1 + 1");```
Error
Could not load file or assembly 'Microsoft.CodeAnalysis.CSharp.resources, Culture=neutral, PublicKeyToken=null'. The system cannot find the specified file.
Root Cause
The NeutralResourcesLanguage assembly attribute is either:
- Missing
- Incorrectly configured without
UltimateResourceFallbackLocation.MainAssembly
This causes .NET's ResourceManager to search for a satellite assembly with neutral culture instead of using the resources embedded in the main assembly.
Proposed Fix
Option 1: Add/Fix Assembly Attribute (Recommended)
In src/Compilers/CSharp/Portable/CSharpResources.Designer.cs or assembly-level file:
csharp [assembly: NeutralResourcesLanguage("en", UltimateResourceFallbackLocation.MainAssembly)]
Apply the same to:
-
Microsoft.CodeAnalysis -
Microsoft.CodeAnalysis.CSharp.Workspaces -
Microsoft.CodeAnalysis.CSharp.Scripting -
Microsoft.CodeAnalysis.VisualBasic(and related) -
Microsoft.CodeAnalysis.Workspaces -
Microsoft.CodeAnalysis.Scripting
Option 2: MSBuild Configuration
Ensure .csproj files specify:
<SatelliteResourceLanguages>en de;es;fr;it;ja;ko;pl;pt-BR;ru;tr;zh-Hans;zh-Hant</SatelliteResourceLanguages>
(Note: en is deliberately excluded to keep it in the main assembly)
Workaround
Users currently need to add this to their application startup:
csharp AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => { var name = new AssemblyName(args.Name); if (name.Name?.Contains("Microsoft.CodeAnalysis") == true && name.Name.EndsWith(".resources")) { return Assembly.Load(name.Name.Replace(".resources", "")); } return null; };
Or add to their .csproj:
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
Impact
This affects any application using Roslyn at runtime on non-English systems:
- Scripting scenarios
- Runtime code generation frameworks (e.g., WolverineFx, NServiceBus)
- Code analyzers
- IDE extensions
Environment
- Roslyn: 4.14.0 (and likely earlier versions)
- .NET: 8.0, 9.0
- OS: Windows with non-English culture settings
References
Thanks for taking the time to report this issue.
I cannot repro from the provided information. Specifically, I've set my Windows language to Czech and ran this file-based app:
#:package [email protected]
using Microsoft.CodeAnalysis.CSharp.Scripting;
var script = CSharpScript.Create("1 + 1");
var result = await script.RunAsync();
Console.WriteLine(result.ReturnValue);
I got no errors.
Can you provide a complete minimal repro?
I'm also running into this issue, when referencing 4.14.0 nothing from that assembly (things like DiagnosticDescriptor) can be resolved.
Can you provide a minimal reproducible example so we can investigate further? A complog might be ideal.