简体   繁体   中英

No source found.Exception has been thrown by the target of an invocation

I am constructing a tree in wpf application based on the value returned from a method getvalues(). I am parsing an xml files and storing the values in the variable and returning it to a class which is accessing it's value.I am accessing the xml file from the registry keys. If there is no xml file in my machine my application should show an emptry tree.

so i wrote like this. I returned null when there is no xml file

public class Model
 {
    public Model()
    {

            using (RegistryKey pRegKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Something"))
            if (pRegKey != null)
            {

                Object val = pRegKey.GetValue("INSTALLLOGSDIR");
                basepath = (string)val1;
                tot_val = basepath+ @"\some.xml";
            }
            else
            {
                MessageBox.Show("some.xml Not found in ur machine.");
            }
    }

 public Mainclass[] getValues()
    {
        if (tot_val.Equals(null))
        {
            return null;
        }
        else
        {
        //return something of type Mainclass[];
        }
      }
}

But am keep getting an exception No source available Exception has been thrown by the target of an invocation.

I ll be glad if you help me to solve this problem. Sorry if it is a duplicate. I searched several forums. din find the related scenario.
Thanks in advance.

As stated in comment:

tot_val.Equals(null) is strange and if it supposed to compare if tot_value is null it will fail with NullPointerException - use == instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM