Skip to content

DfuInstallation.Start() Exception thrown on .Net MAUI #27

@MouratidisA

Description

@MouratidisA

Describe the bug

I tried to implement the DFU on a .NET MAUI application, but it seems that when I create the DfuInstallation object and call the Start() function the process throws an Exception with a message:
Exception of type 'Foundation.You_Should_Not_Call_base_In_This_Method' was thrown.

To Reproduce

Steps to reproduce the behavior:

  1. Create a MAUI project
  2. Install the Laerdal.Dfu 1.27.8 NuGet package
  3. Create a method to download or retrieve your firmware update file
  4. Scan for the desired device to DFU
  5. Create the DfuInstallation object and call Start()

To download the firmware File:


public async Task<bool> DownloadFirmwareFile()
{ 
    //Retrieve firmware file in bytes 
    byte[] fileBytes = await HttpClientService.Instance.GetByteArrayAsync(Constants.GetFirmwareUpdate);

    //Create the file inside LocalApplicationData
    string outputFilePath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "app_dfu_package.zip");

    File.WriteAllBytes(outputFilePath, fileBytes);

    //Check if the file exists and update the SelectedFirmwareFile
    var exists = File.Exists(outputFilePath);
    if (!exists)
    {
        Instance.SelectedFirmwareFile = null;                            
        return false;
    }
    else
    {
        Instance.SelectedFirmwareFile = new FileInfo(outputFilePath);
        return true;
    }
}

To launch the update process:

var deviceId = $"{Instance.SelectedDevice?.Id.ToString()}";
var filePath = $"{Instance.SelectedFirmwareFile?.FullName.ToString()}";

var fileExists = File.Exists(filePath);
Debug.WriteLine($"File path exists: {fileExists}");

var output = new DfuInstallation(deviceId, filePath);

output.DfuErrorReceived += DfuInstallationOnErrorOccured;
output.DfuStateChanged += DfuInstallationOnStateChanged;
output.DfuProgressChanged += DfuInstallationOnProgressChanged;

output.Start();

FileUrl value: /var/mobile/Containers/Data/Application/537D36A3-7D6D-4A0F-B78A-8A03F85CEFEF/Documents/app_dfu_package.zip

Expected behavior

Start and complete the DFU process with the BLE device.

Exception information
Source: Laerdal.Dfu.Bindings.iOS
Message: Exception of type 'Foundation.You_Should_Not_Call_base_In_This_Method' was thrown.
StackTrace:
at Laerdal.Dfu.Bindings.iOS.DFUFirmware..ctor(NSUrl urlToZipFile, NSError& error)
at Laerdal.Dfu.DfuServiceInitiatorDelegate..ctor(DfuInstallation dfuInstallation)
at Laerdal.Dfu.DfuInstallation.Start(DfuConfiguration configuration)
at ProjectName.ViewModels.FirmwareUpdatePopUpViewModel.GetDfuInstallation() in /Users/username/ProjectName/ProjectName/ViewModels/FirmwareUpdatePopUpViewModel.cs: line 264

line 264 has the command Start command

Environment:

  • OS: macOS 13.5.2 (22G91)
  • IDE: Visual Studio for Mac 17.6.4 (build 472)
  • NuGet package Laerdal.Dfu version 1.27.8
  • Tested target device: iPhone 11 with iOS 17.1

Additional context

I've tried to recreate the exception on Android 12, but the debugger gets disconnected when reaches the start command.
(I am using wireless debug, due to maui issues #16274.

Is there an active example on MAUI I can follow?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions