Receiving error message "The type "XmlNode" is defined in an assembly that is not referenced.", but appropriate assembly is referenced

517 views Asked by At

I've been searching for solution for a long time with no luck. I'm using this code to extract text from a .odt file:

public String ReadOdt(String path)
        {
            var sb = new StringBuilder();
            using (var doc = new TextDocument())
            {
                doc.Load(path);

                XElement stylesPart = XElement.Parse(doc.DocumentStyles.Styles.OuterXml);
                string stylesText = string.Join("\r\n", stylesPart.Descendants().Where(x => x.Name.LocalName == "header" || x.Name.LocalName == "footer").Select(y => y.Value));

                var mainPart = doc.Content.Cast<IContent>();
                var mainText = String.Join("\r\n", mainPart.Select(x => x.Node.InnerText));

                sb.Append(stylesText + "\r\n");
                sb.Append(mainText);
            }
            return sb.ToString();
        }

However, Visual Studio is telling me:

Error CS0012: The type 'XmlNode' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xml, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. (CS0012) (ScriptTablerV0)

And the same thing for type 'XmlDocument'.

As a solution it proposes to import the System.Xml reference, but this doesn't change anything and the errors persist.

Is there anything i should look at or try? Any help would be greatly appreciated.

EDIT: I've tried using other methods/classes from the System.Xml assembly and they've worked with no problems, but VS still doesn't recognise Styles and Node.

0

There are 0 answers