For context I opened my other developers GitHub branch of our project in Visual Studio. As soon as I set the project start up option to iOS and tried to run it, I got the error shown below. I am plugging my phone in and I successfully went through the Hot Reload setup steps (linking developer account etc). This error does not show up when running the android project.

Severity    Code    Description Project File    Line    Suppression State   Details
Error       The "UnpackFrameworks" task failed unexpectedly.
System.BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid.
   at Mono.Cecil.PE.ImageReader.ReadOptionalHeaders(UInt16& subsystem, UInt16& dll_characteristics) in C:\src\cecil\Mono.Cecil.PE\ImageReader.cs:line 197
   at Mono.Cecil.PE.ImageReader.ReadImage() in C:\src\cecil\Mono.Cecil.PE\ImageReader.cs:line 86
   at Mono.Cecil.PE.ImageReader.ReadImage(Disposable`1 stream, String file_name) in C:\src\cecil\Mono.Cecil.PE\ImageReader.cs:line 765
   at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters) in C:\src\cecil\Mono.Cecil\ModuleDefinition.cs:line 1113
   at Xamarin.iOS.HotRestart.Tasks.UnpackFrameworks.Execute() in /Users/builder/azdo/_work/1/s/xamarin-macios/msbuild/Xamarin.iOS.Tasks.Windows/Tasks/UnpackHotRestartFrameworks.cs:line 35
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() StartUpz8.iOS               

I have already tried to debug by rebuilding project, checking packages are updated, searching for the problematic files etc however nothing has worked.

1

There are 1 best solutions below

0
Guangyu Bai - MSFT On

This is a known issue on the Github and you can try the solution by editing Xamarin.iOS.HotRestart.targets file.

Search UnpackFrameworks node and add ContinueOnError="true".

<UnpackFrameworks ContinueOnError="true"
        ReferencedAssemblies="@(AssembliesWithFrameworks)"
        IntermediateOutputPath="$(DeviceSpecificIntermediateOutputPath)">

        <Output TaskParameter="Frameworks" ItemName="_UnpackedFramework" />
    </UnpackFrameworks>