0

I am trying to debug a Revit design automation bundle like in this tutorial:

https://www.youtube.com/watch?v=i0LJ9JOpKMQ

using these repositories:

https://github.com/Autodesk-Forge/design.automation-csharp-revit.local.debug.tool https://github.com/Autodesk-Forge/learn.forge.designautomation

I am getting this error:

enter image description here

System.Xml.XmlException HResult=0x80131940 Message=There is no Unicode byte order mark. Cannot switch to Unicode. Source=System.Xml StackTrace:
 at System.Xml.XmlTextReaderImpl.Throw(Exception e)
 at System.Xml.XmlTextReaderImpl.CheckEncoding(String newEncodingName)
 at System.Xml.XmlTextReaderImpl.ParseXmlDeclaration(Boolean isTextDecl) at System.Xml.XmlTextReaderImpl.Read()
 at System.Xml.XmlReader.MoveToContent()
 at System.Xml.Linq.XElement.Load(XmlReader reader, LoadOptions options)
 at System.Xml.Linq.XElement.Load(String uri, LoadOptions options)
 at DesignAutomationHandler.DesignAutomationHandlerApp.Execute(ExternalCommandData commandData, String& message, ElementSet elements) in C:\Users\CALS079313\source\repos\debug_design_automation_addin\design.automation-csharp-revit.local.debug.tool-master\DesignAutomationHandler.cs:line 22
 at apiManagedExecuteCommand(AString* assemblyName, AString* className, AString* vendorDescription, MFCApp* pMFCApp, DBView* pDBView, AString* message, Set<ElementId,std::less<ElementId>,tnallc<ElementId> >* ids, Map<AString,AString,std::less<AString>,tnallc<std::pair<AString const ,AString> > >* data, AString* exceptionName, AString* exceptionMessage)

I tried to change the code

XElement addin = XElement.Load(file);

to this:

XElement addin;
using (FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read))
{
    XmlReaderSettings settings = new XmlReaderSettings { CheckCharacters = false };
    using (XmlReader reader = XmlReader.Create(stream, settings))
    {
        addin = XElement.Load(reader);
    }
}

but nothing, I got the same error...

I tried to do the same steps from the tutorial but got that error.

Rahul Bhobe
  • 4,165
  • 4
  • 17
  • 32

2 Answers2

0

Your error seems to be with the XML file you are trying to parse. This is likely nothing to do with Revit. To isolate the problem, try to parse the same file in an independent program outside of Revit addin.

Also see the answer if this helps.

Rahul Bhobe
  • 4,165
  • 4
  • 17
  • 32
  • Probably, check the `Autodesk.RobotStructuralAnalysysLink.Application.addin` in `C:\ProgramData\Autodesk\Revit\Addins\20xx`, and then fix the XML header from to – Eason Kang May 02 '23 at 03:17
0

I created this function:

        private XElement LoadXmlWithInvalidChars(string filePath)
        {
            using (StreamReader sr = new StreamReader(filePath))
            {
                string xmlContent = sr.ReadToEnd();
                xmlContent = Regex.Replace(xmlContent, @"[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD\u10000-\u10FFFF]", "");
                return XElement.Parse(xmlContent);
            }
        }

and I changed this line :

XElement addin = XElement.Load(file);

for this :

XElement addin = LoadXmlWithInvalidChars(file);

and now is working fine.