WriteFile error 0x80004005 on Azure Websites - c#

I have a simple website running on Azure Websites. It's using native code that basically writes into file when called. Everything works fine, most of the time. But sometimes (as far as I observe it's random - once a week to once a month) I got error 0x80004005:
(0x80004005): I/O error during "WriteFile" operation for file "C:\DWASFILES\SITES\***\VIRTUALDIRECTORY0\SITE\WWWROOT\APP_DATA\***"
Error while trying to write to file ---> I/O error during "WriteFile" operation for file "C:\DWASFILES\SITES\***\VIRTUALDIRECTORY0\SITE\WWWROOT\APP_DATA\***"
Error while trying to write to file
If I stop the application and start it again in a one or two seconds everything is back to normal.
The application is running in shared mode.
Any idea what's wrong? Or what to try to pinpoint the problem?

Related

System.IO.Copy operation intermittently giving Access Denied Error in .Net 4.0 C# Console Application

I have a console application written in .Net framework 4.0 C#. In the application I am copying a file from one location of the server to another location.
Here is the code:
System.IO.File.Copy("sourceFile","destFile",true);
I have created a Windows scheduler which executes the console app everyday at a particular time.
The code works perfectly fine if I run it manually. However it intermittently gives below access denied error (say once in every 10 times) while running it through scheduler.
Error Message: Access to the path "destFile" is denied. Other information(if any)
Stack Trace: at Syste.IO._Error.WinIOError(Int32 errorCode, String maybeFullPath) at Syste.IO.File.InternalCopy(String sourceFileName, String destFileName,Boolean overwrite,Boolean checkHost) at System.IO.File.Copy(String sourceFileName,String destFileName,Boolean overwrite)
I tried to reproduce the error in other lower environment servers (Dev/Test), but the issue could not be reproduced. Have already deleted the task scheduler and created fresh ones many times, but no luck. The issue gets fixed once I rerun the code as it is totally intermittent in nature. Permission to the source and destination location is already given because of which it works fine 9/10 times.
Pls advise if you see any issue or need additional information for further troubleshooting.
Give a look to the application user permissions, probably the user which you are using to run your application, misses the permissions to write in your desired path.
Noticed that you turned on overwrite option. If one of the dest files(being overwritten) are opened by other applications, you will get some error messages.

I am getting error while moving file to NAS path

I have a web application to upload file. Application first store file to local server and then move to NAS path. Application is using System.IO.File.Move method of C# to move file from local server to NAS.
I am seeing strange issue. After login to application first upload works fine. but if upload another file immediately,it fails. If I wait for 3-5 minutes after a file upload and try to upload file again. it works.
I have tested the connectivity from local server to NAS, it is fine.
Same web application was running on another server, we have stopped application on that server and moved to this server. This issue is happening only on new server not on old server.
Error message:The specified network name is no longer available.
Line of code which throw error: File.Move(sourceFilePath,DestinationFilePath)
Also I was trying to see if connection to NAS path has issue. So what I did is that just before the line of code which is throwing error I added a condition:
If(!File.Exist(DestinationFilePath)){ throw new Exception(<some message>)
After adding this check application is working fine. I am not sure how?

File gets "locked" while moving operation and iis give 401 error

I have a windows service run with local system account
What my program does is :
if (File.Exists(outputPath))
{
File.Delete(outputPath);
}
File.Move(archivePath, outputPath);
Relevant folder is application folder of iis where its application pool's identity is ApplicationPoolIdentity located under c:\MyAppFolder.
My windows service does its few times a day, and my clients checks if any new version exists every 5 minutes(0,5,10,15...) and download that file.
Time to time, file is somehow get "locked" on filesystem then
iis gives 401 error
File cannot be deleted
My first question how can I repro this situation?
One patch is done by colleagues is:
var fs = File.GetAccessControl(outputPath);
fs.SetAccessRuleProtection(false, false);
File.SetAccessControl(outputPath, fs);
Although this patch, it seems error occured again,
I may apply, this solution as well.
Are those solutions are enough or necessary?
Again my first question is important "repro issue" and understand why this happens.

Inaccessible logs: Security. The source was not found, but some or all event logs could not be searched

I am assuming it has something to do with my app pool/IIS but why is this error only being thrown while in Production?
To Start- I have read every related question about this topic on SO.
I cannot reproduce this error in my Dev and/or Test environments. I have sent hundreds of POST requests using postman(DEV), I have also used my iOS application pointing to my Test Environment and sent thousands of requests and I am still in the same boat.
About my Project: I am using WebAPI and my application is running on iOS10 written in swift. I only receive this error occasionally and cannot reproduce it on command. I am wondering if anyone else has run into this issue and if so, what were the steps you took to take care of this problem?
Error #1
The source was not found, but some or all event logs could not be searched.
To create the source, you need permission to read all event logs to make
sure that the new source name is unique. Inaccessible logs: Security.
Note: This error is not causing me to lose any data when I receive it, all records are still being committed to my database. So it is not a huge issue since I only get the error 1 out of about 100 times a new record is submitted. But curiosity is killing me and wanted to see if anyone had any suggestions.

C# COM application crash debugging

The C# console application running .NET 4.5.2 (app1) opens a COM application (app2) and does some work with that app2's API. So far all of the work is successful, but sometimes when app1 attempts to close app2, app2 hangs permanently.
If the process for app2 is ended with task manager then app1 reports access denied. Does that occur because the terminated process is no longer available or does it occur because it was blocking a thread in app1 and it was unable to report the error until the thread was allowed to continue?
The code used to terminate app2 is
private static void CloseSW(SldWorks swApp, Process sw_proces)
{
// Close with API call
if (Task.Run(() => { swApp.CloseAllDocuments(true); swApp.ExitApp(); }).Wait(TimeSpan.FromSeconds(20)))
return;
// Kill process if API call failed
if (Task.Run(() => { SWHelper.CloseSW(sw_proces); }).Wait(TimeSpan.FromSeconds(20)))
return;
// Unable to close SolidWorks, ignore error and continue
// This will eventually cause SolidWorks to crash and the crash handler will take over
}
This code should never take much more than 40 seconds to complete, but maybe the COM interop is causing some unexpected behaviour?
I am unable to reproduce this error on a development machine. What it the best way to trace the exact point of failure? It is possible that the failure is not in CloseSW but some point before this. Is there a better way to trace the error than to write each line to a log file?
It is also worth noting that this code works for 60 - 150 runs before it has any errors and both applications are closed between each run.
I have control of the remote environment so remote debugging is an option, but I've never set that up before.
Typically with COM interops causing issues is that IIS is having issues with the object using the current ISAPI.dll. Please verify that your permissions are configured within your assembly to work with your current version of IIS>
A few questions to help assist would be, which framework version are you using, which version of IIS and what is your Application Pool using for a framework.
HTH

Categories