RyGuy RyGuy - 3 months ago 21
C# Question

linq non-invocable member - cannot be used like a method

I want to use clientXml as a public property of my main form class so that I can use it in other events in my form but i get the error "linq non-invocable member - cannot be used like a method".

So at the top it is defined as :

public List<data> clientList = new List<data>();


...

var clientXml = XDocument.Load(@"ClientData.xml");

clientList(
from d in clientXml.Descendants("Client")
select new RegexData(
d.Element("Bla1").Value.ToString(),
d.Element("Bla2").Value.ToString(),
d.Element("Bla3").Value.ToString(),
d.Element("Bla4").Value.ToString(),
d.Element("Bla5").Value.ToString(),
d.Element("Bla6").Value.ToString(),
d.Element("Bla7").Value.ToString(),
d.Element("Bla8").Value.ToString(),
bool.Parse(d.Element("Bla9").Value.ToString()),
d.Element("Bla10").Value.ToString()
)
);

Answer

The message is slightly cryptic around the "non-invocable member" part. C# is trying to tell you that using clientList, a field denoting a List<data>, as if it were a method is not allowed.

You should write an assignment instead:

clientList = (
from d in clientXml.Descendants("Client")
select new RegexData(
    d.Element("Bla1").Value.ToString(),
    d.Element("Bla2").Value.ToString(),
    d.Element("Bla3").Value.ToString(),
    d.Element("Bla4").Value.ToString(),
    d.Element("Bla5").Value.ToString(),
    d.Element("Bla6").Value.ToString(),
    d.Element("Bla7").Value.ToString(),
    d.Element("Bla8").Value.ToString(),
    bool.Parse(d.Element("Bla9").Value.ToString()),
    d.Element("Bla10").Value.ToString()
).ToList();

and make sure that clientList has List<RegexData> data type.

Comments