Null

  • Thread starter Thread starter James Roberts
  • Start date Start date
J

James Roberts

hiya i'm using this piece of code

RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Retrospect",
true);
if(key != null)
{
// Sets up the registry, when run for the first time.
// Creates the subkey and sets the key to the directory its in
key = Registry.CurrentUser.CreateSubKey(@"Software\Retrospect");
key.SetValue("Letumexe", folder + @"\" + self.ScopeName);
// and copies itself to the choosen directory
}

when i run i get an nullreferenceexception which i think has come from

if(key != null)

i have also tried if(key == null) with no luck
How can this be solved?
 
James Roberts said:
hiya i'm using this piece of code

RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Retrospect",
true);
if(key != null)
{
// Sets up the registry, when run for the first time.
// Creates the subkey and sets the key to the directory its in
key = Registry.CurrentUser.CreateSubKey(@"Software\Retrospect");
key.SetValue("Letumexe", folder + @"\" + self.ScopeName);
// and copies itself to the choosen directory
}

when i run i get an nullreferenceexception which i think has come from

if(key != null)

i have also tried if(key == null) with no luck
How can this be solved?

No, using if (key != null) will certainly not generate an exception.
Look at the stack trace in the exception to see which line generated
it. If you're still having problems, could you post a short but
complete program which demonstrates the problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top