Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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) // Close PLC ModBus Connection
            {
                MBDevice_RW2.Disconnect();
            }

            if (MBDevice_RW2.IsConnected) // Close PLC Modbus Connection
            {
                MBDevice_RW2.Disconnect();
            }

            if (myFtdiDevice.IsOpen) // Close RS232 Reader Connection
            {
                myFtdiDevice.Close();
            }

            WriteLog("Shutting down application", MessageLogType.Message);
            ArrImports.UnregisterApplicationRestart(); // Unregister Application Restart
        }
        catch (Exception)
        {
            // Do nothing
        }
    }
    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 :(
C#
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;
}
Posted
Updated 4-Nov-15 18:34pm
v4
Comments
Duncan Edwards Jones 4-Nov-15 7:34am    
1) Is there any error logged in the event viewer (run "eventvwr.exe" on the server)?

2) Are you closing down your application cleanly or killing it with task manager?

3) What 3rd party tools?
tslin89 4-Nov-15 21:07pm    
1) There are several errors in the EventViewer as shown below -
TerminalServices-Licensing, Report Server Windows Service, DNS-Server-Service, ESENT, HlpCtntMgr, Perflib, GroupPolicy, ADWS, TerminalServices-SessionBroker, Rdsm-UI, lphlpsvc, NetBT, TerminalServices-TSV-VmHostAgent, Service Control Manager, VSS, DistrubuctedCOM, MsiInstaller, Hyper-V-VMMS. I couldn't find anything related to my application. Or I do not know :(

2) I close down the application normally. I just added my Form-Closing method in the question. I also tried to close down using taskkill command from command line. But still the same.

3) 3rd party tools used in this project are -
(i) "FTD2XX_Net.dll" - Library to read data from FTDI Device which is used to convert RS232 to USB
(ii) "INGEAR.NET.MBLINK.dll" - MODBUS driver from Ingeardrivers to read/write PLC Modbus
(iii) "HCNetSDK.dll" - to capture HIKVision Network camera images
Suvendu Shekhar Giri 4-Nov-15 22:54pm    
I am not sure but I think form closing is taking more time to close. Try to debug and find which process is taking more time to finish. Then you can identify the issue.
tslin89 4-Nov-15 23:01pm    
Do you mean I should give more time to close the form?

This problem only occurred on server and I cannot debug on server as I only have 1 development license for INGEAR.NET.MBLINK.dll which is the main purpose of this application. But I will exclude that part and try to debug. Thanks.
phil.o 5-Nov-15 1:15am    
For remote debugging, you should have a look at Remote IIS Debugging. Good luck :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900