I have a Web API that is responsible for saving files to a network path (NFS), Every 50-60 calls i'm getting "Network path was not found", when even trying to validate the location:
Directory.CreateDirectory(path);
and also when trying to write files.
usually 2-3 tracking requests will receive this error and then it returns to normal.
Where path is a network location \\10.169.10.148\storage\
The location exists, and it's not a permission issue since I do manage to write to this location for most of the calls.
The error occurs on multiple endpoints, each trying to save files in a different way.
One is receiving a url and trying to download a remote file to the disk
using (WebClient webClient = new WebClient())
{
await webClient.DownloadFileTaskAsync(new Uri(video.FullPath), fullFilePath);
}
One is receiving the file itself:
using (Bitmap bmp1 = new Bitmap(fileContent.ReadAsStreamAsync().Result))
{
Directory.CreateDirectory(path);
ImageCodecInfo jpgEncoder = GetEncoder(ImageFormat.Jpeg);
System.Drawing.Imaging.Encoder myEncoder =
System.Drawing.Imaging.Encoder.Quality;
EncoderParameters myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 50L);
myEncoderParameters.Param[0] = myEncoderParameter;
bmp1.Save(filePath, jpgEncoder, myEncoderParameters);
}
And one is receiving a JSON string and writing it to a file:
public IHttpActionResult Post([FromBody] CreationJSON settings)
{
var location = Path.Combine(path, fileName);
File.WriteAllText(location, settings.JSON);
return Created(new Uri(location), fileName);
}
All try/catch and logging code was removed for clarity.
I receive around 20k requests per day, not a heavy load, and the error can occur after a few minutes of having no requests.
This Web API is written in C#, .NET 4.6 running on IIS 8.5 on a Windows Server 2012 R2 machine.
I'm aware of this similar question: C# The network path was not found
but it wasn't resolved.
Any help would be much appreciated.