nullreferenceexception

Fully-qualified property name

笑着哭i 提交于 2019-11-28 12:14:53
问题 I'm trying to prevent System.NullReferenceException. I have a Company, which has a collection of Employees. Each Employee has a collection of Skills. SelectedEmployee points to the currently selected element within the Employee collection. SelectedSkill points to the currently selected element within the collection of Skills. I have a ListView that has its ItemSource bound to the Skills collection; The ListView's SelectedItem is bound to the SelectedSkill. When a Skill is deleted I want the

How to ignore property of property in AutoMapper mapping?

时光毁灭记忆、已成空白 提交于 2019-11-28 11:45:13
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; set; } } public class PersonDTO { public string Name { get; set; } public List<GroupDTO> Groups { get;

WebBrowser control throws seemingly random NullReferenceException

我与影子孤独终老i 提交于 2019-11-28 10:39:06
For a couple of days I am working on a WebBrowser based webscraper. After a couple of prototypes working with Threads and DocumentCompleted events, I decided to try and see if I could make a simple, easy to understand Webscraper. The goal is to create a Webscraper that doesn't involve actual Thread objects. I want it to work in sequential steps (i.e. go to url, perform action, go to other url etc. etc.). This is what I got so far: public static class Webscraper { private static WebBrowser _wb; public static string URL; //WebBrowser objects have to run in Single Thread Appartment for some

How do I enforce null checking?

試著忘記壹切 提交于 2019-11-28 09:09:45
I'm working on a large project where, even with 10s of 1000s of automated tests and 100% code coverage, we're getting a ridiculous number of errors. About 95% of errors we get are NullReferenceExceptions. Is there any way to enforce null-checking at compile time? Barring that, is there any way to automagically enforce null-checking in unit tests without having to write the tests for null cases myself? You should look into Code Contracts . The static checker is only available for the higher-end VS editions, but that's basically what you're after. There are plenty of resources online, and <plug>

Why does ResourceManager.GetResourceSet return null on the first request after a build? (C#)

蹲街弑〆低调 提交于 2019-11-28 07:02:33
问题 I'm working on a large-ish web application built in C# (asp.net). I've got a simple aspx page that serves localized strings to the client browser for use in javascript controls. To get the strings, I do the following: ResourceManager _resources = new ResourceManager(_pathname, typeof(ARM).Assembly); ResourceSet rs = _resources.GetResourceSet(culture, false, false); //loop through rs and write the keys & values out to the client in plaintext This all works fine, except for the first request to

httpcontext.current.server.mappath Object reference not set to an instance of an object

不想你离开。 提交于 2019-11-28 06:14:57
I am using the following code within a class: string filePath = HttpContext.Current.Server.MapPath("~/email/teste.html"); The file teste.html is in the folder But when it will open the file the following error is being generated: Object reference not set to an instance of an object. Don't use Server.MapPath. It's slow. Use this instead, HttpRuntime.AppDomainAppPath . As long as your web site is running, this property is always available to you. Then use it like this: string filePath = Path.Combine(HttpRuntime.AppDomainAppPath, "email/teste.html"); if the code is not running from within a

EmguCV - Face Recognition - 'Object reference not set' exception when using training set from Microsoft Access Database

我的梦境 提交于 2019-11-28 05:57:49
问题 I've been developing a face recognition application using EmguCV (C#). I got the whole thing working okay if I store the face images (training set) in simple windows folder. But, after I tried to migrate the face images to be stored in a Microsoft Access database, an 'object reference not set to an instance of an object' exception message often occurs (not always, but most of the time) when the application tries to recognize a face from the video feed. Funny thing is, the recognition actually

Why is casting a dynamic of type object to object throwing a null reference exception?

孤者浪人 提交于 2019-11-28 03:32:20
I have the following function: public static T TryGetArrayValue<T>(object[] array_, int index_) { ... //some checking goes up here not relevant to question dynamic boxed = array_[index_]; return (T)boxed; } When I call it in the following way, object a = new object(); object v = TUtils.TryGetArrayValue<object>(new object[] { a }, 0); (T)boxed throws a null reference exception. Any other type I put in there other than "object", it works perfectly fine. Any ideas what this is, and why it's throwing the exception? Edit: The reason why I use dynamic is to avoid exception when converting types, for

Getting the variable name for NullReferenceException

大兔子大兔子 提交于 2019-11-28 01:10:15
问题 Stack traces for NullReferenceException is very uninformative, they just include the method name and the call stack. Any variable in a method can be null and it's hard to debug when the bug isn't reproducible on the dev machine. Do you know a way to get more info on that error, getting the variable name perhaps? Or do you have better ways to debug it? 回答1: Keeping track of that name is not always possible (it could be an expression). And where it is possible it would incur unacceptable

LINQ InsertOnSubmit: NullReferenceException

浪子不回头ぞ 提交于 2019-11-28 00:43:45
I have this code: using DC = MV6DataContext; using MV6; // Business Logic Layer // ... public DC.MV6DataContext dc = new DC.MV6DataContext(ConnectionString); IP ip = new IP(Request.UserHostAddress); dc.IPs.InsertOnSubmit(ip); dc.SubmitChanges(); // in Business Logic layer: public class IP : DC.IP { public IP(string address) { ... } } Upon attempting to InsertOnSubmit(ip), I get a NullReferenceException (Object reference not set to an instance of an object). dc is not null; ip and all properties of ip are not null; though some are empty. VS2008 won't let me step into InsertOnSubmit, so I have