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

SecureStorage returns null for all values after restarting app (Android) #23013

Open
pmigliore opened this issue Jun 12, 2024 · 3 comments
Open
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info delighter migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@pmigliore
Copy link

Description

If I set a value in the SecureStorage await SecureStorage.SetAsync("TestKey", "TestValue") during the first app startup, and then return the value await SecureStorage.GetAsync("TestKey"), the value is returned correctly. But if I close the app, even from running in the background, and restart it a second time, and call await SecureStorage.GetAsync("TestKey"), then it returns null. But if I set the value again, then it starts working successfully, and returns the value corectly if I restart the app a third time and so on.

Steps to Reproduce

  1. Create a new .NET MAUI project.
  2. In the App.xaml.cs constructor add the following line of code:
    Task.Run(async () => { await SecureStorage.SetAsync("TestKey", "TeskKey"); var val = await SecureStorage.GetAsync("TeskKey"); });
    and add a breakpoint in the last line of code.
  3. Start the Android (API 30) emulator in debug mode, "val" should return the correct value
  4. Close the app, even from the background, and comment out await SecureStorage.SetAsync("TestKey", "TeskKey");.
  5. Restart the app in debug mode.
  6. If running it again "val" returns "null"

Link to public reproduction project repository

No response

Version with bug

8.0.40 SR5

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 12 and below

Did you find any workaround?

No

Relevant log output

None
@pmigliore pmigliore added the t/bug Something isn't working label Jun 12, 2024
Copy link
Contributor

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@jsuarezruiz jsuarezruiz added platform/android 🤖 area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info labels Jun 13, 2024
@ninachen03 ninachen03 added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert labels Jun 25, 2024
@ninachen03
Copy link

I can repro this issue on the latest 17.11.0 Preview 2.1 (8.0.60 & 8.0.40 & 8.0.21).
image

@samhouts samhouts removed s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 3, 2024
@samhouts samhouts added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 10, 2024
@jsuarezruiz jsuarezruiz added this to the Backlog milestone Oct 14, 2024
@Domik234
Copy link

Domik234 commented Nov 6, 2024

@ninachen03, @samhouts Hey, I think this should always return null.

SetAsync is used to save value TeskKey to key TestKey.
GetAsync after is calling for key TeskKey but this key won't exist because SetAsync for this key was never used.

Key Value
TestKey TeskKey
TeskKey null

For a relevant test you should call var val = await SecureStorage.GetAsync("TestKey");

(this case tested on 8.0.82 - requested was for 8.0.40 SR5):
Physical Device API 31
Image

Emulator API 30
Image

I believe this issue should be propably tagged as (s/needs-info) because it looks like it's no more needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info delighter migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants