nullreferenceexception

GetAdornerLayer mysteriously returning null

会有一股神秘感。 提交于 2019-12-01 03:21:20
I've been using the same bit of code for several versions of my app with no problems, but I'm now mysteriously receiving NullRerefenceException s with the following: this.Loaded += delegate { deleteBrush = new DeleteBrushAdorner( background ); AdornerLayer al = AdornerLayer.GetAdornerLayer( background ); al.Add( deleteBrush ); // null ref here?? }; background is just a Border element. My two thoughts on what could be causing it are a) switching to .NET 4.0, and b) placing instances of the above element (which is a UserControl ) in an ItemsControl . Oddly this doesn't happen all the time, and

WPF - Saving font to disk, then instantiating GlyphTypeface for font throws exception. Why?

江枫思渺然 提交于 2019-12-01 03:04:23
问题 I am mucking about with WPF glyphs and documents and have run into a null reference exception in the .Net 4 framework. I extract and save true-type fonts to disk as .ttf files, then try to create Glyphs based on the fonts. The first time I save a font to disk and instantiate a GlyphTypeface based on the font after creating a GlyphTypeface from another font in the same folder I get a null reference exception. Say I have fonts A and B. B has not been saved to disk (A may or may not have been

Null reference in web api call

扶醉桌前 提交于 2019-11-30 22:31:49
This is a weird one, and I'm at a loss to understand what's going on here. I have a web api project that in one controller a call to a certain method eventually calls a function in a service that looks like this: public MyClassBase GetThing(Guid id) { if (cache.ContainsKey(id)) { return cache[id]; } else { var type = typeof(MyClassBase).Assembly.GetTypes().FirstOrDefault ( t => t.IsClass && t.Namespace == typeof(MyClassBase).Namespace + ".Foo" && t.IsSubclassOf(typeof(MyClassBase)) && (t.GetCustomAttribute<MyIdAttribute>()).GUID == id ); if (type != null) { System.Diagnostics.Debug.WriteLine

How to check for null in nested references

独自空忆成欢 提交于 2019-11-30 20:34:55
Looking for some best-practice guidance. Let's say I have a line of code like this: Color color = someOrder.Customer.LastOrder.Product.Color; where Customer, LastOrder, Product, and Color could be null under normal conditions. I'd like color to be null if any one of the objects in the path is null, however; in order to avoid null reference exceptions, I'd need to check for the null condition for each one of the objects, e.g. Color color = someOrder == null || someOrder.Customer == null || someOrder.Customer.LastOrder == null || someOrder.Customer.Product == null ? null : someOrder.Customer

Why does Entity Framework return null List<> instead of empty ones?

大城市里の小女人 提交于 2019-11-30 16:54:38
I'm pretty new in the ASP .NET MVC world. Maybe, that's the reason I can't explain to myself the cause of what is, for me, an annoying problem. I have one class with One-To-Many relashionship. class MyClass{ public List<OtherClass> otherClasses {get;set;} } When I'm persisting one instance of this class, I fill it's relationship with an empty List<> MyClass myClass = new MyClass(){ otherClasses = new List<OtherClass>() } context.myClass.Add(myClass); The problem is that, when I try to retrieve that instance, and for any reason, I try to access that list, system gives me a Null Reference

How to solve Object reference not set to an instance of an object.? [duplicate]

99封情书 提交于 2019-11-30 16:47:19
This question already has an answer here: What is a NullReferenceException, and how do I fix it? 31 answers In my asp.net program.I set one protected list.And i add a value in list.But it shows Object reference not set to an instance of an object error protected List<string> list; protected void Page_Load(object sender, EventArgs e) { list.Add("hai"); } How to solve this error? You need to initialize the list first: protected List<string> list = new List<string>(); I think you just need; List<string> list = new List<string>(); list.Add("hai"); There is a difference between List<string> list;

Why is [Owin] throwing a null exception on new project?

孤人 提交于 2019-11-30 11:44:09
问题 I have a rather strange issue i'm not sure how to fix or if i can even fix it. I've done some research into the issue but can't find an answer to what's causing it. I'm following a rather simple guide at http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on and after enabling SSL and changing the controller to require https i get the following error: Server Error in '/' Application. Object reference not set to an instance of an

How can a readonly static field be null?

爷,独闯天下 提交于 2019-11-30 08:11:08
So here's an excerpt from one of my classes: [ThreadStatic] readonly static private AccountManager _instance = new AccountManager(); private AccountManager() { } static public AccountManager Instance { get { return _instance; } } As you can see, it's a singleton-per-thread - i.e. the instance is marked with the ThreadStatic attribute. The instance is also instantiated as part of static construction. So that being the case, how is it possible that I'm getting a NullReferenceException in my ASP.NET MVC application when I try to use the Instance property? Quoting MSDN ThreadStaticAttribute : Do

How to ignore property of property in AutoMapper mapping?

天涯浪子 提交于 2019-11-30 05:58:10
问题 Image a Person and a Group class with a many-to-many relationship. A person has a list of groups and a group has a list of people. When mapping Person to PersonDTO I have a stack overflow exception because AutoMapper can't handle the Person > Groups > Members > Groups > Members >... So here's the example code: public class Person { public string Name { get; set; } public List<Group> Groups { get; set; } } public class Group { public string Name { get; set; } public List<Person> Members { get;

Android - null object reference when iterating List

戏子无情 提交于 2019-11-30 04:50:42
问题 I'm trying to copy a List 'usrs' which is created in an Inner class to a different list 'team_memebers'. After copying I try to iterate 'team_memebers' in the FOR loop, but I get a 'null object reference' error. The 'users' list contains the returned objects, tested via debug prints. public class ListNodeActivity extends AppCompatActivity { private ParseObject parse_task=null; private List<String> team_memebers=null; @Override protected void onCreate(Bundle savedInstanceState) { super