nullreferenceexception

Disposing the members that implement IDisposable

我怕爱的太早我们不能终老 提交于 2020-01-02 01:47:08
问题 In my Dispose methods (like the one below), everytime i want to call someObj.Dispose() i also have a check for someObj!=null. Is that because of bad design on my part? Is their a cleaner way to ascertain that Dispose of all the members (implementing IDisposable) being used in an object is called without having a risk of NullReference exception ? protected void Dispose(bool disposing) { if (disposing) { if (_splitTradePopupManager != null) { _splitTradePopupManager.Dispose(); } } } Thanks for

NullReferenceException WIA C#

寵の児 提交于 2019-12-31 05:49:07
问题 When I run the code below I get this error NullreferenceException was unhandled.. below is my code private void showScannerDialog() { this.scanner = null; this.imageItem = null; this.getScanner(); WIA.CommonDialog dialog = new WIA.CommonDialog(); Items imageItems = dialog.ShowSelectItems(this.scanner, WiaImageIntent.TextIntent, WiaImageBias.MinimizeSize, false, true, false); if (imageItems != null) { foreach (Item item in imageItems) { imageItem = item; break; } } } thanks // complete code

How to get result of Null Reference Analysis into a log file

若如初见. 提交于 2019-12-31 03:09:08
问题 I have following classes. class Tim { public Tim() { } public Tom GetTom() { return new Tom(); } } class Tom { public Tom() { } public Jim GetJim() { return new Jim(); } } class Jim { public Jim() { } public Jom GetJom() { return null; } } class Jom { public Jom() { } public string GetMagicString() { return "Hello World"; } } Its used as follows. class Program { static void Main(string[] args) { new Tim().GetTom().GetJim().GetJom().GetMagicString(); } } When I run it, a Null Reference

GetAdornerLayer mysteriously returning null

青春壹個敷衍的年華 提交于 2019-12-30 08:11:51
问题 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

GetAdornerLayer mysteriously returning null

醉酒当歌 提交于 2019-12-30 08:11:36
问题 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

Null reference in web api call

China☆狼群 提交于 2019-12-30 06:59:09
问题 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

NullReferenceException in string.IsNullOrWhiteSpace() and string.IsNullOrEmpty()

好久不见. 提交于 2019-12-25 16:32:38
问题 I'm checking the cell values of cells of a column that might or not be empty/null so I needed something to avoid a NullReferenceException . How do I do that since even with the IsNullOrWhiteSpace() and IsNullOrEmpty() I get that exception somehow. Here's part of the code I'm using: s = "Total = " + dataGridView1.Rows[0].Cells.Count + "0 = " + dataGridView1.Rows[0].Cells[0].Value.ToString() + "/n 1 = " + dataGridView1.Rows[0].Cells[1].Value.ToString() + "/n 2= " + dataGridView1.Rows[0].Cells[2

NullReferenceException in string.IsNullOrWhiteSpace() and string.IsNullOrEmpty()

会有一股神秘感。 提交于 2019-12-25 16:31:29
问题 I'm checking the cell values of cells of a column that might or not be empty/null so I needed something to avoid a NullReferenceException . How do I do that since even with the IsNullOrWhiteSpace() and IsNullOrEmpty() I get that exception somehow. Here's part of the code I'm using: s = "Total = " + dataGridView1.Rows[0].Cells.Count + "0 = " + dataGridView1.Rows[0].Cells[0].Value.ToString() + "/n 1 = " + dataGridView1.Rows[0].Cells[1].Value.ToString() + "/n 2= " + dataGridView1.Rows[0].Cells[2

“NullReferenceException was unhandled by user code” [duplicate]

本小妞迷上赌 提交于 2019-12-25 09:45:10
问题 This question already has answers here : What is a NullReferenceException, and how do I fix it? (29 answers) Closed 5 years ago . I was having some issues the other day with my interface lagging and after asking here someone suggested using a using statement to dispose of the webbrowser. Now after implementing it I keep getting: NullReferenceException was unhandled by user code- Object reference not set to an instance of an object. I am having a weird issue because even if I am running code

Trying to update control and getting NullReferenceException

Deadly 提交于 2019-12-25 08:23:02
问题 i got answer to my last problem related to my mini project: when i tried to update image control from other thread i got error: Trying to update image control source from other tread and getting Error- enter link description here but now i got NullReferenceException at this line: item.Dispatcher.Invoke(new Action(() => image1.Source = item)); from some reason and i dont know why? the code: public partial class MainWindow : Window { BlockingCollection<BitmapSource> pictures = new