Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XamlReader.Load Failures #3206

Open
josvernon opened this issue Jun 30, 2020 · 6 comments
Open

XamlReader.Load Failures #3206

josvernon opened this issue Jun 30, 2020 · 6 comments
Labels
Investigate Requires further investigation by the WPF team.
Milestone

Comments

@josvernon
Copy link

josvernon commented Jun 30, 2020

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

@lindexi
Copy link
Contributor

lindexi commented Jul 1, 2020

What is your _documentExporter.PackageUri value ?

@josvernon
Copy link
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

@fabiant3 fabiant3 added this to the 5.0.0 milestone Jul 1, 2020
@josvernon
Copy link
Author

Do you need more from me?

@bgrainger
Copy link
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.

@miloush
Copy link
Contributor

miloush commented Jul 27, 2022

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

@bgrainger
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Investigate Requires further investigation by the WPF team.
Projects
None yet
Development

No branches or pull requests

8 participants