Click here to Skip to main content
15,668,517 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
Hi to All.
There is some problem:
I'm use fault tolerant system with Microsoft Windows Server 2008 sp2.
Where I try to get registry value as
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(@"Installer\Components\" + myBranch);
if (key.GetValue("1001") != null && (string)key.GetValue("1001") == myKey){
/*TODO: something*/}

Application return the error:
"Object reference not set to an instance of an object"
In another windows versions all is worked

What I have tried:

I tried set to user full access to registry, used C-libs for getting registry value..all isn't work
Updated 19-Mar-17 22:39pm
Evil Jay 22-Mar-17 1:29am    
Error was in system architect.
Despite the path "HKEY_CLASSES_ROOT\Installer\Components\myBranch" it refers to path "HKEY_CLASSES_ROOT\Wow6432node\Installer\Components\myBranch"

1 solution

The first thing to do is find out which bit is null: probably it's "key" but we can't tell.
So either use the debugger to find out, or add code to check if the value of key after the attempt to create the subkey is null. If it is, then the subkey creating failed - and that's likely to be a permissions issue (do you need Admin access?) rather than anything we can fix from here.
Share this answer
Evil Jay 20-Mar-17 5:01am    
Key is not problem. Debugger talk, that command "GetValue()" is not working and return not found exception. It is precedent situation. In Registry there are branch and key, and value in the key. Variable 'key' get path in Registry correctly.
Admin access allready in use.
OriginalGriff 20-Mar-17 5:13am    
"Object reference" is a very specific exception: it happens when a value is null and you try and access a field, property, or method of that value.
How did you check that key is not null?
Evil Jay 20-Mar-17 5:55am    
I added log where subkey was created/or found (I checked all methods, which let get the key, and key was righted always). It path was in Registry (Checked by Registry Editor).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900