Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6144265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:37:33+00:00 2026-05-23T18:37:33+00:00

Sorry for the long post the output is quite large. Recently i started testing

  • 0

Sorry for the long post the output is quite large. Recently i started testing out C# and WPF and im really enjoying the creativity and freedom it offers for visual effects. I started converting the functions of an application i am currently working on into a DLL mostly so i don’t have to redo the work I have already done and because i want to learn and gain some experience in writing DLL’s and using interop.

Every function so far has only had a single input or output. However my final two functions (Which take a list of filenames and the hash of the file its self and for each file and hash saves it to an xml file) aren’t working so well for me. Im getting output but not in the form i want it so obviously my logic is flawed but im not sure how to correct it.

The functions are very similar the only difference is the one creates a brand new xml while the second updates an existing xml. They both worked perfectly before as straight C++/CLI functions however now that i need to use them in C# i have to put them in iterations so they work for each of the files and their hashes displayed in the lists.

Below is one of the functions in the Dll where i have now replaced the previous hard-coded variables which would have been listBox2->Items[x]->ToString() as varibales such as CurrentFile which are now defined in the .cs.

public: void XMLUpdate(String^ Location, int NumberItems, String^ ProjectName, 
                String^ ProjectTC, String^ CurrentFile, String^ CurrentHash)
    {
        try
        {
            XmlDocument^ XmlDoc = gcnew XmlDocument();
            XmlDoc->Load(Location);

            XmlElement^ NewProject = XmlDoc->CreateElement("Project");
            NewProject->SetAttribute("Name", ProjectName);
            XmlDoc->DocumentElement->AppendChild(NewProject);

            XmlElement^ NewTestCycle =  XmlDoc->CreateElement("TestCycle");
            NewTestCycle->SetAttribute("Number", ProjectTC);
            NewProject->AppendChild(NewTestCycle);

            XmlElement^ NewFile = XmlDoc->CreateElement("Files");
            NewTestCycle->AppendChild(NewFile);

            for (int x = 0; x < NumberItems; ++x)
            {
                String^ FileName = CurrentFile;
                String^ Hash = CurrentHash;

                XmlElement^ NewFileName = XmlDoc->CreateElement("FileName");
                NewFileName->SetAttribute("File", FileName);
                NewFile->AppendChild(NewFileName);

                XmlElement^ NewHashCode = XmlDoc->CreateElement("HashCode");
                NewHashCode->SetAttribute("Code", Hash);
                NewFile->AppendChild(NewHashCode);
            }

            XmlDoc->Save(Location);
            return;
        }
        catch(Exception^)
        {
            return;
        }           
     }

Here is the call for the method from the dll in my WPF form:

        private void button2_Click(object sender, RoutedEventArgs e)
    {
        DllTest.Funtions Functions = new DllTest.Funtions();

        String Name = textBox1.Text;
        String TC = textBox2.Text;
        String Location = "C:\\Users\\brandonm\\Desktop\\Backup\\XML\\test1.xml";
        int Number = listBox2.Items.Count;

        for (int x = 0; x < listBox2.Items.Count; ++x)
        {
            Functions.XMLUpdate(Location, Number, TC, Name, listBox2.Items[x].ToString(),
                    listBox3.Items[x].ToString());
        }

    }

Output is only taking the last item in the list and duplicating it by the number in the list in this case the list had 3 filenames and the second list had 3 hashes here is an example:

<?xml version="1.0" encoding="utf-8"?>
<Project Name="New">
  <TestCycle Number="1">
  <Files>
    <FileName
      File="C:\Users\brandonm\Documents\Visual Studio 2008\Projects\WpfDllTest\WpfDllTest\bin\x86\Release\WpfDllTest.vshost.exe" />
    <HashCode
      Code="76-7B-6F-37-0D-3A-F2-F4-32-D1-70-A5-75-3B-DE-95" />
    <FileName
      File="C:\Users\brandonm\Documents\Visual Studio 2008\Projects\WpfDllTest\WpfDllTest\bin\x86\Release\WpfDllTest.vshost.exe" />
    <HashCode
      Code="76-7B-6F-37-0D-3A-F2-F4-32-D1-70-A5-75-3B-DE-95" />
    <FileName
      File="C:\Users\brandonm\Documents\Visual Studio 2008\Projects\WpfDllTest\WpfDllTest\bin\x86\Release\WpfDllTest.vshost.exe" />
    <HashCode
      Code="76-7B-6F-37-0D-3A-F2-F4-32-D1-70-A5-75-3B-DE-95" />
  </Files>
    </TestCycle>
  </Project>
</Project>

So here is the second function that updates an exisitng XML and gives me completely different output, still incorrect, from the output in the new function.

public: void XMLNew(String^ Path, String^ ProjectName, String^ TCNumber, int NumberItems, 
                    array^ CurrentFile, array^ CurrentHashCode)
        {
            try
            {
                XmlWriterSettings^ settings = gcnew XmlWriterSettings();
                settings->NewLineOnAttributes = true;
                settings->Indent = true;
                settings->Encoding->UTF8;

                XmlWriter^ Writer = XmlTextWriter::Create(Path, settings);
                Writer->WriteStartDocument();

                Writer->WriteStartElement("Projects");

                Writer->WriteStartElement("Project");
                Writer->WriteAttributeString("Name", ProjectName);

                Writer->WriteStartElement("TestCycle");
                Writer->WriteAttributeString("Number", TCNumber);

                Writer->WriteStartElement("Files");

                for (int x = 0; x WriteStartElement("FileName");
                    Writer->WriteAttributeString("File", FileName);

                    //End the FileName element
                    Writer->WriteEndElement();

                    Writer->WriteStartElement("HashCode");
                    Writer->WriteAttributeString("Code", Hash);

                    //End the HashCode element
                    Writer->WriteEndElement();
                }

                //End Element for File
                Writer->WriteEndElement();

                //End Element for TestCycle
                Writer->WriteEndElement();

                //End element for Project
                Writer->WriteEndElement();

                //End element for Projects
                Writer->WriteEndElement();

                Writer->Flush();
                Writer->Close();
            }
            catch(Exception^)
            {
                return;
            }           
        }

The method call:

private void button4_Click(object sender, RoutedEventArgs e)
    {
        DllTest.Funtions Functions = new DllTest.Funtions();

        String Name = textBox1.Text;
        String TC = textBox2.Text;
        String path = "C:\\Users\\brandonm\\Desktop\\Backup\\XML\\test1.xml";
        int Number = listBox2.Items.Count;

        for (int x = 0; x < listBox2.Items.Count; ++x)
        {
            Functions.XMLNew(path, Name, TC, Number, listBox2.Items[x].ToString(),
                listBox3.Items[x].ToString());
        }
    }

the output for this one which is closer to what i need since it using all of the items in the list but its duplicating them in every element i only want a single new element with the new files and their hashes.

    <?xml version="1.0" encoding="utf-8"?>
    <Project Name="New">
    <TestCycle Number="1">
      <Files>
        <FileName File="C:\Users\brandonm\Documents\Visual Studio 2008\Projects\WpfDllTest\WpfDllTest\bin\x86\Release\WpfDllTest.vshost.exe" />
        <HashCode Code="76-7B-6F-37-0D-3A-F2-F4-32-D1-70-A5-75-3B-DE-95" />
        <FileName File="C:\Users\brandonm\Documents\Visual Studio 2008\Projects\WpfDllTest\WpfDllTest\bin\x86\Release\WpfDllTest.vshost.exe" />
        <HashCode Code="76-7B-6F-37-0D-3A-F2-F4-32-D1-70-A5-75-3B-DE-95" />
        <FileName File="C:\Users\brandonm\Documents\Visual Studio 2008\Projects\WpfDllTest\WpfDllTest\bin\x86\Release\WpfDllTest.vshost.exe" />
        <HashCode Code="76-7B-6F-37-0D-3A-F2-F4-32-D1-70-A5-75-3B-DE-95" />
      </Files>
    </TestCycle>
  </Project>
  <Project Name="2">
    <TestCycle Number="New">
      <Files>
        <FileName File="C:\Users\brandonm\Documents\Visual Studio 2008\Projects\WpfDllTest\WpfDllTest\bin\x86\Release\DllTest.dll" />
        <HashCode Code="0E-C2-B1-A4-3C-D8-C0-51-96-0F-FF-19-BC-3A-CE-AC" />
        <FileName File="C:\Users\brandonm\Documents\Visual Studio 2008\Projects\WpfDllTest\WpfDllTest\bin\x86\Release\DllTest.dll" />
        <HashCode Code="0E-C2-B1-A4-3C-D8-C0-51-96-0F-FF-19-BC-3A-CE-AC" />
        <FileName File="C:\Users\brandonm\Documents\Visual Studio 2008\Projects\WpfDllTest\WpfDllTest\bin\x86\Release\DllTest.dll" />
        <HashCode Code="0E-C2-B1-A4-3C-D8-C0-51-96-0F-FF-19-BC-3A-CE-AC" />
      </Files>
    </TestCycle>
  </Project>
  <Project Name="2">
    <TestCycle Number="New">
      <Files>
        <FileName File="C:\Users\brandonm\Documents\Visual Studio 2008\Projects\WpfDllTest\WpfDllTest\bin\x86\Release\WpfDllTest.exe" />
        <HashCode Code="C0-7C-51-C2-92-70-1B-11-E0-26-6D-D5-B8-79-12-0D" />
        <FileName File="C:\Users\brandonm\Documents\Visual Studio 2008\Projects\WpfDllTest\WpfDllTest\bin\x86\Release\WpfDllTest.exe" />
        <HashCode Code="C0-7C-51-C2-92-70-1B-11-E0-26-6D-D5-B8-79-12-0D" />
        <FileName File="C:\Users\brandonm\Documents\Visual Studio 2008\Projects\WpfDllTest\WpfDllTest\bin\x86\Release\WpfDllTest.exe" />
        <HashCode Code="C0-7C-51-C2-92-70-1B-11-E0-26-6D-D5-B8-79-12-0D" />
      </Files>
    </TestCycle>
  </Project>
  <Project Name="2">
    <TestCycle Number="New">
      <Files>
        <FileName File="C:\Users\brandonm\Documents\Visual Studio 2008\Projects\WpfDllTest\WpfDllTest\bin\x86\Release\WpfDllTest.vshost.exe" />
        <HashCode Code="76-7B-6F-37-0D-3A-F2-F4-32-D1-70-A5-75-3B-DE-95" />
        <FileName File="C:\Users\brandonm\Documents\Visual Studio 2008\Projects\WpfDllTest\WpfDllTest\bin\x86\Release\WpfDllTest.vshost.exe" />
        <HashCode Code="76-7B-6F-37-0D-3A-F2-F4-32-D1-70-A5-75-3B-DE-95" />
        <FileName File="C:\Users\brandonm\Documents\Visual Studio 2008\Projects\WpfDllTest\WpfDllTest\bin\x86\Release\WpfDllTest.vshost.exe" />
        <HashCode Code="76-7B-6F-37-0D-3A-F2-F4-32-D1-70-A5-75-3B-DE-95" />
      </Files>
    </TestCycle>
  </Project>
    </Project>

So now you can see the problem i have loops within loops causing output that repeats its self. I can post an example of my output if you need.

But for the life of me i cannot get around it, i have tried splitting up the functions in to parts but i get errors trying to do that.

Can anyone see a way around this? I only want to completely rewrite the methods in c# if its my only alternative since i want all the main functions in the dll. Please dont bash me for my lack of knowledge im still learning and testing alot of things for the first time.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:37:33+00:00Added an answer on May 23, 2026 at 6:37 pm

    Solved the issue 🙂

    I placed the items in the lists into an array and then past them in that way.

    The Code as follows is for the one function but they both can use the same identical changes in structure.

    DLL method to create a new xml the following lines changed in the DLL:
    Complete:

    public: void XMLUpdate(String^ Location, int NumberItems, String^ ProjectName, 
                    String^ ProjectTC, array<String^>^ CurrentFile, array<String^>^ CurrentHash)
        {
            try
            {
                XmlDocument^ XmlDoc = gcnew XmlDocument();
                XmlDoc->Load(Location);
    
                XmlElement^ NewProject = XmlDoc->CreateElement("Project");
                NewProject->SetAttribute("Name", ProjectName);
                XmlDoc->DocumentElement->AppendChild(NewProject);
    
                XmlElement^ NewTestCycle =  XmlDoc->CreateElement("TestCycle");
                NewTestCycle->SetAttribute("Number", ProjectTC);
                NewProject->AppendChild(NewTestCycle);
    
                XmlElement^ NewFile = XmlDoc->CreateElement("Files");
                NewTestCycle->AppendChild(NewFile);
    
                for (int x = 0; x < NumberItems; ++x)
                {
                    String^ FileName = CurrentFile[x];
                    String^ Hash = CurrentHash[x];
    
                    XmlElement^ NewFileName = XmlDoc->CreateElement("FileName");
                    NewFileName->SetAttribute("File", FileName);
                    NewFile->AppendChild(NewFileName);
    
                    XmlElement^ NewHashCode = XmlDoc->CreateElement("HashCode");
                    NewHashCode->SetAttribute("Code", Hash);
                    NewFile->AppendChild(NewHashCode);
                }
    
                XmlDoc->Save(Location);
                return;
            }
            catch(Exception^)
            {
                return;
            }           
         }
    

    What changed:

    public: void XMLNew(String^ Path, String^ ProjectName, String^ TCNumber, int NumberItems, array<String^>^ CurrentFile, array<String^>^ CurrentHashCode)
    

    and

    for (int x = 0; x < NumberItems; ++x)
    {
        String^ FileName = CurrentFile[x];
        String^ Hash = CurrentHashCode[x];
    

    And then the calling function changed to this in C#:

    private void button4_Click(object sender, RoutedEventArgs e)
    {
        DllTest.Funtions Functions = new DllTest.Funtions();
        String Name = textBox1.Text;
                String TC = textBox2.Text;
                String path = "C:\\Users\\brandonm\\Desktop\\Backup\\XML\\test1.xml";
                int Number = listBox2.Items.Count;
                String[] Files = new String[Number];
                String[] Hashes = new String[Number];
    
                for (int i = 0; i < listBox2.Items.Count; i++)
                {
            object s = listBox2.Items[i];
                    Files[i] = s.ToString();
                }
    
                for (int j = 0; j < listBox3.Items.Count; j++)
                {
                    object s = listBox3.Items[j];
                    Hashes[j] = s.ToString();
                }
    
                Functions.XMLNew(path, Name, TC, Number, Files, Hashes);
        }
    

    And if i now made the same changes and used the exact same logic in the other function they now both work correctly

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for the long post, but most of it is code spelling out my
Sorry for long winded post. I am trying to understand UIScrollView and running into
Sorry for this long post. The question is however small but requires full detail.
Sorry in advance for the long question. What I'm really interested in is a
Hello (this is a long post sorry), I am writing a application in ASP.NET
Sorry if this post appears to be long winded. I have a parent repeater
(Sorry for long post) Ok guys, so I'm having some issues with something I'm
Sorry for the long post that follows. I know that it is not a
Sorry for the long post... While being introduced to a brown field project, I'm
Sorry for the long post, but this forum always asks for use cases :-).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.