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

Unable to view baml files in WF4 dll's resources #298

Closed
rebulanyum opened this issue Dec 6, 2011 · 1 comment
Closed

Unable to view baml files in WF4 dll's resources #298

rebulanyum opened this issue Dec 6, 2011 · 1 comment

Comments

@rebulanyum
Copy link

I can not view the baml files in System.Activities.Core.Presentation.dll's resources. Especially, the ones that are ActivityDesigner's. An example resource key for your trial is "system/activities/core/presentation/ifelsedesigner.baml".

When I try to view the baml resource it's giving me the following exception text:

System.NotSupportedException: Type 'System.Activities.Presentation.ActivityDesigner, System.Activities.Presentation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' not found!
at Ricciolo.StylesExplorer.MarkupReflection.XmlBamlReader.GetKnownTypeDeclarationByName(String name)
at Ricciolo.StylesExplorer.MarkupReflection.XmlBamlReader.ReadElementStart()
at Ricciolo.StylesExplorer.MarkupReflection.XmlBamlReader.ProcessNext()
at Ricciolo.StylesExplorer.MarkupReflection.XmlBamlReader.ReadInternal()
at Ricciolo.StylesExplorer.MarkupReflection.XmlBamlReader.Read()
at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
at ILSpy.BamlDecompiler.BamlResourceEntryNode.LoadIntoDocument(IAssemblyResolver resolver, AssemblyDefinition asm, Stream stream)
at ILSpy.BamlDecompiler.BamlResourceEntryNode.LoadBaml(AvalonEditTextOutput output)
at ILSpy.BamlDecompiler.BamlResourceEntryNode.<>c__DisplayClass3.b__1()

However, System.Activities.Presentation.dll was already included in ILSpy and it is resolved successfully.

@rebulanyum
Copy link
Author

Okay! I found my own way to get baml files to convert xaml files:

  1. Add System.Activities.Presentation reference to the ILSpy.BamlDecompiler project references.
  2. In the KnownInfo.cs make the following changes:
    a. In the void LoadKnownAssemblies40() method:
    KnownAssemblyTable = new string[5]; -> KnownAssemblyTable = new string[6];
    KnownAssemblyTable[5] = "System.Activities.Presentation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
    b. In the public KnownInfo(ITypeResolver resolver) method:
    KnownTypeTable = new TypeDeclaration[760]; -> KnownTypeTable = new TypeDeclaration[762];
    KnownTypeTable[0x2f8] = new TypeDeclaration(resolver, "ActivityDesigner", "System.Activities.Presentation", 5);
    KnownTypeTable[0x2f9] = new TypeDeclaration(resolver, "WorkflowViewElement", "System.Activities.Presentation", 5);

This should be enough though; however, it will still not going to work for xaml files containing "Grid"; because it gives the following error:
System.Xml.XmlException: 'Name' is a duplicate attribute name.
at System.Xml.XmlWellFormedWriter.AddAttribute(String prefix, String localName, String namespaceName)
at System.Xml.XmlWellFormedWriter.WriteStartAttribute(String prefix, String localName, String namespaceName)
at System.Xml.Linq.ElementWriter.WriteStartElement(XElement e)
at System.Xml.Linq.ElementWriter.WriteElement(XElement e)
at System.Xml.Linq.XElement.WriteTo(XmlWriter writer)
at System.Xml.Linq.XContainer.WriteContentTo(XmlWriter writer)
at System.Xml.Linq.XNode.GetXmlString(SaveOptions o)
at System.Xml.Linq.XNode.ToString()
at ILSpy.BamlDecompiler.BamlResourceEntryNode.LoadBaml(AvalonEditTextOutput output) in G:\BTAKADEMI\PortableApplications\IL Spy Source Code\ILSpy.BamlDecompiler\BamlResourceEntryNode.cs:line 68
at ILSpy.BamlDecompiler.BamlResourceEntryNode.<>c__DisplayClass3.b__1() in G:\BTAKADEMI\PortableApplications\IL Spy Source Code\ILSpy.BamlDecompiler\BamlResourceEntryNode.cs:line 36

If you get this error then you should also do the following;

  1. In the BamlResourceEntryNode.cs file change the "bool LoadBaml(AvalonEditTextOutput output)" method as below:
    bool LoadBaml(AvalonEditTextOutput output)
    {
    var asm = this.Ancestors().OfType().FirstOrDefault().LoadedAssembly;
    Data.Position = 0;
    XDocument xamlDocument = LoadIntoDocument(asm.GetAssemblyResolver(), asm.AssemblyDefinition, Data);
    if (asm.AssemblyDefinition.FullName == "System.Activities.Core.Presentation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")
    {
    XmlReader reader = xamlDocument.CreateReader();
    reader.Settings.ValidationType = ValidationType.None;
    //You may change the file name "aaa.xaml" as you like...
    XmlTextWriter writer = new XmlTextWriter("aaa.xaml", System.Text.Encoding.UTF8);
    writer.Formatting = Formatting.Indented;
    while (reader.Read())
    {
    writer.WriteNode(reader, true);
    }
    writer.Flush();
    writer.Close();
    reader.Close();
    }
    output.Write(xamlDocument.ToString());
    return true;
    }

Finally this is definately working B~).

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants