Hello everybody, Greeting!
I'm getting error "System.IO.FileNotFoundException: Could not load file or assembly 'xxx' or one of its dependencies. The system cannot find the file specified. File name 'xxx' ..... ". I've already googled this error for many hours and followed many suggestions like "Changing x64 to x32", "Clean", "Rebuild", etc... but still couldn't solve my problem. All the dlls exist in the application directory.
One thing weird is it only happen on my production server but not on my development computer.
My server specs is shown below -
Type: DELL Poweredge RS320
OS: Windows Server 2012 R2 Standard
Processor: Intel(R) Xeon(R) CPU E5-2430 v2 @ 2.5GHz
Memory: 16GB
HD: 1TB
Microsoft .Net Framework: 4.6
These are the steps to reproduce the problem on my server.
1. Build the project and copy all files from bin\debug to server.
2. Run my ApplicationName.exe - It works fine
3. Let the application run for few minutes
4. Close the application
5. Launch the application again - Error appeared (Not always. But 6 out of 10 tries have the issue)
When that happen, I tried to rebuild the project and copy new files and replace it on server, but still the same. Once it happened, I cannot launch the application anymore.
After that error occurred,
1) I also can't open many system applications on server like Device Manager, Administrative Tools, etc... When I click, I got nothing. They just don't open.
2) When I open SQL Server Configuration Manager, I got the error message "The instruction at 0x00e0ae20 reference memory at 0x000000058. The memory could not be read."
3) When I open ssms "SQL Server Management Studio", I got the error "Out of memory".
So, I suspect that my server have some memory issue. But there is only 16% of my server memory was used as I found that in Task Manager.
And here is the quick fix (but not correct solution for sure).
1. I have another application written in C# that used to read data from COM Port. That program also used one of the 3rd party dll used in my main application. I launch that program and start reading data from that COM Port for about 3 seconds. I close that program. After that, I can re-launch my main application again. Weird! I can also open "Device Manager", "Administrative Tools", etc... again.
2. Another quick fix is to launch Event Viewer. Just open the Event Viewer and my main application can launch again.
So, what could be the problem? Can .net program cause memory issue on server with 16GB of RAM?
My application is a quite complex and busy application. What it does is:
1) Read data from database and send signal to 2 LED Display using sockets every 300 milliseconds.
2) Read data from database and send signal to another 2LED Display using sockets every 5 seconds.
3) Read/Write data from 2 PLC Controllers every seconds.
4) Write Current Operation files into XML files from two different locations every 5 minutes.
5) Capture images from serveral network cameras and upload to server through webservice every 3 minutes.
6) Read data sent from COM Port every seconds and send to another LED Display using sockets.
7) Check PLC Connection every 3 seconds (we have some issue with PLC and this step cannot be skipped)
All above operations were based on timer. I currently have 9 window timers (I'm not sure it is good practise to use 9 timers in one application). Each timers used background workers or threads or threadpool.QueueUserWorkItem. Well, it is quite busy application. But why only problem on my server??? I've out of idea solving this thing.
Please advise what are the things to check, should I need to reduce timers and threads? Why it was solved after I run another C# application? Is there anything I need to check on server? I also check BIOS setting and it is in performance mode. Please advise me.
Sorry for the long post. I just want to explain everything I noticed related to this problem.
Thanks in advanced,
tslin
[Update]
When I close the application, I have FormClosing method to confirm user about Application Exit, and close connections to PLC Mod-Bus and COM Port Reader. This is my FormClosing Method.
private void FrmOperation_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("Are you sure to close this?", "Service Stop Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
try
{
if (MBDevice_RW1.IsConnected)
{
MBDevice_RW2.Disconnect();
}
if (MBDevice_RW2.IsConnected)
{
MBDevice_RW2.Disconnect();
}
if (myFtdiDevice.IsOpen)
{
myFtdiDevice.Close();
}
WriteLog("Shutting down application", MessageLogType.Message);
ArrImports.UnregisterApplicationRestart();
}
catch (Exception)
{
}
}
else
{
e.Cancel = true;
}
}
[Update 2]
I just created a new simple windows form with one data gridview and one button. Button click is shown below. It create a datatable, add a row to it and bind to datagridview. This few lines of code also is solving the problem. After I run this program and click on that button, it is working again (i.e. my main application can start again, Device Manager, SQL Server Mangement Studios, etc... can call again). I feel like something was not completed in the memory until another thing invoked :(
private void button1_Click(object sender, EventArgs e)
{
DataTable l_Table = new DataTable();
l_Table.Columns.Add("Description");
l_Table.Rows.Add(new string[] { "Hello world" });
dgvData.AllowUserToAddRows = false;
dgvData.AllowUserToDeleteRows = false;
dgvData.DataSource = l_Table;
}