Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

C# Class Library

I have the following code below and I am trying to create a DLL that will create, read, encode, decode and update an XML file. I have several other programs that I am writing that will have this DLL refrenced so I can re-use the code.

I get an error on System.Xml.XmlReader X = new System.Xml.XmlReader(CommonArea.AssemblyLocation + @"/TestXMLFile.xml"); It will not let me build the project. Is there somthing else I need to do first or declare Read() in a diffrent way? I a DLL the way to go?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpUtilityBelt
{
    public class CommonArea
    {
        public static string AssemblyLocation = System.Reflection.Assembly.
            GetExecutingAssembly().Location.Substring(0, System.Reflection.
            Assembly.GetExecutingAssembly().Location.LastIndexOf("\\"));
    }

    public class ReadXmlFile
    {
        public void Read()
        {
            System.Xml.XmlReader X = new System.Xml.XmlReader(CommonArea.AssemblyLocation + @"/TestXMLFile.xml");

            X.MoveToElement();

            while (X.Read())
            {
                if (X.NodeType = System.Xml.XmlNodeType.Text)
                {
                    System.Console.WriteLine(X.Value.ToString);
                    System.Console.ReadLine();
                }
            }
                
        }
    }
}

Open in new window

0
Mister_Spock
Asked:
Mister_Spock
  • 3
  • 3
1 Solution
 
Snarf0001Commented:
You're using an actual Filepath now, the separater dash is flipped:
instead of @"/TestXMLFile.xml"
try @"\TestXMLFile.xml"
0
 
Mister_SpockAuthor Commented:
Tried it but that is not the problem. I need to instantiate the Sytem.Xml.XmlReader. So far I am not able to do so using a class library.
0
 
Snarf0001Commented:
Can you post the error you're getting?
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
Mister_SpockAuthor Commented:
Cannot create an instance of the abstract class or interface 'System.Xml.XmlReader' I have done this many time in both a console and windows application in C#, unsure as to why I cannot here.
0
 
Snarf0001Commented:
Ahh, sorry, should have actually tried the code out myself.
XmlReader itself is abstract, it doesn't actually have a constructor.

You either need to call the .Create method, or use and XmlTextReader object (which is probably what you used in the past).
System.Xml.XmlReader X = System.Xml.XmlReader.Create(CommonArea.AssemblyLocation + @"/TestXMLFile.xml");

   OR

System.Xml.XmlReader X = new System.Xml.XmlTextReader(CommonArea.AssemblyLocation + @"/TestXMLFile.xml");

Open in new window

0
 
Mister_SpockAuthor Commented:
Thank you for your help
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now