dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.27k stars 1.76k forks source link

Preferences.Get() gives different results on Windows Machine simulator vs Android simulator ... #10676

Closed vsfeedback closed 2 years ago

vsfeedback commented 2 years ago

This issue has been moved from a ticket on Developer Community.


Run 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

When run using the Android simulator, the following is displayed:

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

Also posted issue at: https://github.com/dotnet/maui/pull/9361

Environment (copied from Visual Studio:

Microsoft Visual Studio Community 2022 Version 17.3.5 VisualStudio.17.Release/17.3.5+32922.545 Microsoft .NET Framework Version 4.8.04084

Installed Version: Community

ADL Tools Service Provider 1.0 This package contains services used by Data Lake tools

ASA Service Provider 1.0

ASP.NET and Web Tools 17.3.376.3011 ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.3.376.3011 Azure App Service Tools v3.0.0

Azure Data Lake Tools for Visual Studio 2.6.5000.0 Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools 17.3.376.3011 Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio 2.6.5000.0 Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools 4.3.0-3.22470.13+80a8ce8d5fdb9ceda4101e2acb8e8eb7be4ebcea C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus 1.2.6 (master@34d6af2) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Microsoft Azure Hive Query Language Service 2.6.5000.0 Language service for Hive query

Microsoft Azure Stream Analytics Language Service 2.6.5000.0 Language service for Azure Stream Analytics

Microsoft Azure Tools for Visual Studio 2.9 Support for Azure Cloud Services projects

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Mono Debugging for Visual Studio 17.3.20 (3f4cb00) Support for debugging Mono processes with Visual Studio.

NuGet Package Manager 6.3.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Razor (ASP.NET Core) 17.0.0.2232702+e1d654e792aa2fe6646a6935bcca80ff0aff4387 Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 17.0.62207.04100 Microsoft SQL Server Data Tools

ToolWindowHostedEditor 1.0 Hosting json editor into a tool window

TypeScript Tools 17.0.10701.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.3.0-3.22470.13+80a8ce8d5fdb9ceda4101e2acb8e8eb7be4ebcea Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.1.0-beta.22363.4+1b94f89d4d1f41f20f9be73c76f4b229d4e49078 Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio.

VisualStudio.DeviceLog 1.0 Information about my package

VisualStudio.Mac 1.0 Mac Extension for Visual Studio

VSPackage Extension 1.0 VSPackage Visual Studio Extension Detailed Info

Xamarin 17.3.0.308 (d17-3@56b9f7e) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 17.3.0.217 (remotes/origin/d17-3@b81db1dcc0) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 17.2.28 (9b3d244) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 13.0.0.0 (d17-3/030cd63) Xamarin.Android Reference Assemblies and MSBuild support. Mono: dffa5ab Java.Interop: xamarin/java.interop/d17-3@7716ae53 SQLite: xamarin/sqlite/3.38.5@df4deab Xamarin.Android Tools: xamarin/xamarin-android-tools/main@14076a6

Xamarin.iOS and Xamarin.Mac SDK 16.0.0.75 (e4f48bed7) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.


Original Comments

Feedback Bot on 10/7/2022, 06:36 PM:

(private comment, text removed)


Original Solutions

(no solutions)

jfversluis commented 2 years ago

@mattleibow this is something you requested in #9361 would you maybe have a look?

ghost commented 2 years ago

Hi @vsfeedback. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

mattleibow commented 2 years ago

Tested this code in the .NET 6 SR6 and .NET 7 and it all seems to be good:

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