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

LVL 3
Mister_SpockAsked:
Who is Participating?
 
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
 
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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
Snarf0001Commented:
Can you post the error you're getting?
0
 
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
 
Mister_SpockAuthor Commented:
Thank you for your help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.