Getting a compile error in c# about not referencing System.XML, yes System.XML is being reference

14,665

Solution 1

Using a namespace does not mean you referenced something. You need to add a reference to System.XML.

If you are using Visual Studio, right click on references, click Add Reference and then select System.XML.

Solution 2

The using directive (not to be confused with the using statement) is just to import namespaces from your referenced assemblies into your code file in order to make it easier to use the types that the assemblies contain without having to fully-qualify their names with their namespaces. The fact that the assembly System.Xml and the namespace System.Xml are named the same, in this case, is merely a coincidence.

You need to actually add the System.Xml.DLL reference, as it suggests, to your project: right-click on "References" beneath your project in the solution explorer, select "Add Reference", then locate and check off the System.Xml assembly within the list of framework assemblies:

enter image description here

enter image description here

Solution 3

The error may be misleading if you have the reference - you may also need to reference System.Xml.Serialization.

System.Xml.Serialization library

Share:
14,665

Related videos on Youtube

needoriginalname
Author by

needoriginalname

Updated on September 15, 2022

Comments

  • needoriginalname
    needoriginalname over 1 year

    I am trying to add a new feature to an old program I wrote. However, when trying to get the program to build in VS express it spits back an error message to me.

    Error 1 The type 'System.Xml.Serialization.IXmlSerializable' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. C:\Path\To\File\summaryForm.cs 101 18 SerialController

    However the thing is at the top of the cs file, it has

    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms; 
    using System.Xml;
    

    Any ideas whyits not recognizing the XML reference?

  • Damien_The_Unbeliever
    Damien_The_Unbeliever almost 9 years
    using directive. There are two unrelated features in C# that both use the keyword using. They are the using directive and the using statement. Using the name of the second when you mean the first can only lead to confusion.
  • Sebastian Negraszus
    Sebastian Negraszus almost 9 years
    A using does not really import an assembly, but a namespace.
  • rory.ap
    rory.ap almost 9 years
    @SebastianNegraszus -- You're right, of course. Updated.