Wartość null po inicjalizacji obiektu z nie pustymi parametrami zamiast true dlaczego?

0

Witam mam problem z uzyskaniem wartości TRUE bo obiekt zwraca mi do return wartość NULL a nie powinien i nie wiem dlaczego skoro wszystkie parametry ma wypełnione danymi.
Kod wygląda następująco:

internal class UpdateXml{
.....
internal UpdateXml(Version version, Uri uri, string fileName, string md5, string description, string launchArgs) 
        {
            this.version = version;
            this.uri = uri;
            this.fileName = fileName;
            this.md5 = md5;
            this.description = description;
            this.launchArgs = launchArgs;
        }
internal static UpdateXml Parse(Uri location, string appID)
        {
            Version version = null;
            string url = "", fileName = "", md5 = "", description = "", launchArgs = "";
            UpdateXml arg = null;
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(location.AbsoluteUri);
                XmlNode node = doc.DocumentElement.SelectSingleNode("//update[@appId='" + appID + "']");
                if (node == null)
                {
                    return null;
                }
                version = Version.Parse(node["version"].InnerText);
                url = node["url"].InnerText;
                fileName = node["fileName"].InnerText;
                md5 = node["md5"].InnerText;
                description = node["description"].InnerText;
                launchArgs = node["launchArgs"].InnerText;
                //Tu zamieniłem z tego return na zmienna arg bo był błąd CS0321 ale teraz mam dalej zwracaną wartość na NULL nie wiem co zrobić?
                arg = new UpdateXml(version, new Uri(url), fileName, md5, description, launchArgs);
                return arg;
                //return new UpdateXml(version, new Uri(url), fileName, md5, description, launchArgs);
            }
            catch { return null; }
        }
}
2

Wyświetl sobie w catch jaki masz wyjątek, a nie zwracaj nulla.

1

Witam,

Rozumiem że jak nie masz elementu "md5" w XML to

md5 = node["md5"].InnerText;

to twój kod nie wyrzuci wyjątku? Może napisz coś takiego?

md5 = node["md5"]?.InnerText ?? string.Empty;

Pozdrawiam,

mr-owl

0

Właśnie jak wartości są puste to nie powinno wywalac błędu A wszystkie wartości mi wypełnia jedynie lunchArgs jest puste bo w xml nie ma nic tam podane.
Może mi ktoś podpowiedzieć czemu rekurencja do konstruktora tej klasy zwraca null mimo wypełnionych wartości nawet jeśli lunchArgs zawiera coś?

1 użytkowników online, w tym zalogowanych: 0, gości: 1