Tag: argumentnullexception

System.NullReferenceException检查是否!= null

我正在使用ASHX处理程序,我希望处理程序检查Session!= null。 if (context.Session[“Username”] != null) 我得到这个错误指向这一行: System.NullReferenceException:未将对象引用设置为对象的实例。 有什么问题?

关于更改框架的ArgumentNullException

所以我试图在Windows 8应用程序中更改帧。 我尝试按照本页的教程,但我一直得到同样的错误。 我在线上得到了一个ArgumentNullException: frameState[_pageKey] = pageState; 在LayoutAwarePage.cs类中,在OnNavigatedFrom方法中。 现在我不确定为什么会出现这个错误,因为我觉得在我的代码中没有任何东西可以导致它。 我的按钮onclick函数有这个代码: DateTime chosenDateTime = new DateTime(year, month, day, hours, minutes, seconds); this.Frame.Navigate(typeof(MainPage), chosenDateTime.ToString()); 我的MainPage中的OnNavigatedTo方法如下所示: protected override void OnNavigatedTo(NavigationEventArgs e) { string parameter = (string)e.Parameter; if (parameter != “”) { Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings; roamingSettings.Values[“chosenDateTime”] = parameter; chosenDateTime = Convert.ToDateTime(e.Parameter); } else { Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings; […]

从string创建类实例

我有一个C#方法,它从字符串创建一个类的新实例,但是,在运行代码时出现错误。 obj = (ClassX)Activator.CreateInstance(Type.GetType(“classPrefix_” + className)); ArgumentNullException未处理 值不能为空 参数名称: 类型 任何有关此错误的帮助将不胜感激。