dotnet / dotnet/wpf

BamlLocalizer throws exception reading BAML streams in .NET Core

Open
#7,245 6 comments 1 reaction 0 assignees View on GitHub
issue-type-tracking-external
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

* .NET Core Version: 6.0
* Win 10 22H2
* Does the bug reproduce also in WPF for .NET Framework 4.8?: No

**Problem description:** I migrated a .NET Framework 4.8 class library to .NET 6.0 using the .NET upgrade assistant. The library uses BamlLocalizer to extract BAML streams from .NET Framework Assemblies which use WPF. After the update, the library can't read BAML streams in .NET 6 assemblies any more as BamlLocalizer throws a FileNotFoundException.



**Actual behavior:** a FileNotFoundException upon instantiation of BamlLocalizer:
```
at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, RuntimeAssembly requestingAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, AssemblyLoadContext assemblyLoadContext) in /_/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs:line 347
at System.Reflection.Assembly.Load(String assemblyString) in /_/src/coreclr/System.Private.CoreLib/src/System/Reflection/Assembly.CoreCLR.cs:line 21
at System.Windows.Markup.BamlReader.ReadAssemblyInfoRecord()
at System.Windows.Markup.BamlReader.ReadNextRecord()
at System.Windows.Markup.BamlReader.Read()
at MS.Internal.Globalization.BamlResourceDeserializer.LoadBamlImp(Stream bamlSteam)
at System.Windows.Markup.Localizer.BamlLocalizer..ctor(Stream source, BamlLocalizabilityResolver resolver, TextReader comments)
```
**Expected behavior:** BamlLocalizer instantiates correctly and I am able to extract a BamlLocalizationDictionary from the BamlLocalizer instance.

**Minimal repro:** Create a .NET 6 project which loads an assembly containing BAML steams, and supply one of those streams when instantiating BamlLocalizer. An exception will be thrown.

I have read elsewhere that the LocBaml utility doesn't work either when upgraded to .NET 6 https://tomaskohl.com/code/2020-06-24/localizing-wpf-app-on-net-core/ and there is an open issue here to port it to .NET core here https://github.com/microsoft/WPF-Samples/issues/85 but it would be good to hear this from the horse's mouth as it were.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.