Opening PDF via FolderItem.Open: Exceptions 31 and 256

Hello. Currently using 2021 r1 on Mojave

I had two customers contact me about an exception error they received when trying to open a PDF through the app. Both were on Windows, and the app was built in 2021 r1. Their error messages contained exception number 31 and read:

An exception of class IOException was not handled. The application must shut down. Exception Message: No appplication was assoicated with the specified file for this operation. Exception Error Number: 31.

I tested this on my Mac and actually noticed the crash too, but with a different exception number 256 with also the miscellaneous error OSStatus -36

Here is the code for opening this PDF:

Dim f As FolderItem

f = SpecialFolder.ApplicationData.Child("com.visualveggiessoftware.rdexamstudysuite").Child("Help Docs").Child("Study Suite Users Guide.pdf")

f.Open

What’s really odd is I do use FolderItem.Open elsewhere, and this opens the PDF with no problem. In these other areas, I am generating a PDF with DynaPDF, saving it to the ApplicationData folder, and then opening it with f.Open. So I thought maybe this is because I am not creating the Users Guide PDF as this is copied over with CopyFiles. So I took the file I generated and placed it into the Help Docs folder where the Users Guide is, replaced the path, and the PDF opened with the f.Open. Ok, so maybe there is an issue with the Users Guide PDF. It’s an older file from 2018 (mind was racing with what the problem could be)

Then I found this thread and the post below from Christian Mezes

Hello, this is a bug. I entered a case in Feedback (58856) which is only visible if you ar a beta tester.

Problem:

  • Xojo 2019R2.1 and 2019R3 can not launch files on macOS with folderitem.launch and folderitem.open when the files are copied from an MSDOS (FAT) formatted USB-disc to a macOS filesystem.
  • FolderItem.launch and FolderItem.open also do not launch files when the files are located an an MS-DOS (FAT) formatted USB-Drive. FolderItem.open gives an „miscellaneous error occurred (OSStatus -36)“ message.

ShowURL(FolderItem.URLPath) launches the files, so use ShowURL until this gets fixed.

Swapped out my f.Open with ShowURL(f.URLPath), and the original Users Guide which was causing the issue now opened!

Christian mentions he submitted a feedback case, which I could not find since I am not a tester but also did not see any mention of the feedback case in the current release notes

Questions:

  • Was this issue resolved in the current Xojo release 2021 r2.1?
  • Is this the new way to go with using ShowURL(FolderItem.URLPath) in lieu of using FolderItem.Open when opening a PDF document?
  • Why did the PDF I generated work when using f.Open but the Users Guide needed ShowURL?
  • This workaround worked for my error number 256, but will this work for the customers’ exception error number 31? I have not been able to reproduce this error number

Mac and Windows use different error codes, I was surprised that you actually got an error message with the IOException as I’ve never seen a message in recent years.

OSStatus -36 = IOError... 
256          = NSFileReadUnknownError

Interesting to see my own code in this post… lol…

So my first suggestion would be to do some checks before opening the PDF.

  1. Does the file exist at that location?
  2. Can you read it (folderitem.isReadable)?

Permissions and magical filing systems cause all kinds of errors.

This technically should work for any file on the file system.

Cant say for sure, but I would suggest that you make a build for your customer and try it.

Learned something new! Thanks Sam

Yes, the file does exist. The error with the Users Guide file was only being thrown when using f.Open, but when I switched to ShowURL(f.URLPath), the same file opened

Yup, will be trying this

Thank you!

1 Like