Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2006

Tip: Looking for answers? Try searching our database.

bug found in Microsoft.Win32.RegistryValueKind.DWord conversion

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ben Wilson - 03 Mar 2006 01:21 GMT
I have found what I can only conclude to be a bug in .net after days of
messing around.  I am trying to assign a large value to a registry dword
entry close to it's limit of 4294967295 or 0xFFFFFFFF

I have tried making the call through vb.net and c# and it produces the same
result.  I am assigning the value like so:

uint myVar = 4294967295
Microsoft.Win32.Registry.LocalMachine.SetValue(VideoSettingsKey &
"RecordingSoftPostPadding",myVar,Microsoft.Win32.RegistryValueKind.DWord)

which fails with a conversion failure, I SHOULD be able to assign a uint
value though.  I can successfully assign an int value (smaller of course)
without a problem, but int does not cover the range of values which can be
contained in a regisry dword, only a uint can cover that range.
Nick Hounsome - 03 Mar 2006 05:37 GMT
>I have found what I can only conclude to be a bug in .net after days of
> messing around.  I am trying to assign a large value to a registry dword
[quoted text clipped - 12 lines]
> without a problem, but int does not cover the range of values which can be
> contained in a regisry dword, only a uint can cover that range.

I agree it looks like a bug.
The work around is easy - use an int:

int myIVar = unchecked((int)myVar);

This will give the right value in the registry.
Ben Wilson - 03 Mar 2006 09:47 GMT
not sure I follow that code example you gave me, could you show me how you
would implement that in my sample code?

glad to see someone agrees it's a bug, was banging my head on a wall trying
to figure it out!

> >I have found what I can only conclude to be a bug in .net after days of
> > messing around.  I am trying to assign a large value to a registry dword
[quoted text clipped - 19 lines]
>
> This will give the right value in the registry.
Nick Hounsome - 04 Mar 2006 07:59 GMT
uint 4294967295

has exactly the same binary representation as

int -1

so just convert it to int without  checking and it will hopefully give you
the value that you want in the registry.

I don't understand the argument that uint is not CLS compliant.
Only the interface needs to be CLS compliant and that takes Object so there
is no problem.

The registry is undoubtedly unsigned - just go into regedit and try to
enter -1

> not sure I follow that code example you gave me, could you show me how you
> would implement that in my sample code?
[quoted text clipped - 30 lines]
>>
>> This will give the right value in the registry.
Stephany Young - 03 Mar 2006 11:14 GMT
I'm not convinced it's a bug.

Which statement fails, the assignment or the method call?

If it's the assignment, I've come across a similar gotcha in VB.NET. The
literal is treated as an Integer (Int32) and the value of the literal is too
big for an Integer so kaboom.

In VB.NET, one can specify that the literal is a UInt32 by writing it as:

   Dim myVar As UInteger = 4294967295UI

>I have found what I can only conclude to be a bug in .net after days of
> messing around.  I am trying to assign a large value to a registry dword
[quoted text clipped - 12 lines]
> without a problem, but int does not cover the range of values which can be
> contained in a regisry dword, only a uint can cover that range.
Jos Manuel Agero - 03 Mar 2006 12:54 GMT
Hello Ben,

You are trying to store an Int32 that is grater than Int32.MaxValue.
The registry do not store UInt32 values; you have to convert it before writing and after reading from the registry to a supported type.
For a list of supported types, see:
RegistryValueKind Enumeration
http://msdn2.microsoft.com/en-us/library/microsoft.win32.registryvaluekind(VS.80
).aspx


Regards.

|I have found what I can only conclude to be a bug in .net after days of
| messing around.  I am trying to assign a large value to a registry dword
[quoted text clipped - 11 lines]
| without a problem, but int does not cover the range of values which can be
| contained in a regisry dword, only a uint can cover that range.
Ben Wilson - 03 Mar 2006 13:21 GMT
The registry DWORD can store values up to 0xFFFFFFFF or 4294967295, yet there
is no way to assign this, and this is the bug.

Using an int or uint works, however it will not accept values higher than
0x7FFFFFFF or 2147483647, which is the maximum positive value of an int.

I believe it is impossible to to successfully assign a registry dword value
> 2147483647 programmaticlly through the Registry.LocalMachine.SetValue
method, and this is the bug, as you *should* be able to do this.

"José Manuel Agüero" wrote:

> Hello Ben,
>
[quoted text clipped - 21 lines]
> | without a problem, but int does not cover the range of values which can be
> | contained in a regisry dword, only a uint can cover that range.
Jos Manuel Agero - 03 Mar 2006 15:28 GMT
I think you shouldn't be able, as long as UInt32 is not CLS compliant (it's only my opinion).
Why don't you use bitconverter to convert it to Int32 and then save it to the registry?

Regards.

| The registry DWORD can store values up to 0xFFFFFFFF or 4294967295, yet there
| is no way to assign this, and this is the bug.
[quoted text clipped - 31 lines]
| > | without a problem, but int does not cover the range of values which can be
| > | contained in a regisry dword, only a uint can cover that range.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.