I had an app that worked well in Debug. Then I switched to Release and built the solution. I got a prompt asking for things like "continue to debug" etc, and chose the one that deactivate "Just My Code" (note: I'm new in this).
I launched my .exe and my app gave me an exception in a place my code worked just fine these past 2 weeks.
The code in question:
private void DgDeliveryOrders_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
foreach (string piece in e.AddedItems)
{
Database.Pieces.Add(piece);
}
foreach (string piece in e.RemovedItems)
{
Database.Pieces.Remove(piece);
}
FillDetailsDataGrid();
}
Database.Pieces is a model property in my library project:
public static class Database
{
public static List<string> Pieces { get; set; }
}
I chose the static route because I used it in several places and it was easier (I don't know if it's the best practice, but it worked in Debug).
But then, each time I clicked on a item in my DataGrid, I got an exception: Object reference not set to an instance of an object. Plus something telling me things about optimized code. I switched back to Debug, it worked, no more errors. I switched again to Release, the same error is back. Breakpoints were acting funny (sometimes it stopped, sometimes not), and although I had the exception message, my ex was null.
After following some topics here, I checked that my solution was in Release for my 2 projets. I deactivated "Optimize" in the projets properties too. What did it change? Breakpoints not working at all.
So I checked again "Optimize", reactivated Just my Code and... my code isn't working in Debug anymore. Nor do the breakpoints.
I tried to reboot Visual Studio, but nothing changed.
At this point, I don't know what to do, it's the first time I do a release, what did I do wrong?
Thank you for reading.
UPDATE
The code problem was resolved in the comments, as for the VS problem, it solved itself after several reboot of the software/computer.