c# - NullReferenceException external code Xamarin-Android -


i got problem when passing static string delegate, i've tried copying value of static string normal string , works fine.

((jsonhttpclient)connection).requestfilter = httpreq => {     string authtoken = memorycache.authtoken;     httpreq.headers.add(udareconstants.authtokenkey, authtoken); }; 

also, hard coding value works fine.

((jsonhttpclient)connection).requestfilter = httpreq => {     string authtoken = "62bebc52-fde3-4f47-beab-6a3e4e3440f0";     httpreq.headers.add(udareconstants.authtokenkey, authtoken); }; 

memorycache it's static class , authtoken property it's static string.

this driving me insane.

the call stack exception

console output after app crashes

i haven't coded in java ages , have never used xamarin might have run stuff related java memory model.

java documentation says:

  • each action in thread happens-before every action in thread comes later in program's order.

  • an unlock (synchronized block or method exit) of monitor happens-before every subsequent lock (synchronized block or method entry) of same monitor. , because happens-before relation transitive, actions of thread prior unlocking happen-before actions subsequent thread locking monitor.

  • a write volatile field happens-before every subsequent read of same field. writes , reads of volatile fields have similar memory consistency effects entering , exiting monitors, not entail mutual exclusion locking.

  • a call start on thread happens-before action in started thread.

  • all actions in thread happen-before other thread returns join on thread.

you can read bit more in nathan hughes' answer on so.

another option you've run issue static field initialization order.

btw: static variables bad idea.


Comments

Popular posts from this blog

Listboxes in c# -

Excel Duty List -

Multilayer CSV to filtered excel -