Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET IO Exception "Invalid Signature"

Executing code in a web service:

using (File.OpenRead(@"\\server\file.txt"))
{
    // some stuff
}

Causing IO Exception that just says "Invalid Signature"

I can't find anything through google about this error message when using File static methods.

var exists = File.Exists(@"\\server\file.txt"))

Does not throw an exception however, which makes it seem like it can see the file there, but it cannot open it for reading.

I'm really at a loss for what "Invalid Signature" is trying to say in this instance.

Thanks.

UPDATE:

Even using impersonation to open read files from the server, it still throws the IO Exception with "Invalid Signature."

Stack:

<StackTrace>
  <StackFrame Index="6">
    <FileName />
    <Method>Void RenderImages(System.String, System.Nullable`1[System.Int32])</Method>
    <LineNumber>0</LineNumber>
    <ColumnNumber>0</ColumnNumber>
    <ILOffset>88</ILOffset>
  </StackFrame>
  <StackFrame Index="5">
    <FileName />
    <Method>Void .ctor(System.String, Boolean)</Method>
    <LineNumber>0</LineNumber>
    <ColumnNumber>0</ColumnNumber>
    <ILOffset>0</ILOffset>
  </StackFrame>
  <StackFrame Index="4">
    <FileName />
    <Method>Void .ctor(System.String, System.Text.Encoding, Boolean, Int32)</Method>
    <LineNumber>0</LineNumber>
    <ColumnNumber>0</ColumnNumber>
    <ILOffset>7</ILOffset>
  </StackFrame>
  <StackFrame Index="3">
    <FileName />
    <Method>Void .ctor(System.String, System.Text.Encoding, Boolean, Int32, Boolean)</Method>
    <LineNumber>0</LineNumber>
    <ColumnNumber>0</ColumnNumber>
    <ILOffset>113</ILOffset>
  </StackFrame>
  <StackFrame Index="2">
    <FileName />
    <Method>Void .ctor(System.String, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, Int32, System.IO.FileOptions, System.String, Boolean, Boolean, Boolean)</Method>
    <LineNumber>0</LineNumber>
    <ColumnNumber>0</ColumnNumber>
    <ILOffset>35</ILOffset>
  </StackFrame>
  <StackFrame Index="1">
    <FileName />
    <Method>Void Init(System.String, System.IO.FileMode, System.IO.FileAccess, Int32, Boolean, System.IO.FileShare, Int32, System.IO.FileOptions, SECURITY_ATTRIBUTES, System.String, Boolean, Boolean, Boolean)</Method>
    <LineNumber>0</LineNumber>
    <ColumnNumber>0</ColumnNumber>
    <ILOffset>998</ILOffset>
  </StackFrame>
  <StackFrame Index="0">
    <FileName />
    <Method>Void WinIOError(Int32, System.String)</Method>
    <LineNumber>0</LineNumber>
    <ColumnNumber>0</ColumnNumber>
    <ILOffset>571</ILOffset>
  </StackFrame>
</StackTrace>

Environment:

 <Environment>
<DateTime.Now>1/23/2015 8:50:28 AM</DateTime.Now>
<MachineName>xxxxx</MachineName>
<UserDomainName>xxxxx</UserDomainName>
<UserName>xxxx</UserName>
<Executable>w3wp.exe</Executable>
<ExecutableTimestamp>0101.01.0000</ExecutableTimestamp>
<CommandLine>c:\windows\system32\inetsrv\w3wp.exe -ap "xxx.xxxxx.com" -v "v4.0" -l "webengine4.dll" -a \\.\pipe\iisipm45ad21f3-41a8-4e9a-a27c-fd0c679b337a -h "C:\inetpub\temp\apppools\xxxx.xxxx.com\xxxx.xxx.com.config" -w "" -m 0 -t 20 -ta 0</CommandLine>
<OSVersion>Microsoft Windows NT 6.3.9600.0</OSVersion>
<WorkingSet>168112128</WorkingSet>
<EnvironmentVersion>4.0.30319.34003</EnvironmentVersion>

using (File.Open(@"\\server\file.txt", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)

and

File.WriteAllText(destinationFile, sb.ToString());

where destinationFile is \\server\sharename\generatedFileName.txt

Also throw the exception, for clarification purposes.

like image 915
Joel Reid Avatar asked Jan 23 '15 14:01

Joel Reid


1 Answers

I've managed to get the same error message. I think the following method helped, but it could just be that I'm forcing the application to reload with every change. In my case, I've been building the file path using a string from a SQL 2000 database.

var folderVar = myDataRow["folderVar"].ToString();
var di = new DirectoryInfo("\\\\domain.website.com\\shares\\" + folderVar + "\\subdir\\");`

The problem stopped after I changed this code to something (horrible) like this:

var folderVar = myDataRow["folderVar"].ToString();
if (folderVar == "ABC")
{
    var di = new DirectoryInfo("\\\\domain.website.com\\shares\\ABC\\subdir\\");`
}
else if (folderVar == "BCD")
{
    var di = new DirectoryInfo("\\\\domain.website.com\\shares\\BCD\\subdir\\");`
}

I don't typically work with string formatting on the byte level. If encoding really is the issue, there's definitely a better solution.

like image 103
Nathan Avatar answered Oct 06 '22 17:10

Nathan