简体   繁体   中英

External DLL running in Unity behaves differently then when run in Visual Studio

I'm writing some C# to represent nodes, edges, and graphs. As part of that code library, I have some classes to write/read graphs to/from xml. I have a test, in Visual Studio, that creates a graph, writes it to xml, and then reconstructs the graph back from xml. This seems to work fine. Next, I wanted to visualize the graphs inside Unity. I compiled my graph code into a .dll with .net 3.5 and imported it into Unity. Unity recognizes the .dll, and throws no errors trying to run it. However, when I try to load the same xml file as before, the xml parser breaks and fails to load the graph.

Does anyone have any idea what might be causing this? Back in Visual Studio, I tried swapping out the .net libraries for mono libraries guessing that could be a problem, but it still worked fine. Visual studio works great, but Unity is throwing up.

The xml file that I am trying to parse looks like...

    <?xml version="1.0" encoding="utf-8"?>
<graph>
    <time time="0">
        <newNodes>
            <node type="Person" id="£*6O▒$5M¥▒(6»S}_-03+" />
            <node type="Person" id="JÇ$T!-%=▒¾4IW┼RR¿¿G%" />
            <node type="Person" id="X2¿+2B#¥V,ß«88!9-D;)" />
        </newNodes>
        <newEdges>
            <edge type="Knows" id="_«C~F/¾0¾€`J]¾F%†9╟▒" from="£*6O▒$5M¥▒(6»S}_-03+" to="JÇ$T!-%=▒¾4IW┼RR¿¿G%" />
            <edge type="Knows" id="Ð}Ø4┴~Ð;┴/$£YHߣH,P(" from="JÇ$T!-%=▒¾4IW┼RR¿¿G%" to="£*6O▒$5M¥▒(6»S}_-03+" />
            <edge type="Knows" id="J;R`߆`VH9*,J†1(5XÇ/" from="£*6O▒$5M¥▒(6»S}_-03+" to="X2¿+2B#¥V,ß«88!9-D;)" />
            <edge type="Knows" id="¾,┴N!S'@\N{?┴3£D;@‡$" from="X2¿+2B#¥V,ß«88!9-D;)" to="£*6O▒$5M¥▒(6»S}_-03+" />
            <edge type="Knows" id="*6)Ð7$Z¿†*RXCY½3I]X!" from="JÇ$T!-%=▒¾4IW┼RR¿¿G%" to="X2¿+2B#¥V,ß«88!9-D;)" />
            <edge type="Knows" id="┼¼~CØ0;N5C[X+OV«Ø!7]" from="X2¿+2B#¥V,ß«88!9-D;)" to="JÇ$T!-%=▒¾4IW┼RR¿¿G%" />
        </newEdges>
        <oldNodes />
        <oldEdges />
    </time>
    <time time="1">
        <newNodes>
            <node type="Person" id="+E%_WØ¿V_J7N-|]75«W!" />
        </newNodes>
        <newEdges>
            <edge type="Knows" id="Ç┼/»U.¾9+YQ8}╟C=#CV*" from="£*6O▒$5M¥▒(6»S}_-03+" to="+E%_WØ¿V_J7N-|]75«W!" />
            <edge type="Knows" id="€'T[┼‡/¿~8=Ç`Ç3]$R\*" from="+E%_WØ¿V_J7N-|]75«W!" to="£*6O▒$5M¥▒(6»S}_-03+" />
        </newEdges>
        <oldNodes />
        <oldEdges />
    </time>
    <time time="2">
        <newNodes>
            <node type="Person" id="]?:ER#349A@.%PXG8V§," />
        </newNodes>
        <newEdges>
            <edge type="Knows" id="Ç~-EY'@26@▒~ØU^I½1_/" from="JÇ$T!-%=▒¾4IW┼RR¿¿G%" to="+E%_WØ¿V_J7N-|]75«W!" />
        </newEdges>
        <oldNodes />
        <oldEdges />
    </time>
    <time time="3">
        <newNodes />
        <newEdges>
            <edge type="Knows" id="§/«;~'2H,}KÐ8»•ÐVMÐ{" from="+E%_WØ¿V_J7N-|]75«W!" to="]?:ER#349A@.%PXG8V§," />
        </newEdges>
        <oldNodes />
        <oldEdges />
    </time>
</graph>

In Unity, the parser is failing to read all of the nodes under newNodes This little chuck of code is supposed to read them all in. In Visual Studio, it works great, and all three newNodes in the first time element are parsed. In Unity, only the first one is.

reader.ReadToFollowing(XmlConstants.NEW_NODES);
if (reader.ReadToDescendant(XmlConstants.NODE))
{
     do
     {
           Node node = XmlHelper.readNode(reader, nodeTypes);
           g.add(node, time);
           Slog.WriteLn("Loaded node " + node.Sguid);

     } while (reader.ReadToNextSibling(XmlConstants.NODE));
}

The code inside the function XmlHelper.readNode just does calls to reader.MoveToAttribute() and reader.Value

I am pretty frazzled by this problem. Any insight would be greatly appreciated. Thanks!

Ah ha. I was trying to figure this out ever since yesterday, and I think I just found the answer.

I added the command

reader.MoveToElement()

after I read the attributes. That solved it. I guess reader.MoveToAttribute() was jumping ahead and getting to an attribute later on, and that was throwing the rest of the traversal off.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM