I have a winforms file search application that runs with no errors in visual studio, but when i publish it i get a "object not set to an instance of object error"
The backgroundworker code which is the point where it fails is :
private void backGroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
e.Result = RunSearch();
PopulateUi((FilteredList)e.Result);
}
private void backGroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
try
{
var ans = (FilteredList)e.Result;
toolStripStatusLabel1.Text += "Folders found: " + ans.FolderCount + " | Files found: " + ans.FileCount;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
The messagebox shows the exception text.What do i need to do to correct this?
EDIT This question is different to the one referred to above as its about a concurrency issue and not simply an object being null. As stated above, the application runs with no errors before publishing.
thanks
Edit 2
I have tried creating a private object ( _x) in the class and assigning the result to it, but it still shows as null in the RunWorkerCompleted function. The edited code looks like this:
private void backGroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
e.Result = RunSearch();
_x = e.Result;
PopulateUi((FilteredList)e.Result);
}
private void backGroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
try
{
if (_x == null)
{
MessageBox.Show("e is null");
}
var ans = (FilteredList)_x;
toolStripStatusLabel1.Text += "Folders found: " + ans.FolderCount + " | Files found: " + ans.FileCount;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}