updater.AuthenticateApplication fails with ArgumentException?

I’m testing the application in field update but hitting an ArgumentException when calling AuthenticateApplication()… Not sure why. Any ideas?

Error:

#### Exception System.ArgumentException - 0xfd000000 (6) ####
#### Message: 
#### GHIElectronics.TinyCLR.Update.InFieldUpdate::NativeAuthenticateApplication [IP: 0000] ####
#### GHIElectronics.TinyCLR.Update.InFieldUpdate::AuthenticateApplication [IP: 0023] ####
#### Ecu.ECU::CheckForAndUpdateFirmwareIfAvailable [IP: 0140] ####
#### Ecu.ECU::UsbHostController_OnConnectionChangedEvent [IP: 00cc] ####
#### GHIElectronics.TinyCLR.Devices.UsbHost.UsbHostController::OnConnectionChangedCallBack [IP: 0019] ####
#### GHIElectronics.TinyCLR.Devices.UsbHost.Provider.UsbHostControllerApiWrapper::<.ctor>b__6_0 [IP: 0042] ####

Source:

        FileStream fsApp = null;
        
        try 
        {
            fsApp = new FileStream($"{drive.Name}PlaneAC_Preview2_Update0.tca", FileMode.Open);
        }
        catch(Exception e)
        {
            FileSystem.Unmount(media.Hdc);
            p.WriteLine($"Firmware update not found: {e.ToString()}");
            return;
        }

        if(fsApp == null)
        {
            return;
        }

        InFieldUpdate updater;
        updater = new InFieldUpdate(fsApp);

        if (updater == null)
        {
            return;
        }


        updater.ApplicationKey = new byte[] { redacted }; //Add key as byte array here.

        try
        {
            updater.AuthenticateApplication(out var versionApp);  <-- Exceptions here with ArgumentException 
        }
        catch (Exception e)
        {

Make sure the key matches to tca file.

Use that key and tca and update by TinyCLR Config to see if it work.

Thanks for the suggestion Dat. I verified the hex matches. I also verified that using the same .tca (right off the USB stick) from TinyCLR Config works OK. However, it doesn’t work in the code above… If the hex doesn’t match, does it throw than ArgumentException or something else?

Are you willing to send that tca file to us?

Sure thing, PM sent with download links

Got it, will check in shortly

I have sent you a simple but full ifu project that I just used to tested your tca, all you need just copy your two files that you sent me into your SD Card, and run that project.

I tried SD, 2 USB, no problem found. Hopefully you will see something different between my code and your code.

And make sure your SD or USB are working well. Your issue is likely corrupted when reading file.

Thanks Dat, yes, this appears to be a USB reading problem…

This first stick I used is a Samsung BAR Plus 32GB USB 3.1. Note that flashing the chip with the update with TinyCLR Config off of the USB drive from the PC works successfully, so the file itself is not corrupted.

Using the simple IFU flashing code (but adding this to the top so USB works):

        var usbHostController = GHIElectronics.TinyCLR.Devices.UsbHost.UsbHostController.GetDefault();
        usbHostController.Enable();

… I get exactly the same error.

Also, if I change it to just read the bytes out of the filestream for testing purposes, the Read() function returns 0 bytes read:

        var fsApp = new FileStream($"{drive.Name}PlaneAC_Preview2_Update0.tca", FileMode.Open);

        var bufferSize = 1024;
        byte[] app = new byte[bufferSize];

        int bytesRead = 1;
        int totalBytesRead = 0;

        while (bytesRead > 0)
        {
            bytesRead = fsApp.Read(app, 0, bufferSize);   <-- Reads 0 bytes
            totalBytesRead += bytesRead;
            Debug.WriteLine($"Total read: {totalBytesRead}");
        }

So I tried a second USB stick, MBR, 128gb total size with a 12 GB FAT32 partition (only partition on the drive). This second stick is a SanDisk 128GB Ultra Fit USB 3.1. It sees the device as mass storage arrival and can mount the file system, but thinks the volume label is blank and can’t open/find the file (exception opening FileStream).

I tried a third USB stick, MBR, 32gb total size with a 32gb FAT32 partition (only partition on the drive). This is a Patriot Xporter XT 32 GB USB 2.0. It sees the device as mass storage arrival, but can’t even mount the file system (CLR_E_INVALID_OPERATION in FileSystem::Initialize).

All of these sticks work good on a PC, and the errors for each stick are 100% consistent to that stick (tried under both the simple IFU app and my main app, several times each) so it’s not a randomized/reliability failure. Do you have specific USB sticks that are known to work, like specific makes and models?

Make sure it is FAT32, not extFAT.

We do have 128GB and it work.

As Window10 is usually force to format at exFAT, I usually use this tool to make partition and format “MiniTool Partition Wizard Free Edition”.

This tool is a third party and just my experience, check carefully before install. :))
Make sure you know what you are doing when select drive to format, careful with your hard drive data.

Bold text by me.

I’ve noticed that if you have a space in the volume label, then TinyCLR returns an empty label.

My USB stick was named “PNY UFD31” and showed empty label in DriveInfo(). Once I renamed it to “PNY_UFD31” TinyCLR displayed this label.

I will raise an issue for this. White spaces should be allowed in volume label.

Edit : Issue created. But now if I rename again and replace the underscore with a space, TinyClr does show the correct volume label :open_mouth:

1 Like

they applied on your complain remote invisible fix , but you do not see it
:rofl: :rofl: :rofl:

2 Likes

Most annoying is that I cannot reproduce :frowning: Even with a newly formatted drive. I just don’t understand.

I also use MiniTool Partition Wizard :slight_smile:

But yes, all are FAT32:

image

image

I appreciate you aren’t in the office on the weekends (at least I hope not!), but when you get a chance could you post the make/model of one of the sticks you’re using that works? That way I can grab one off of Amazon for testing to make sure I’m not going crazy over here… :slight_smile:

The volume label it thinks is blank in my case is “MUSIC”… So maybe the space isn’t the key here, but something else?

https://www.corsair.com/us/en/Categories/Products/Storage/USB-Drives/CMFVYGT3B-config/p/CMFVYGT3B-128GB

Verbatim Store 'n' Go V3 - USB flash drive - 256 GB - 49168 - -!

Those are we usually use to test.

1 Like

I picked up the SanDisk Ultra Flair 128GB you linked to above and it works totally normal with the default FAT32 partition that came on the stick, with the exception of the volume label being blank. The CLR can read the file and authenticate it.

So I deleted that partition, recreated a 32 GB partition in Windows (FAT32) and I get a CLR_E_FILE_NOT_FOUND exception. It correctly reads the partition size, but is unable to find/read the file. It also has a blank volume label.

So I deleted that partition, recreated a full 128 GB partition in MiniTool Partition Wizard (FAT32) and the CLR can correctly read the partition size AND has a correct volume label.

So I resized that partition to 32 GB in MiniTool Partition Wizard (FAT32) and the CLR can’t even mount it. I’m not to worried about this as it’s kind of a corner case.

So I deleted that partition, created a new one at 32 GB partition in MiniTool Partition Wizard (FAT32) and it works fine, including volume label.

So to recap:

  1. Stick as it arrived - Mounts, reads, volume label blank.
  2. Formatted 32gb FAT32 in Windows - Mounts, FileNotFound exception, volume label blank
  3. Formatted 128gb FAT32 in MiniTool Partition Wizard - Mounts, reads, volume label works
  4. Resized 128gb->32gb FAT32 in MiniTool Partition Wizard - Can’t mount volume
  5. Formatted 32gb FAT32 in MiniTool Partition Wizard - Mounts, reads, volume label works

Don’t take this the wrong way, but there are clearly some corner cases to be sorted out with the USB file system. Mostly it seems that testing with anything formatted by Windows has issues being read, although per previous testing the other sticks I used, even when formatted with MiniTool, also had issues…

Perfect. This is what we needed to fix the issue

1 Like