Invalid signature
Hi, while working on code to access remotely some files, I got this error :
Invalid Signature. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileSystemEnumerableIterator`1.CommonInit() at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost) at System.IO.Directory.GetFiles(String path, String searchPattern)
The line where it happens is Directory.GetFiles (path, "*.*").ToList();
I have the exact same code in another file, and it works perfectly
If anyone has an idea
16 Replies
check that filepath is correct
It is, it's in the config file, I use the same for both codes
to debug the issue i'd do something like this
DirectoryInfo dir = new DirectoryInfo(path)
var b = dir.GetFiles()
foreach(var file in b)
{
}
then you can narrow it down to what bit it is.
set a breakpoint and verify, or inspect the state when the exception occurs
I'll try something like that with logs, but I can't really debug, the issue only happens on the prod server
Might be a policy issue, maybe the user ain't allowed to read from that folder.
Write a function that tests if the folder is readable and/or writable (if needed).
Put the result in a log (verbose logging).
If you're on Windows you could make use of ACL, but the allround solution is to read and/or write in that folder wrapped around a try block.
from what i remember the shit thing about getfiles/enumeratefiles is that if you getfiles in a folder but one of those files your program isn't allowed to access it'll throw an exception. meaning it won't return anything at all. But that was a long time ago when i came across that so i might be misremembering
I think I can answer both messages at the same time
The server isn't really up to date, and to access files, we need to use impersonation
It works well for the same code in another part of the program, so same user, user allowed and no file blocking
That's true, in this case you gotta wrap the
Directory.GetFiles
in recursion remembering which already has been read and which not.Same error at the line var b = ...
only thing it'll be is permissions issue then.
I used a domain admin account for the impersonation, it's supposed to have all rights on everything
And still, it works in one file of the project, so it should work too in another one
what happens if you do FileInfo file = new FileInfo(path of file in folder you can't access using getfiles)
also do you know what the errorcode it returns?
I'll try in a few minutes, I'm publishing the app to test it
Maybe I found something, the execution continued after returning, maybe that's what caused the error
I don't have the errorcode, sorry
That was it
It executed the return twice
I feel dumb and it's too soon to have the excuse "it's the end of the day I'm tired"
:kekw:
Well thanks everyone for helping me
Everything works now
Until I break something (again)