dotnet / dotnet/wpf

XamlReader.Load Failures

Open
#3,206 6 comments 2 reactions 0 assignees View on GitHub
Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

I'm seeing issues with XamlReader.Load. They come via WPF but it may be that the root problem is actually in System.IO.Compression.

This is code that works in .NET 4.X but fails in .NET 5 Preview 5 & 6.

My code is much like this:

```
ParserContext parserContext = new ParserContext();
parserContext.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
parserContext.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml");
parserContext.BaseUri = new Uri("pack://" + _documentExporter.PackageUri.AbsoluteUri.Replace('/', ',') + "/");
Canvas canvas = (Canvas)XamlReader.Load(xmlStream, parserContext); // *** Exception Here ***
```

The exception that is thrown is XamlParseException but the inner exception is from System.IO.Compression,

```
System.Windows.Markup.XamlParseException: ''Failed to create a 'Color' from the text 'ContextColor /Resources/dc1d82f7-39c9-4539-a5fe-f0cffc7db8b6.icc 1,.81910431,.75130844,.63895631,.92820632'.' Line number '1' and line position '384'.'

InnerException
"Entries cannot be opened multiple times in Update mode."
Source "System.IO.Compression" string
at System.IO.Compression.ZipArchiveEntry.OpenInUpdateMode()
at System.IO.Compression.ZipArchiveEntry.Open()
at System.IO.Packaging.ZipStreamManager.Open(ZipArchiveEntry zipArchiveEntry, FileMode streamFileMode, FileAccess streamFileAccess)
at System.IO.Packaging.ZipPackagePart.GetStreamCore(FileMode streamFileMode, FileAccess streamFileAccess)
at System.IO.Packaging.PackagePart.GetStream(FileMode mode, FileAccess access)
at MS.Internal.IO.Packaging.PackagePartExtensions.GetSeekableStream(PackagePart packPart, FileMode mode, FileAccess access)
at System.IO.Packaging.PackWebResponse.CachedResponse.GetResponseStream()
at System.IO.Packaging.PackWebResponse.GetResponseStream()
at System.Windows.Media.ColorContext.Initialize(Uri profileUri, Boolean isStandardProfileUriNotFromUser)
at System.Windows.Media.Color.FromProfile(Uri profileUri)
at System.Windows.Media.Color.FromAValues(Single a, Single[] values, Uri profileUri)
at MS.Internal.Parsers.ParseContextColor(String trimmedColor, IFormatProvider formatProvider, ITypeDescriptorContext context)
at MS.Internal.Parsers.ParseColor(String color, IFormatProvider formatProvider, ITypeDescriptorContext context)
at System.Windows.Media.ColorConverter.ConvertFrom(ITypeDescriptorContext td, CultureInfo ci, Object value)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateObjectWithTypeConverter(ServiceProviderContext serviceContext, XamlValueConverter`1 ts, Object value)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateFromValue(ServiceProviderContext serviceContext, XamlValueConverter`1 ts, Object value, XamlMember property)
at System.Xaml.XamlObjectWriter.Logic_CreateFromValue(ObjectWriterContext ctx, XamlValueConverter`1 typeConverter, Object value, XamlMember property, String targetName, IAddLineInfo lineInfo)
```

Does this look like a known issue or does it need more detail?

Jos

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.