nullreferenceexception

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

拟墨画扇 提交于 2019-11-27 23:20:35
问题 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? 回答1: Go to Debug -> Exceptions -> Search

MVC5 Razor NullReferenceException in Model

二次信任 提交于 2019-11-27 23:04:07
问题 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

Using VB.NET IIF I get NullReferenceException

对着背影说爱祢 提交于 2019-11-27 21:00:43
I am doing a little debugging, and so I want to log the eventArgs value I have a simple line that basically does: logLine = "e.Value: " + IIf(e.Value Is Nothing, "", e.Value.ToString()) The way I understand the IIF function, if the e.Value is Nothing (null) then it should return the empty string, if not it should return the .ToString of the value. I am, however getting a NullReferenceException. This doesn't make sense to me. Any idea's? IIf is an actual function, so all arguments get evaluated. The If keyword was added to VB.NET 2008 to provide the short-circuit functionality you're expecting.

Why does this extension method throw a NullReferenceException in VB.NET?

允我心安 提交于 2019-11-27 20:30:56
From previous experience I had been under the impression that it's perfectly legal (though perhaps not advisable) to call extension methods on a null instance. So in C#, this code compiles and runs: // code in static class static bool IsNull(this object obj) { return obj == null; } // code elsewhere object x = null; bool exists = !x.IsNull(); However, I was just putting together a little suite of example code for the other members of my development team (we just upgraded to .NET 3.5 and I've been assigned the task of getting the team up to speed on some of the new features available to us),

Consuming JSON in WCF service method

大憨熊 提交于 2019-11-27 20:18:06
In a larger project I am having trouble getting a WCF service method to consume a JSON parameter. So I produced a smaller test case and the behaviour is echoed. If I debug the service I can see the parameter value is null at the service call. Fiddler confirms that the JSON is being sent and JsonLint confirms it is valid. Code below with annotations from debugging. [ServiceContract] public interface IWCFService { [OperationContract] [WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, UriTemplate = "getstring")] string GetString();

System.NullReferenceException in App_Web_*.dll

空扰寡人 提交于 2019-11-27 15:38:05
问题 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

findViewById returns NULL when using Fragment

对着背影说爱祢 提交于 2019-11-27 13:37:57
问题 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"

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

做~自己de王妃 提交于 2019-11-27 10:23:26
问题 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

Initializing list property without “new List” causes NullReferenceException

风格不统一 提交于 2019-11-27 09:39:58
using System; using System.Collections.Generic; class Parent { public Child Child { get; set; } } class Child { public List<string> Strings { get; set; } } static class Program { static void Main() { // bad object initialization var parent = new Parent() { Child = { Strings = { "hello", "world" } } }; } } The above program compiles fine, but crashes at runtime with Object reference not set to an instance of the object . If you notice in the above snippet, I have omitted new while initializing the child properties. Obviously the correct way to initialize is: var parent = new Parent() { Child =

NullReferenceException when opening a subkey I know exists

有些话、适合烂在心里 提交于 2019-11-27 08:51:08
问题 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 & "\"