Home All Groups Group Topic Archive Search About

bug found in Microsoft.Win32.RegistryValueKind.DWord conversion

Author
3 Mar 2006 1:21 AM
Ben Wilson
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.

Author
3 Mar 2006 5:37 AM
Nick Hounsome
Show quote
"Ben Wilson" <BenWil***@discussions.microsoft.com> wrote in message
news:AD3D0BF7-8CEA-4AAD-91B4-111B6C5B54CB@microsoft.com...
>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.

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.
Author
3 Mar 2006 9:47 AM
Ben Wilson
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!

Show quote
"Nick Hounsome" wrote:

>
> "Ben Wilson" <BenWil***@discussions.microsoft.com> wrote in message
> news:AD3D0BF7-8CEA-4AAD-91B4-111B6C5B54CB@microsoft.com...
> >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.
>
> 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.
>
>
>
Author
4 Mar 2006 7:59 AM
Nick Hounsome
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

Show quote
"Ben Wilson" <BenWil***@discussions.microsoft.com> wrote in message
news:2550C281-8B62-45B8-B486-FA209BEB05BB@microsoft.com...
> 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!
>
> "Nick Hounsome" wrote:
>
>>
>> "Ben Wilson" <BenWil***@discussions.microsoft.com> wrote in message
>> news:AD3D0BF7-8CEA-4AAD-91B4-111B6C5B54CB@microsoft.com...
>> >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.
>>
>> 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.
>>
>>
>>
Author
3 Mar 2006 11:14 AM
Stephany Young
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


Show quote
"Ben Wilson" <BenWil***@discussions.microsoft.com> wrote in message
news:AD3D0BF7-8CEA-4AAD-91B4-111B6C5B54CB@microsoft.com...
>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.
Author
3 Mar 2006 12:54 PM
José_Manuel_Agüero
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.


Show quote
"Ben Wilson" <BenWil***@discussions.microsoft.com> escribió en el mensaje news:AD3D0BF7-8CEA-4AAD-91B4-111B6C5B54CB@microsoft.com...
|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.
Author
3 Mar 2006 1:21 PM
Ben Wilson
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.

Show quote
"José Manuel Agüero" wrote:

> 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.
>
>
> "Ben Wilson" <BenWil***@discussions.microsoft.com> escribió en el mensaje news:AD3D0BF7-8CEA-4AAD-91B4-111B6C5B54CB@microsoft.com...
> |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.
>
Author
3 Mar 2006 3:28 PM
José_Manuel_Agüero
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.


Show quote
"Ben Wilson" <BenWil***@discussions.microsoft.com> escribió en el mensaje news:8C32C515-4933-4B3D-84CE-38D5B2B42F4C@microsoft.com...
| 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,
| >
| > 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.
| >
| >
| > "Ben Wilson" <BenWil***@discussions.microsoft.com> escribió en el mensaje news:AD3D0BF7-8CEA-4AAD-91B4-111B6C5B54CB@microsoft.com...
| > |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.
| >

AddThis Social Bookmark Button