Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Not all code paths return a value

I wrote the following code to count the node of an XML file:

private Dictionary<string, int> ExtractNodeInfo(string fileContent)
    {
        XmlDocument xmlDocument;
        xmlDocument = new XmlDocument();
        xmlDocument.Load(fileContent);
        var ediNodes = xmlDocument.DocumentElement.SelectNodes("/EDI");
        Dictionary<string, int> nodeCount = new Dictionary<string, int>();
        foreach (XmlNode nodes in ediNodes)
        {
            FileManager.nodeRecurse(nodes, nodeCount);
        }

        foreach (var entry in nodeCount)
        {
            Console.WriteLine(entry.ToString());
        }
    }

But it gives me the following error: 'XmlFileManager.FileManager.ExtractNodeInfo(string)': not all code paths return a value.

like image 337
user1255009 Avatar asked Jun 27 '26 10:06

user1255009


1 Answers

You aren't returning a value.

You need a return statement at the end of your method, in this case:

return nodeCount;
like image 81
psubsee2003 Avatar answered Jun 30 '26 03:06

psubsee2003



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!