user3456466
user3456466

Reputation:

the best overloaded method match for has some invalid arguments C#

I am trying this code :

string file =@"C:\Program.xml";
XDocument doc = new XDocument(XElement.Load(file));
XElement root = XElement.Parse(doc);

I get the following error :

the best overloaded method match for has some invalid arguments  

I really need some help...I've been searchig for some hours for a solution.

Upvotes: 0

Views: 1071

Answers (2)

StuartLC
StuartLC

Reputation: 107327

XElement.Parse is used to load xml from a string, whereas Load is used to load an xml file - generally you won't need to use both.

I think you may be looking to do something like:

string file = @"C:\Program.xml";
XDocument doc = XDocument.Load(file);
XElement root = doc.Root;
var value = root.Element("foo").Attribute("bar");

Upvotes: 0

Tinwor
Tinwor

Reputation: 7973

XElement.Parse(string s) or XElement.Parse(string s, LoadOptions l) hasn't a overload that accept an XDocument control.
According to this dotnetperls' example you can do this:

XElement xelement = XElement.Load("myFile.xml");

Upvotes: 1

Related Questions