Closed wieslawsoltes closed 7 years ago
@wieslawsoltes Ok, I've tried but I can't seem to replicate this issue. Is this still occurring for you?
@cwensley
Yes I still get the exception and its easily reproducible in my app. I'm using version 0.15.0 from NuGet and latest appveyor build.
This is my serializer code:
https://github.com/wieslawsoltes/Core2D/tree/master/src/Serializer.Xaml
This is my app:
https://github.com/wieslawsoltes/Core2D/tree/master/src/Core2D.Wpf
Video how to reproduce:
@cwensley Tested with version 0.16.0
Core2D.Avalonia.Direct2D.exe Error: 0 : Unresolved object reference 'AND' was found
w Portable.Xaml.XamlObjectWriterInternal.ResolvePendingReferences()
w Portable.Xaml.XamlObjectWriterInternal.OnWriteEndObject()
w Portable.Xaml.XamlWriterInternalBase.WriteEndObject()
w Portable.Xaml.XamlWriterInternalBase.CloseAll()
w Portable.Xaml.XamlObjectWriter.Dispose(Boolean disposing)
w Portable.Xaml.XamlWriter.System.IDisposable.Dispose()
w Serializer.Xaml.CoreXamlReader.Load(XamlXmlReader reader)
w Serializer.Xaml.CoreXamlReader.Load(TextReader textReader)
w Serializer.Xaml.CoreXamlSerializer.Deserialize[T](String xaml)
w Serializer.Xaml.PortableXamlSerializer.Core2D.Interfaces.IXamlSerializer.Deserialize[T](String xaml)
w Core2D.Editor.ProjectEditor.OnImportXamlString(String xaml)
w Core2D.Editor.ProjectEditor.OnImportXaml(String path)
Updated Xaml for latest version of Core2D https://gist.github.com/wieslawsoltes/dcc5ee153d1bdd8d89a654ac13750b2f
This may be related to how the Name
property is written by Portable.Xaml
as cs:Name="AND"
:
https://gist.github.com/wieslawsoltes/dcc5ee153d1bdd8d89a654ac13750b2f#file-and-xaml-L1
https://github.com/wieslawsoltes/Core2D/blob/master/src/Serializer.Xaml/CoreAttributeProvider.cs#L24
https://github.com/wieslawsoltes/Core2D/blob/master/src/Core2D/Attributes/NameAttribute.cs#L11
https://github.com/wieslawsoltes/Core2D/blob/master/src/Core2D/Shape/BaseShape.cs#L42
https://github.com/wieslawsoltes/Core2D/blob/master/src/Core2D/Shapes/XGroup.cs#L16
@cwensley I have created minimal reproduction for this issue here (standalone .Net Core console app): https://github.com/wieslawsoltes/Core2D/tree/PortableXamlIssue20/apps/PortableXamlRepro
@wieslawsoltes, awesome thanks for putting together a more minimal reproduction! I'll try to get this down to "unit test size", e.g. the most minimal to repro the issue without dependencies so I can add a unit test for it.
I think you might be right in that the namespaces that are causing the issue here. It's pretty odd that it's using a different namespace for the properties of the class and it could be something to do with how it resolves base class property namespaces. This points mainly to a writer problem where I was looking at the reader before.
My guess is that it should be writing the properties without a namespace prefix here, which may end up fixing loading. However, I'll also test to see if System.Xaml can handle this particular situation, and if so, the reader should be updated for that too.
Ok, this should hopefully be fixed! Thanks for the pointer on the namespaces as Portable.Xaml was writing invalid xaml in that case. All attributes and elements of the parent element should not have a namespace defined even if they are from a base class in a different namespace.
If you have time, I'd love it if you can give it a go and see if it works for your app.
@cwensley Tested merged fixes and generated xaml is better: https://gist.github.com/wieslawsoltes/38b21783d88dba1e0c022599011a9131 and this exception is gone.
But got another issue reported here https://github.com/cwensley/Portable.Xaml/issues/55
This exception is thrown when trying to load Xaml that was written automatically by
Portable.Xaml
from the object graph.Xaml to reproduce: