nullreferenceexception

How do I allow breaking on 'System.NullReferenceException' in VS2010?

若如初见. 提交于 2019-11-29 05:40:28
I have a VS 2010 C# .NET 4 project. The issue is that the program is not breaking on 'NullReferenceException' errors during debugging. The output window will display the following: A first chance exception of type 'System.NullReferenceException' occurred in myProgram.exe ...but the debugger will just exit out of the function and continue running the rest of the program. How do I change this behavior so that the debugger will break on these exceptions? Go to Debug -> Exceptions -> Search for NullReferenceException and check the "thrown" checkbox. 来源: https://stackoverflow.com/questions/4475464

VS2012: Property Pages isn't opening: Object reference not set to an instance of an object

懵懂的女人 提交于 2019-11-29 05:31:10
I'm on Visual Studio Premium 2012, Version 11.0.50727.1 RTMREL, Windows 7 Enterprise (SP1). When I right click on the Solution, and click Properties, I get a popup window showing the the null reference exception (Object reference not set to an instance of an object). When I try the same in 2010, it works fine, opening up the normal solution properties pages, allowing me to set the startup order etc. Also, in 2012, View -> Property Pages, gives the same result. Please advise how to solve this, is this a known bug? UPDATE 1: Tried running devenv /resetsettings as well as devenv /safemode but the

MVC5 Razor NullReferenceException in Model

雨燕双飞 提交于 2019-11-29 05:29:40
For some reason I'm getting a NullReferenceException whenever I try to access my model. Here is the code from my controller: public async Task<ActionResult> Bar(string fooSlug, int barId) { var foo = await mediaService.GetFoo(fooSlug); var bar = await barService.GetBarFromFooByTitleId(foo.TitleId, barId); var viewModel = new ViewModels.BarViewModel(foo, bar); return View(viewModel); } Code from the ViewModel: public class BarViewModel { public Models.Sub.FooDetails Foo{ get; set; } public Models.Sub.BarDetails Bar { get; set; } public BarViewModel(Models.Sub.FooDetails foo, Models.Sub

Can Visual Studio tell me which reference threw a NullReferenceException?

前提是你 提交于 2019-11-29 03:59:28
I'm writing unit tests for an MVC web app, and I've been getting null reference exceptions because the mocked-up test objects are only partly initialized. I know which line is throwing the exceptions, and it looks something like this: return Supervisor.RegistrationInformation.Registrations .Any(r => r.RegistrationCountry.IsUSAOrCandada() && (!DatesWorked.Start.HasValue || r.RegistrationDate <= DatesWorked.Start.Value) && (!DatesWorked.End.HasValue || r.RegistrationExpirationDate >= DatesWorked.End.Value) && //... There are a lot of references in there, and any of them could be the problem.

System.NullReferenceException in App_Web_*.dll

不问归期 提交于 2019-11-29 01:09:09
I am having an odd issue. My MVC application seems to be working perfectly fine except for one view page. The view page in question (Organization/Edit) gets a 'NullReferenceException' on every code item on the page. Whether it is Html.TextBoxFor() or HTML.AntiForgeryToken() . I have my model, view, and controller laid out here on another question that i think is related -- https://stackoverflow.com/questions/26475866/dropdownlistfor-null-reference-error As you can see below, my model does have information inside of it. This screen capture was taken at the " Return View("Edit", model) " inside

Checking session if empty or not

六眼飞鱼酱① 提交于 2019-11-29 00:39:39
问题 I want to check that session is null or empty i.e. some thing like this: if(Session["emp_num"] != null) { if (!string.IsNullOrEmpty(Session["emp_num"].ToString())) { //The code } } Or just if(Session["emp_num"] != null) { // The code } because sometimes when i check only with: if (!string.IsNullOrEmpty(Session["emp_num"].ToString())) { //The code } I face the following exception: Null Reference exception 回答1: Use this if the session variable emp_num will store a string: if (!string

findViewById returns NULL when using Fragment

℡╲_俬逩灬. 提交于 2019-11-28 21:14:11
I'm new to Android developing and of course on Fragments. I want to access the controls of my fragment in main activity but 'findViewById' returns null. without fragment the code works fine. Here's part of my code: The fragment : <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" tools:ignore="HardcodedText" > <EditText android:id="@+id/txtXML" android:layout_width="fill_parent"

How do I break down a chain of member access expressions?

廉价感情. 提交于 2019-11-28 17:04:42
The Short Version (TL;DR): Suppose I have an expression that's just a chain of member access operators: Expression<Func<Tx, Tbaz>> e = x => x.foo.bar.baz; You can think of this expression as a composition of sub-expressions, each comprising one member-access operation: Expression<Func<Tx, Tfoo>> e1 = (Tx x) => x.foo; Expression<Func<Tfoo, Tbar>> e2 = (Tfoo foo) => foo.bar; Expression<Func<Tbar, Tbaz>> e3 = (Tbar bar) => bar.baz; What I want to do is break e down into these component sub-expressions so I can work with them individually. The Even Shorter Version: If I have the expression x => x

NullReferenceException when opening a subkey I know exists

南楼画角 提交于 2019-11-28 14:35:35
I'm trying to open a registry key so I can delete its subkeys: Dim asu As New System.Security.Principal.NTAccount(username.Text) Dim si As System.Security.Principal.SecurityIdentifier = asu.Translate(GetType(System.Security.Principal.SecurityIdentifier)) Dim MyReg As Microsoft.Win32.RegistryKey MyReg = Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, host.Text) _ .OpenSubKey("Software\Microsoft\Windows NT\currentVersion\ProfileList\" & si.ToString & "\") Dim myval As String myval = MyReg.GetValue("Guid") MsgBox(myval.ToString) ' retuns GUID no errors Dim

When would SqlCommand.ExecuteReader() return null?

感情迁移 提交于 2019-11-28 13:21:00
When using calling the SqlCommand.ExecuteReader() method, ReSharper tells me I have a possible NullReference exception when I use the SqlDataReader object afterwards. So with the following code: using (SqlConnection connection = GetConnection()) { using (SqlCommand cmd = connection.CreateCommand()) { cmd.CommandText = ; //snip using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { //snip } } } } The while (reader.Read()) line is underlined. My question is when would the reader object ever be null? I've never come across it and the documentation doesn't mention that it