- Home /
Windows Phone: NullReferenceException in HttpWebRequest.Headers.set_Item
Not much else to say--I hit this on WinPhone, but not other platforms. This code gives me a NullReferenceException if it's part of the Unity project (i.e. in Assembly-CSharp.dll):
HttpWebRequest r = (HttpWebRequest)WebRequest.Create("http://www.yahoo.com");
var h = r.Headers;
h["header"] = "appId";
But the exact same code in MainPage.xaml.cs works fine. The only thing I can guess is that code from the project itself is somehow using System.Collections.Specialized.NameValueCollection from WinRTLegacy and that version has a bug for setting values. Otherwise I'm at a complete loss.
Any ideas would be most welcome.
Your answer
![](https://koobas.hobune.stream/wayback/20220613161717im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Windows Store App Encryption 2 Answers
Slow start time on WP8: CreateMonoScriptCache 0 Answers
WebCamTexture not working on Windows Phone 8.1 0 Answers
Unity WP8 Better Performance When Connected to Visual Studio 1 Answer
MediaElement watermark wp8 0 Answers