Hi
Coming across a super weird error that i’ve never seen before.
I am using Xamarin which uses c# under the hood. Regardless i am testing for an existance of a key. If true, then i attempt to retrieve the value of the key.


However, whenever assigning the value to a var, it keeps returning null despite the key definitely having a value. I can tell it has a value because i can see it when i debug and hover over the Key.
https://imgur.com/a/i49kRmA
Does anyone have any ideas? the value is not being over-written anywhere else.
Are you sure you’re debugging the latest version of the code and not a version that doesn’t match the code?
Ah, the white circle of doom.
First off, as a sanity check, rebuild all code, including dependencies.
Could you show how the dictionary is declared, and how a values are added to it?
I’d also try deleting the .vs folder from your solution directory and try restarting Visual Studio.
Re-open visual studio and rebuild your code. I’ve had a few bugs similar to this occur.
If that doesn’t work. Toss ?Application.Current.Properties[“BaseCurrency”] into the immediate window and find out what result it’s giving.
Umm you’re actually executing the assignment right? You’re not just setting a breakpoint on that line before the assignment to the local actually occurs, are you? If so then the local will be null.
i’ve set a breakpoint after that line too, so it is actually being executed
Don’t call toString(). Does it return anything then?
cannot convert from object to string if i remove the toString() and the convert.toString()
Is the data type really a dictionary or is it a collection of key value types?
If it’s a collection of key value types make sure you don’t have two entries with the same key in the collection.
Also, what is the scope where you are trying to assign the value? Are you passing it to a method? Is this being data bound to a xamarin control? It’s possible that if data binding is involved then you could be receiving a copy of the collection or it may be in a initialized state via event handling.
Can you give some more context?
didn’t know you could create duplicate keys.
Xamarin.Forms App Class – Xamarin | Microsoft Docs // looks like its just a dictionary.
im passing it into a method.
Your code is using index 0, debug view is showing index 1.
The index 1 is in the ..Properties dictionary, he has a list “list4base” where he puts the value that is on index 0.
Did you found the problem?
Try to get the value from the list in another way. Or just create the baseCurrency before the if statement and assign it in it
no, still isnt sorted. Will try this however. thanks
C# devs
null reference exceptions

source