Professional Web Applications Themes

nullreferenceexception - ASP.NET Data Grid Control

I'm having a hard time debugging a nullreferenceexception in my datagrid -- the exception occurs in 'System' .. so its hard to debug.. i can't seem to figure out where the update in my code is causing this nullreferenceexception ... when i break, the call stack looks like this: A first chance exception of type 'System.NullReferenceException' occurred in system.data.dll Additional information: Object reference not set to an instance of an object. the only thing i can tell by the call stack - is that the break happens at a different row each time! so i can't even narrow it down ...

  1. #1

    Default nullreferenceexception

    I'm having a hard time debugging a nullreferenceexception in my datagrid --
    the exception occurs in 'System' .. so its hard to debug..

    i can't seem to figure out where the update in my code is causing this
    nullreferenceexception ... when i break, the call stack looks like this:

    A first chance exception of type 'System.NullReferenceException' occurred in
    system.data.dll
    Additional information: Object reference not set to an instance of an object.

    the only thing i can tell by the call stack - is that the break happens at a
    different row each time! so i can't even narrow it down by row updated.

    How can i debug this??

    here is the call stack:


    system.data.dll!System.Data.DataColumnPropertyDesc riptor.GetValue(System.Object component = <undefined value>) + 0x29 bytes

    system.windows.forms.dll!System.Windows.Forms.Data GridColumnStyle.GetColumnValueAtRow(System.Windows .Forms.CurrencyManager
    source = {System.Windows.Forms.RelatedCurrencyManager}, int rowNum = 28) +
    0x83 bytes

    system.windows.forms.dll!System.Windows.Forms.Data GridTextBoxColumn.Paint(System.Drawing.Graphics
    g = {System.Drawing.Graphics}, System.Drawing.Rectangle bounds = {X=37 Y=544
    Width=74 Height=17}, System.Windows.Forms.CurrencyManager source =
    {System.Windows.Forms.RelatedCurrencyManager}, int rowNum = 28,
    System.Drawing.Brush backBrush = {Color={RGB=0x0}}, System.Drawing.Brush
    foreBrush = {Color={RGB=0x0}}, bool alignToRight = false) + 0x25 bytes

    system.windows.forms.dll!System.Windows.Forms.Data GridRelationshipRow.PaintCellContents(System.Drawi ng.Graphics
    g = {System.Drawing.Graphics}, System.Drawing.Rectangle cellBounds = {X=37
    Y=544 Width=74 Height=17}, System.Windows.Forms.DataGridColumnStyle column =
    {HeaderText="DISP_NAME"}, System.Drawing.Brush backBr = {Color={RGB=0x0}},
    System.Drawing.Brush foreBrush = {Color={RGB=0x0}}, bool alignToRight =
    false) + 0x2bd bytes

    system.windows.forms.dll!System.Windows.Forms.Data GridRow.PaintData(System.Drawing.Graphics
    g = {System.Drawing.Graphics}, System.Drawing.Rectangle bounds = {X=37 Y=544
    Width=753 Height=17}, int firstVisibleColumn = 0, int columnCount = 9, bool
    alignToRight = false) + 0x276 bytes

    system.windows.forms.dll!System.Windows.Forms.Data GridRelationshipRow.Paint(System.Drawing.Graphics
    g = {System.Drawing.Graphics}, System.Drawing.Rectangle bounds = {X=37 Y=544
    Width=753 Height=18}, System.Drawing.Rectangle trueRowBounds = {X=37 Y=544
    Width=753 Height=18}, int firstVisibleColumn = 0, int numVisibleColumns = 9,
    bool alignToRight = false) + 0x95 bytes

    system.windows.forms.dll!System.Windows.Forms.Data Grid.PaintRows(System.Drawing.Graphics
    g = {System.Drawing.Graphics}, System.Drawing.Rectangle boundingRect = {X=2
    Y=40 Width=788 Height=550}) + 0x38f bytes

    system.windows.forms.dll!System.Windows.Forms.Data Grid.PaintGrid(System.Drawing.Graphics
    g = {System.Drawing.Graphics}, System.Drawing.Rectangle gridBounds = {X=2
    Y=21 Width=788 Height=569}) + 0x1e2 bytes

    system.windows.forms.dll!System.Windows.Forms.Data Grid.OnPaint(System.Windows.Forms.PaintEventArgs
    pe = {ClipRectangle={X=2 Y=94 Width=788 Height=18}}) + 0x24d bytes

    system.windows.forms.dll!System.Windows.Forms.Cont rol.PaintWithErrorHandling(System.Windows.Forms.Pa intEventArgs
    e = {ClipRectangle={X=2 Y=94 Width=788 Height=18}}, short layer = 2, bool
    disposeEventArgs = false) + 0x85 bytes

    system.windows.forms.dll!System.Windows.Forms.Cont rol.WmPaint(System.Windows.Forms.Message m = {System.Windows.Forms.Message}) + 0x570 bytes

    system.windows.forms.dll!System.Windows.Forms.Cont rol.WndProc(System.Windows.Forms.Message m = {System.Windows.Forms.Message}) + 0x2d6 bytes

    system.windows.forms.dll!ControlNativeWindow.OnMes sage(System.Windows.Forms.Message m = {System.Windows.Forms.Message}) + 0x13 bytes

    system.windows.forms.dll!ControlNativeWindow.WndPr oc(System.Windows.Forms.Message m = {System.Windows.Forms.Message}) + 0xda bytes

    system.windows.forms.dll!System.Windows.Forms.Nati veWindow.DebuggableCallback(int
    hWnd = 134070, int msg = 15, int wparam = 0, int lparam = 0) + 0x3d bytes

    system.windows.forms.dll!System.Windows.Forms.Appl ication.ComponentManager.System.Windows.Forms.Unsa feNativeMethods+IMsoComponentManager.FPushMessageL oop(int dwComponentID = 1, int reason = -1, int pvLoopData = 0) + 0x349 bytes
    system.windows.forms.dll!ThreadContext.RunMessageL oopInner(int reason =
    -1, System.Windows.Forms.ApplicationContext context =
    {System.Windows.Forms.ApplicationContext}) + 0x1f3 bytes
    system.windows.forms.dll!ThreadContext.RunMessageL oop(int reason = -1,
    System.Windows.Forms.ApplicationContext context =
    {System.Windows.Forms.ApplicationContext}) + 0x50 bytes

    system.windows.forms.dll!System.Windows.Forms.Appl ication.Run(System.Windows.Forms.Form mainForm = {Collector.Form1}) + 0x34 bytes
    > RealTickTry2.exe!Collector.Form1.Main() Line 327 C#



    --
    Jon Oringer
    [url]http://www.shutterstock.com[/url]
    Jon Oringer Guest

  2. #2

    Default Re: nullreferenceexception



    Jon Oringer wrote:
    > I'm having a hard time debugging a nullreferenceexception in my
    datagrid --
    > the exception occurs in 'System' .. so its hard to debug..
    >
    > i can't seem to figure out where the update in my code is causing
    this
    > nullreferenceexception ... when i break, the call stack looks like
    this:
    >
    > A first chance exception of type 'System.NullReferenceException'
    occurred in
    > system.data.dll
    > Additional information: Object reference not set to an instance of an
    object.
    >
    > the only thing i can tell by the call stack - is that the break
    happens at a
    > different row each time! so i can't even narrow it down by row
    updated.
    >
    > How can i debug this??
    >
    > here is the call stack:
    >
    >
    >
    system.data.dll!System.Data.DataColumnPropertyDesc riptor.GetValue(System.Object
    component = <undefined value>) + 0x29 bytes
    >
    >
    system.windows.forms.dll!System.Windows.Forms.Data GridColumnStyle.GetColumnValueAtRow(System.Windows .Forms.CurrencyManager
    > source = {System.Windows.Forms.RelatedCurrencyManager}, int rowNum =
    28) +
    > 0x83 bytes
    >
    >
    system.windows.forms.dll!System.Windows.Forms.Data GridTextBoxColumn.Paint(System.Drawing.Graphics
    > g = {System.Drawing.Graphics}, System.Drawing.Rectangle bounds =
    {X=37 Y=544
    > Width=74 Height=17}, System.Windows.Forms.CurrencyManager source =
    > {System.Windows.Forms.RelatedCurrencyManager}, int rowNum = 28,
    > System.Drawing.Brush backBrush = {Color={RGB=0x0}},
    System.Drawing.Brush
    > foreBrush = {Color={RGB=0x0}}, bool alignToRight = false) + 0x25
    bytes
    >
    >
    system.windows.forms.dll!System.Windows.Forms.Data GridRelationshipRow.PaintCellContents(System.Drawi ng.Graphics
    > g = {System.Drawing.Graphics}, System.Drawing.Rectangle cellBounds =
    {X=37
    > Y=544 Width=74 Height=17}, System.Windows.Forms.DataGridColumnStyle
    column =
    > {HeaderText="DISP_NAME"}, System.Drawing.Brush backBr =
    {Color={RGB=0x0}},
    > System.Drawing.Brush foreBrush = {Color={RGB=0x0}}, bool alignToRight
    =
    > false) + 0x2bd bytes
    >
    >
    system.windows.forms.dll!System.Windows.Forms.Data GridRow.PaintData(System.Drawing.Graphics
    > g = {System.Drawing.Graphics}, System.Drawing.Rectangle bounds =
    {X=37 Y=544
    > Width=753 Height=17}, int firstVisibleColumn = 0, int columnCount =
    9, bool
    > alignToRight = false) + 0x276 bytes
    >
    >
    system.windows.forms.dll!System.Windows.Forms.Data GridRelationshipRow.Paint(System.Drawing.Graphics
    > g = {System.Drawing.Graphics}, System.Drawing.Rectangle bounds =
    {X=37 Y=544
    > Width=753 Height=18}, System.Drawing.Rectangle trueRowBounds = {X=37
    Y=544
    > Width=753 Height=18}, int firstVisibleColumn = 0, int
    numVisibleColumns = 9,
    > bool alignToRight = false) + 0x95 bytes
    >
    >
    system.windows.forms.dll!System.Windows.Forms.Data Grid.PaintRows(System.Drawing.Graphics
    > g = {System.Drawing.Graphics}, System.Drawing.Rectangle boundingRect
    = {X=2
    > Y=40 Width=788 Height=550}) + 0x38f bytes
    >
    >
    system.windows.forms.dll!System.Windows.Forms.Data Grid.PaintGrid(System.Drawing.Graphics
    > g = {System.Drawing.Graphics}, System.Drawing.Rectangle gridBounds =
    {X=2
    > Y=21 Width=788 Height=569}) + 0x1e2 bytes
    >
    >
    system.windows.forms.dll!System.Windows.Forms.Data Grid.OnPaint(System.Windows.Forms.PaintEventArgs
    > pe = {ClipRectangle={X=2 Y=94 Width=788 Height=18}}) + 0x24d bytes
    >
    >
    system.windows.forms.dll!System.Windows.Forms.Cont rol.PaintWithErrorHandling(System.Windows.Forms.Pa intEventArgs
    > e = {ClipRectangle={X=2 Y=94 Width=788 Height=18}}, short layer = 2,
    bool
    > disposeEventArgs = false) + 0x85 bytes
    >
    >
    system.windows.forms.dll!System.Windows.Forms.Cont rol.WmPaint(System.Windows.Forms.Message
    m = {System.Windows.Forms.Message}) + 0x570 bytes
    >
    >
    system.windows.forms.dll!System.Windows.Forms.Cont rol.WndProc(System.Windows.Forms.Message
    m = {System.Windows.Forms.Message}) + 0x2d6 bytes
    >
    >
    system.windows.forms.dll!ControlNativeWindow.OnMes sage(System.Windows.Forms.Message
    m = {System.Windows.Forms.Message}) + 0x13 bytes
    >
    >
    system.windows.forms.dll!ControlNativeWindow.WndPr oc(System.Windows.Forms.Message
    m = {System.Windows.Forms.Message}) + 0xda bytes
    >
    >
    system.windows.forms.dll!System.Windows.Forms.Nati veWindow.DebuggableCallback(int
    > hWnd = 134070, int msg = 15, int wparam = 0, int lparam = 0) + 0x3d
    bytes
    >
    >
    system.windows.forms.dll!System.Windows.Forms.Appl ication.ComponentManager.System.Windows.Forms.Unsa feNativeMethods+IMsoComponentManager.FPushMessageL oop(int
    dwComponentID = 1, int reason = -1, int pvLoopData = 0) + 0x349 bytes
    > system.windows.forms.dll!ThreadContext.RunMessageL oopInner(int
    reason =
    > -1, System.Windows.Forms.ApplicationContext context =
    > {System.Windows.Forms.ApplicationContext}) + 0x1f3 bytes
    > system.windows.forms.dll!ThreadContext.RunMessageL oop(int reason =
    -1,
    > System.Windows.Forms.ApplicationContext context =
    > {System.Windows.Forms.ApplicationContext}) + 0x50 bytes
    >
    >
    system.windows.forms.dll!System.Windows.Forms.Appl ication.Run(System.Windows.Forms.Form
    mainForm = {Collector.Form1}) + 0x34 bytes
    > > RealTickTry2.exe!Collector.Form1.Main() Line 327 C#
    >
    >
    >
    >
    > --
    > Jon Oringer
    > [url]http://www.shutterstock.com[/url]

    I think i figured it out - looks like i was calling a datagrid update
    method from another thread - without knowing i was on another thread. I
    had to use form.Invoke - works now.

    surfsecret@gmail.com Guest

  3. #3

    Default NullReferenceException

    Hi all,
    I am creating a web application on web matrix.I have a
    datagrid.I have the following code :
    DataTable dt=(DataTable)Session["DataGrid"];

    DataRow dr = dt.NewRow();

    DataView dv;
    First it was giving correct result.After that I run the same code then
    it is giving the following error message :

    Exception Details: System.NullReferenceException: Object reference not
    set to an instance of an object.

    for the line DataRow dr = dt.NewRow();

    what can be the problem??
    Any ideas???

    mohit Guest

  4. #4

    Default Re: NullReferenceException

    Error itself shows that there is no data in Session["DataGrid"]. Check if
    you save datatable to the Session before you retrieve it.



    HTH





    "mohit" <co.in> wrote in message
    news:googlegroups.com... 


    Elton Guest

Similar Threads

  1. NullReferenceException With Different Register Directive
    By Marvin Massih in forum ASP.NET Building Controls
    Replies: 0
    Last Post: March 23rd, 10:23 AM
  2. LoadPostData NullReferenceException
    By Jane Bell in forum ASP.NET Building Controls
    Replies: 1
    Last Post: March 5th, 03:13 PM
  3. DataBindings in child controls (NullReferenceException)
    By LucaP in forum ASP.NET Building Controls
    Replies: 0
    Last Post: June 4th, 02:33 PM
  4. Replies: 0
    Last Post: September 15th, 08:30 PM
  5. Help with System.NullReferenceException
    By msnews.microsoft.com in forum ASP.NET General
    Replies: 1
    Last Post: July 16th, 03:53 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139