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();
}
}
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 ?
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 ?
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.
Ok this time with Debug Mode enalbeld. Please see attachment
Enable debug mode in web.config to show the stack trace in the error dialog.
Please login first to submit.