PLC stops due to file write error

Hello, I have a few C# methods that read and write files. For all of them I use try-catch instructions to determine if the directory exists and issue an error gracefully. It works well. However, on one method the PLC stops and throws the error below if the directory does not exist. Exception Information typeId=Signal subTypeId=0 subType=SIGSEGV taskName=Cyclic100 programName=Arp.Plc.Eclr/MainInstance information=Signal ‘SIGSEGV’ occured extendedInformation= What does it mean? How to avoid it? Thanks.

Hi Alex, That is a segmentation fault, and could be caused (for example) if the code is attempting to use an invalid object reference. In your code, is it the “File.Exists” method that is causing the error, or some other method? Are you checking the return value of the File.Exists method, or just catching exceptions? From the documentation for File.Exists:

Return Value
Type: Boolean
true if the caller has the required permissions and path contains the name of an existing file; otherwise, false. This method also returns false if path is null, an invalid path, or a zero-length string. If the caller does not have sufficient permissions to read the specified file, no exception is thrown and the method returns false regardless of the existence of path.

If the code doesn’t crash on the File.Exists call: a) What value is returned by File.Exists? b) What method does the code crash on? ~ Martin.

Thank Martin, I was just catching exceptions. Checking the return value prevented the PLC from crashing. Regards, Alex