Closed MikeP0911 closed 10 months ago
@MikeP0911 , in order to make sure the internal task is already completed you have to await it , so your code should be like this
public async void SetValueKeyChain(string key, string value)
{
try
{
await Task.Run(async() =>
{
await SecureStorage.Default.SetAsync(key, value);
}).ConfigureAwait(false);
await Task.Delay(30);
}
catch (Exception ex)
{
}
}
@alzubitariq Thank you for your reply. I tried implementing your suggestion. But still the problem persists. When I get the value it is empty.
Help is appreciated.
@alzubitariq My get is as following please let know if there is any problem.
public string GetValueKeyChain(string key)
{
try
{
KeyVal = string.Empty;
GetKeyAsync(key);
}
catch (Exception ex)
{
}
return KeyVal;
}
public async void GetKeyAsync(string keyName)
{
try
{
KeyVal = await SecureStorage.Default.GetAsync(keyName);
}
catch (Exception ex)
{
}
}
@MikeP0911 , why try to do things "synchronous", I suggest u to make things more simple like
string GetValueKeyChain(string key)
{
var result = "";
Task.Run(async () => result = await SecureStorage.Default.GetAsync(key)).Wait();
return result;
}
void SetValueKeyChain(string key, string value)
{
Task.Run(async () => await SecureStorage.Default.SetAsync(key, value)).Wait();
}
and you have to make sure SecureStorage instance is not null , just try to set or get after window "created" event or page Loaded event
@alzubitariq Thank you for the help. The issue is resolved.
Description
When getting the values stored using SetAsync is returning null.
when trying to access through Get it does not throw any exception. but returns null. var Token = GetValueKeyChain(DToken);
Steps to Reproduce
No response
Link to public reproduction project repository
No response
Version with bug
8.0.3
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
No response
Did you find any workaround?
No response
Relevant log output
No response