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
Pengwynn
Pengwynnβ€’6mo ago
check that filepath is correct
π•Ίπ–“π–žπ–
It is, it's in the config file, I use the same for both codes
Pengwynn
Pengwynnβ€’6mo ago
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.
Anchy
Anchyβ€’6mo ago
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
SpReeD
SpReeDβ€’6mo ago
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.
Pengwynn
Pengwynnβ€’6mo ago
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
SpReeD
SpReeDβ€’6mo ago
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 = ...
Pengwynn
Pengwynnβ€’6mo ago
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
Pengwynn
Pengwynnβ€’6mo ago
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"
Pengwynn
Pengwynnβ€’6mo ago
:kekw:
π•Ίπ–“π–žπ–
Well thanks everyone for helping me Everything works now Until I break something (again)
Want results from more Discord servers?
Add your server