diff --git a/src/Avalonia.Base/Utilities/AvaloniaResourcesIndex.cs b/src/Avalonia.Base/Utilities/AvaloniaResourcesIndex.cs index 22e5c952bf..66024236da 100644 --- a/src/Avalonia.Base/Utilities/AvaloniaResourcesIndex.cs +++ b/src/Avalonia.Base/Utilities/AvaloniaResourcesIndex.cs @@ -4,6 +4,8 @@ using System.IO; using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Runtime.Serialization.Json; +using System.Xml.Linq; +using System.Linq; // ReSharper disable AssignNullToNotNullAttribute @@ -19,10 +21,20 @@ namespace Avalonia.Utilities { var ver = new BinaryReader(stream).ReadInt32(); if (ver > LastKnownVersion) - throw new Exception("Resources index format version is not known"); - var index = (AvaloniaResourcesIndex) - new DataContractSerializer(typeof(AvaloniaResourcesIndex)).ReadObject(stream); - return index.Entries; + throw new Exception("Resources index format version is not known"); + + var assetDoc = XDocument.Load(stream); + XNamespace assetNs = assetDoc.Root.Attribute("xmlns").Value; + List entries= + (from entry in assetDoc.Root.Element(assetNs + "Entries").Elements(assetNs + "AvaloniaResourcesIndexEntry") + select new AvaloniaResourcesIndexEntry + { + Path = entry.Element(assetNs + "Path").Value, + Offset = int.Parse(entry.Element(assetNs + "Offset").Value), + Size = int.Parse(entry.Element(assetNs + "Size").Value) + }).ToList(); + + return entries; } public static void Write(Stream stream, List entries) diff --git a/src/Markup/Avalonia.Markup.Xaml/AvaloniaXamlLoader.cs b/src/Markup/Avalonia.Markup.Xaml/AvaloniaXamlLoader.cs index a825deeae3..255357e027 100644 --- a/src/Markup/Avalonia.Markup.Xaml/AvaloniaXamlLoader.cs +++ b/src/Markup/Avalonia.Markup.Xaml/AvaloniaXamlLoader.cs @@ -13,6 +13,8 @@ using System.Reflection; using System.Runtime.Serialization; using System.Runtime.Serialization.Json; using System.Text; +using System.Xml.Linq; +using System.Linq; namespace Avalonia.Markup.Xaml { @@ -240,15 +242,21 @@ namespace Avalonia.Markup.Xaml { using (var xamlInfoStream = assetLocator.Open(xamlInfoUri)) { - var xamlInfo = (AvaloniaResourceXamlInfo)s_xamlInfoSerializer.ReadObject(xamlInfoStream); - if (xamlInfo.ClassToResourcePathIndex.TryGetValue(typeName, out var rv) == true) + var assetDoc = XDocument.Load(xamlInfoStream); + XNamespace assetNs = assetDoc.Root.Attribute("xmlns").Value; + XNamespace arrayNs = "http://schemas.microsoft.com/2003/10/Serialization/Arrays"; + Dictionary xamlInfo = + assetDoc.Root.Element(assetNs + "ClassToResourcePathIndex").Elements(arrayNs + "KeyValueOfstringstring") + .ToDictionary(entry =>entry.Element(arrayNs + "Key").Value, + entry => entry.Element(arrayNs + "Value").Value); + + if (xamlInfo.TryGetValue(typeName, out var rv) == true) { yield return new Uri($"avares://{asm}{rv}"); yield break; } } - } - + } yield return new Uri("resm:" + typeName + ".xaml?assembly=" + asm); yield return new Uri("resm:" + typeName + ".paml?assembly=" + asm);