'Network share file access works with one solution but not another

I have two completely separate and unique solutions in C# in Visual Studio, both of which are using the same section of code below to access the same file on a network share. The projects are both running from the same server under the same local credentials, which are different credentials than the network one used in the solutions.

One of the projects reads the file perfectly fine. But with the second one, I'm getting an "incorrect user name or password" error when it tries to access the file. From the local server, I have access to the network share and the file, both when using the local credentials and the network credentials.

I've tried pointing the failing process to a different file in that same network share but get the same error. If I copy the text file to the local server where the process is running, it works fine.

This is obviously a permissions issue, but I can't figure out what the difference is. Both solutions are using the same code below, both are attempting to access the same file on the same network share, and both are running from the same server using the same local credentials. Can anyone suggest something I might be missing?

NetworkCredential theNetworkCredential = new NetworkCredential(@"domain\username", "password");
CredentialCache theNetCache = new CredentialCache();
theNetCache.Add(new Uri(@"\\server"), "Basic", theNetworkCredential);

string origFile = @"\\server\temp\readFile.txt";
string configText = File.ReadAllText(origFile);

Here is the specific StackTrace if it helps.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost)
   at System.IO.File.InternalReadAllText(String path, Encoding encoding, Boolean checkHost)
   at System.IO.File.ReadAllText(String path)
   at project.project.<WarmupPoolConfig>d__18.MoveNext() in C:\project.cs:line 479
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at project.project.<OnTimer>d__8.MoveNext() in C:\project.cs:line 107


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source