Skip to content

XamlReader.Load Failures #3206

Open
Open

Description

@josvernon

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

Activity

  1. lindexi commented on Jul 1, 2020

    @lindexi
    Member

    What is your _documentExporter.PackageUri value ?

  2. josvernon commented on Jul 1, 2020

    @josvernon
    Author

    The BaseUri property here is,

    pack://urn:x-websupergoo:xpspackage:f008dc38-9134-4dbd-8f3a-1d9c0b35b60c.xps/

    This matches a previous call to,

    PackageStore.AddPackage(PackageUri, _package);

    Using a PackageUri of,

    urn:x-websupergoo:xpspackage:f008dc38-9134-4dbd-8f3a-1d9c0b35b60c.xps

  3. added this to the 5.0.0 milestone on Jul 1, 2020
  4. josvernon commented on Jul 6, 2020

    @josvernon
    Author

    Do you need more from me?

  5. modified the milestones: 5.0.0, 7.0.0 on Aug 26, 2021
  6. bgrainger commented on Jul 23, 2022

    @bgrainger
    Contributor

    This is not the same cause as #6842. This crash can very likely be fixed by disposing profileStream after calling FromStream here:

    FromStream(profileStream, profileUri.AbsolutePath);
    }

    The bug is that ColorContext.Initialize leaks the Stream it opens.

  7. miloush commented on Jul 27, 2022

    @miloush
    Contributor

    @bgrainger good catch, do you want to make a PR?

  8. bgrainger commented on Jul 29, 2022

    @bgrainger
    Contributor

    I could, but I don't have a self-contained repro of the problem to verify the fix.

  9. added
    Investigate
    on Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Investigate

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions