Error code 22 when attempting to create files

Hi,

I’m seeing an odd problem since I upgraded to Mac OS Sonoma, where my app can no longer create files on USB devices. I’m getting an exception where code is 22 (“invalid argument”, funny how this helps :man_shrugging:).

This code shows the issue:

for i as Integer=0 to FolderItem.DriveCount-1
  Var f As FolderItem=FolderItem.DriveAt(i)
  
  if f<>nil and f.Name="Archives" and f.IsWriteable then
    Var g As FolderItem=f.Child(".DoNotSleep")
    
    Var b As BinaryStream=BinaryStream.Create(g,True) 'Exception happens here
    b.Write "Trying to prevent sleeping for this volume."
    b.Flush
    b.Close
  end if
next i

Ideas, please?

So I “fixed” this issue by restarting the computer.
The problem was specific to one USB drive. Even the Finder and the Terminal were unable to create or rename any item on that drive, including creating a simple empty folder, reporting an error “invalid argument”, even as root; the crossed pencil icon wasn’t displayed, as the disk wasn’t “locked”, but any attempt to modify an item would fail.
I’d have loved to find the root issue, but once I restarted the computer, it was gone and I can’t pinpoint the problem anymore.