Object reference not set to an instance of an object.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Object reference not set to an instance of an object.

  1. #1
    Join Date
    Jan 2011
    Posts
    5

    Object reference not set to an instance of an object.

    Hi, im new to c# and new to this forum.

    Win 7 64bit
    .net 3.5 (using vs2008)

    I found this code online to get the 'UninstallString' from a specific subkey within the registry. I am trying to debug the code but im getting the 'Object reference not set to an instance of an object.' error.

    I broke down the code in order to find where it was giving me the error and its at the point where the code posted below has *** ***.

    Im not really sure how to fix this. I previously put a try and catch but it would still break the program. Any help on this would be appreciated.

    Code Below:

    String AppName = "Abode AIR";

    RegistryKey ReadReg = Registry.LocalMachine
    .OpenSubKey("SOFTWARE")
    .OpenSubKey("Microsoft")
    .OpenSubKey("Windows")
    .OpenSubKey("CurrentVersion")
    .OpenSubKey("Installer")
    .OpenSubKey("UserData")
    .OpenSubKey("S-1-5-18")
    .OpenSubKey("Products");
    String[] SubNames = ReadReg.GetSubKeyNames();
    Console.ReadLine(); //Dont mind this line
    for (int i = 0; i < SubNames.Length; i++)
    {
    RegistryKey temp = ReadReg.OpenSubKey(SubNames[i])
    .OpenSubKey("InstallProperties");
    ***if (temp.GetValue("DisplayName").ToString() == AppName)***
    {
    Console.WriteLine("Found it");
    }
    }


    Thanks for your support

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Object reference not set to an instance of an object.

    Either temp is null or temp.GetValue("DisplayName") is returning null. You should be checking for null if it is a possible return value.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center