nullreferenceexception

Dictionary TryGetValue NullReferenceException [closed]

孤街浪徒 提交于 2019-12-10 17:37:21
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I am getting NullReferenceException at the _dicCache.TryGetValue(objID, out newObject); line. And I have no Idea why this is happening at all. Can

Visual Studio Debugger exception on launch

☆樱花仙子☆ 提交于 2019-12-10 16:55:32
问题 When launching my WinForms project (project only contains one source file, Program.cs), the debugger breaks with no stack trace on the following exception: System.ArgumentNullException was unhandled Message="Value cannot be null.\r\nParameter name: activationContext" Source="mscorlib" ParamName="activationContext" StackTrace: at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData) at System.Runtime.Hosting

NHibernate JoinAlias query with null test not working

…衆ロ難τιáo~ 提交于 2019-12-10 16:15:59
问题 I'm getting some unexpected behaviour with a JoinAlias QueryOver in NHibernate. My entity essentially looks like this: public class Field { public virtual long Id { get; protected set; } public virtual Field Parent { get; protected set; } public virtual FieldType Type { get; protected set; } public virtual string Value { get; protected set; } ...(Ctors etc } My mapping is such: public class FieldMap : ClassMap<Field> { public FieldMap() { Id(x => x.Id) .GeneratedBy.Native(); References(x => x

Should NullRefs ever be caught?

我们两清 提交于 2019-12-10 16:06:53
问题 I recently made the statement to a colleague that: NullReferenceExceptions should never be explicitly caught I used the word never.... hmmm. I've never seen a appropriate use case myself for catching them but I wanted to check if anyone else has? Never is such a strong word after all..... 回答1: It depends on why; see Eric Lippert's blog entry. If they are "boneheaded exceptions", then no - just fix the calling code. In the rare case that they are "vexing exceptions" (i.e. the code you are

CIL unbox_any instruction - strange behavior

為{幸葍}努か 提交于 2019-12-10 14:06:35
问题 .method public static void Test<class T>(object A_0) cil managed { // Code size 13 (0xd) .maxstack 1 .locals init (!!T V_0) IL_0000: ldarg.0 IL_0001: isinst !!T IL_0006: unbox.any !!T IL_000b: stloc.0 IL_000c: ret } // end of method DemoType::Test The equal C# code is: public static void Test<T>(object o) where T : class { T t = o as T; } My questions are: Why unbox.any been called? if you just do var a = father as child isinst intruction will call and no unbox.any, and If i'll remove the

Object reference not set to an instance of object when using a List<T> in C# [duplicate]

余生颓废 提交于 2019-12-10 13:45:15
问题 This question already has answers here : What is a NullReferenceException, and how do I fix it? (29 answers) Closed 5 years ago . I have the following code snippet that produces a compilation error: public List<string> batchaddresses; public MapFiles(string [] addresses) { for (int i = 0; i < addresses.Count(); i++) { batchaddresses.AddRange(Directory.GetFiles(addresses[i], "*.esy")); } } I get an error when I try to use the List<T>.AddRange() method: Object reference not set to an instance

How to make a wpf MediaElement play when its Source is a https uri

社会主义新天地 提交于 2019-12-10 13:38:36
问题 In a wpf standalone application (.exe) I have included a MediaElement in the MainWindow <Window x:Class="Media.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Main Window" Height="350" Width="525"> <Grid> <MediaElement x:Name="Player" Stretch="Uniform" LoadedBehavior="Manual" UnloadedBehavior="Stop"/> </Grid> </Window> and from the code behind I set its Source to any https Uri: public partial class

Cascading null reference exception check?

自作多情 提交于 2019-12-10 10:55:24
问题 Is there a way to do a generic cascading null reference check in c#? What i am trying to achieve is if i am trying to access a string variable which is part of a class C, which is inturn in class B, which is in A. A.B.C.str And that i am passed in A, i will have to check to see if A is null, then check if B is null, then check is C is null and then access str. Is it possible to have some method where - we can potentially pass in, A and A.B.C.str and it return null is anything was null or

Calling a method from within a Class

牧云@^-^@ 提交于 2019-12-10 10:13:03
问题 I have 2 Forms (Form1 and Form2) and a class (Class1). Form1 contains a button (Button1) and Form2 contains a RichTextBox (textBox1) When I press Button1 on Form1, I want the method (DoSomethingWithText) to be called. I keep getting "NullReferenceException - Object reference not set to an instance of an object". Here is a code example: Form1: namespace Test1 { public partial class Form1 : Form { Form2 frm2; Class1 cl; public Form1() { InitializeComponent(); } private void button1_Click(object

Null reference exception when generating a url with UrlHelper.Action method

老子叫甜甜 提交于 2019-12-09 07:58:59
问题 For some reason, when certain bots visit the site, generating a url with the UrlHelper.Action method raises a null exception from System.Web.HttpServerVarsCollection.Get . I've done some debugging and the call stack originiates with an attempt to get the 'HTTP_X_ORIGINAL_URL' from the HttpContextBase.Request.ServerVariables collection. If I visit the same address directly from a browser - no problem. The page is server and no error is logged. It only seems to occur when visited by a bot. Not