NullReferenceException only Live not in development environment

0
0

Hi all,

i have an strange error and i don`t find an solution for this.

My Code is running great in development. But when i publish it i get an NullReferenceException.

I hope someone can help.

This is the Code:


private void lblDragSource_MouseDown(object sender, MouseEventArgs e)
{
Label clickedLabel = sender as Label;

movingRoom = (SplitterPanel)clickedLabel.Parent;
startingRoom = movingRoom.Parent as SplitContainer;

if (e.Button == MouseButtons.Left)
{
clickedLabel.DoDragDrop(clickedLabel.Text,
DragDropEffects.Move);
}
if (e.Button == MouseButtons.Right)
{
SplitterPanel splitterPanel = clickedLabel.Parent as SplitterPanel;
GroupBox currentRoom = splitterPanel.Parent.Parent as GroupBox;
DatabaseRoom currentDbRoom = rooms.Where(r => r.name == currentRoom.Text).FirstOrDefault();
Employee employeeToRemove = currentDbRoom.employees.Where(em => em.angName == clickedLabel.Text).FirstOrDefault();
if (employeeToRemove != null)
{
currentDbRoom.employees.Remove(employeeToRemove);
employeeToRemove.removeFromRoom();
}
updateRooms();
}
}


 

Attachment
  • You must to post comments
0
0

Will do but why the hell i don`t get the same error in Visual Studio ?

When i start the app there everything is working great. Same Browser etc………

If one of them would return null wouldn`t i get the same error in VS ?

 

  • You must to post comments
0
0

Will do but why the hell i don`t get the same error in Visual Studio ?

When i start the app there everything is working great. Same Browser etc………

If one of them would return null wouldn`t i get the same error in VS ?

 

  • Luca
    • Luca
    • Mar 5, 2021 - 3:03 pm
    The browser is not related. I don’t know your deployment, could be different files, etc. You can attach VS to the web server and see.
  • Tom Oeben
    Ok the error is here: movingRoom = (SplitterPanel)clickedLabel.Parent; The Label has NO Parent. In Visual Studio it has. Live it has not…..getting mad over it :)
  • Tom Oeben
    Btw same files. I publish from Visual Studio over webDeploy to the server
  • You must to post comments
0
0

So now you know that  the NullReference is in lblDragSource_MouseDown, which you already knew. Looking at your code, these are the only possible places, since NullReferenceException is not caused by Wisej:

 

Label clickedLabel = sender as Label;
movingRoom = (SplitterPanel)clickedLabel.Parent; <-- clickedLabel can be null if the cast above is wrong. Change to a cast or check what the sender is.

If clickedLabel is not null, then:

SplitterPanel splitterPanel = clickedLabel.Parent as SplitterPanel;
GroupBox currentRoom = splitterPanel.Parent.Parent as GroupBox; <-- if the parent of clickedLabel is not a SplitterPanel you get null. Change to a cast or check.

DatabaseRoom currentDbRoom = rooms.Where(r => r.name == currentRoom.Text).FirstOrDefault(); <-- Same as above.



Basically looks like one of the “as” conditional casts fails returning null. Change it to a cast and it will generate an InvalidCastException.

 

  • You must to post comments
0
0

Ok this time with Debug Mode enalbeld. Please see attachment

  • You must to post comments
0
0

Enable debug mode in web.config to show the stack trace in the error dialog.

  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.