Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass the correct parameter value to the method #9361

Merged
merged 1 commit into from
Aug 11, 2022
Merged

Conversation

mattleibow
Copy link
Member

@mattleibow mattleibow commented Aug 11, 2022

Description of Change

In the effort to improve unpackaged support (#8536), I inadvertently broke Preferences on Windows because of a typo: default instead of defaultValue. This got through because our tests were correct, but coincidentally used the same value for defaultValue that was also default.

Issues Fixed

Fixes #9338

@mattleibow mattleibow added this to the 6.0-sr5 milestone Aug 11, 2022
@mattleibow mattleibow added platform/windows 🪟 area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info i/regression This issue described a confirmed regression on a currently supported version labels Aug 11, 2022
@mattleibow mattleibow self-assigned this Aug 11, 2022
Comment on lines 36 to 38
public T Get<T>(string key, T defaultValue, string sharedName) =>
_preferences.Get<T>(key, default, sharedName);
_preferences.Get<T>(key, defaultValue, sharedName);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is it! Oh dear.

@bdcoder2
Copy link

bdcoder2 commented Oct 6, 2022

I must be interpreting how Preferences.Get() is supposed to work.

I cannot seem to find any official documentation, however, the intellisense within Visual Studio displays the following:

VS1

which I am taking to mean, "If the given preferences key is NOT found, then the given defaultValue will be returned". So I ran the following tests using the Windows Machine simulator:

         Preferences.Clear();

         Debug.WriteLine( "String test:" );

         String str_default_val = "default";
         String str_val = Preferences.Get( "string_key", str_default_val);
         
         if ( str_val == str_default_val ) 
         {
            Debug.WriteLine( "- Passed" );
         }
         else
         {
            if ( str_val is null )
            {
               Debug.WriteLine( $"* FAILED: str_val: null, expecting: {str_default_val}" );
            }
            else
            {
               Debug.WriteLine( $"* FAILED: str_val: {str_val}, expecting: {str_default_val}" );
            }
         }


         Debug.WriteLine( "Boolean test:" );

         Boolean bool_default_val = true;
         Boolean bool_val = Preferences.Get( "boolean_key", bool_default_val );

         if ( bool_val == bool_default_val )
         {
            Debug.WriteLine( "- Passed" );
         }
         else
         {
            Debug.WriteLine( $"* FAILED: bool_val: {bool_val}, expecting: {bool_default_val}" );
         }


         Debug.WriteLine( "Int32 test:" );

         Int32 int32_default_val = 123;
         Int32 int32_val = Preferences.Get( "int32_key", int32_default_val );

         if ( int32_val == int32_default_val )
         {
            Debug.WriteLine( "- Passed" );
         }
         else
         {
            Debug.WriteLine( $"* FAILED: int32_val: {int32_val}, expecting: {int32_default_val}" );
         }

Output Displayed:

String test:
* FAILED: str_val: null, expecting: default
Boolean test:
* FAILED: bool_val: False, expecting: True
Int32 test:
* FAILED: int32_val: 0, expecting: 123

Clearly, on Windows, the Preferences.Get() method is returning the variable type default -- NOT the defaultValue given in the Get() method.

When run using the Android simulator, I get the following output:

String test:
- Passed
Boolean test:
- Passed
Int32 test:
- Passed

Which is the correct behavior?

@mattleibow
Copy link
Member Author

Can you open a new issue? Be sure to include the dotnet and workload versions (info for getting this is in the template).

@bdcoder2
Copy link

bdcoder2 commented Oct 6, 2022

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info fixed-in-6.0.540 Look for this fix in 6.0.540 SR5! fixed-in-7.0.0-rc.1.6683 i/regression This issue described a confirmed regression on a currently supported version platform/windows 🪟
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants