question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] [Android] System.IO.FileNotFoundException when <BundleAssemblies>True</BundleAssemblies>

See original GitHub issue

Description

After upgrade from Xamarin.Forms 4.4.0.991640 to 4.5.282-pre4 I noticed that when

<BundleAssemblies>True</BundleAssemblies>

app crash on start with exception

System.IO.FileNotFoundException: Could not load file or assembly ‘Xamarin.AndroidX.AppCompat.Resources, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies.

My working setup for release in 4.4 is

<AndroidLinkMode>Full</AndroidLinkMode>
<AotAssemblies>True</AotAssemblies>
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
<EnableLLVM>True</EnableLLVM>
<BundleAssemblies>True</BundleAssemblies>

in 4.5 everything works fine only if

<AndroidLinkMode>Full</AndroidLinkMode>
<AotAssemblies>True</AotAssemblies>
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
<EnableLLVM>True</EnableLLVM> 
<BundleAssemblies>False</BundleAssemblies>

Steps to Reproduce

  1. Create new solution
  2. Upgrade Xamarin to 4.5.0.282-pre4
  3. Set:
<AndroidLinkMode>Full</AndroidLinkMode>
<AotAssemblies>True</AotAssemblies>
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
<EnableLLVM>True</EnableLLVM>
<BundleAssemblies>True</BundleAssemblies>
  1. Run app on the real device

Expected Behavior

App starts.

Actual Behavior

App crash with System.IO.FileNotFoundException exception.

Basic Information

  • Version with issue: 4.5.0.282-pre4
  • Last known good version: 4.4.0.991640
  • IDE: Visual Studio 2019
  • Platform Target Frameworks:
    • Android: Xamarin.Android 10.1
  • Android Support Library Version: 28.0.0.03, AndroidX 1.1.0
  • Nuget Packages:
  • Affected Devices: all

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:82 (30 by maintainers)

github_iconTop GitHub Comments

5reactions
tranb3rcommented, Mar 3, 2020

Here is another repro project: TestAndroidX.zip

In debug mode, an image will be displayed on the main page. In release mode, the image is not displayed, because of the exception.

The exception is only happening with <BundleAssemblies>True</BundleAssemblies>. It makes no difference whether R8 or Linker are enabled or not. I’m using XF 4.5.0. This exception can be easily reproduced on the emulator.

Stack trace of the exception (no crash, it’s silent): ImageElementManager: Error loading image: System.IO.FileNotFoundException: Could not load file or assembly 'Xamarin.AndroidX.AppCompat.Resources, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. File name: 'Xamarin.AndroidX.AppCompat.Resources, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' at Xamarin.Forms.Platform.Android.FileImageSourceHandler.LoadImageAsync (Xamarin.Forms.ImageSource imagesource, Android.Widget.ImageView imageView, System.Threading.CancellationToken cancellationToken) at Xamarin.Forms.Platform.Android.ImageViewExtensions.UpdateBitmap (Android.Widget.ImageView imageView, Xamarin.Forms.IImageElement newView, Xamarin.Forms.IImageElement previousView, Xamarin.Forms.ImageSource newImageSource, Xamarin.Forms.ImageSource previousImageSource) at Xamarin.Forms.Platform.Android.FastRenderers.ImageElementManager.TryUpdateBitmap (Xamarin.Forms.Platform.Android.IImageRendererController rendererController, Android.Widget.ImageView Control, Xamarin.Forms.IImageElement newImage, Xamarin.Forms.IImageElement previous)

4reactions
jonpryorcommented, Apr 6, 2020

@15mgm15 asked:

Do we have some sort of work around?

The workaround is to not set $(BundleAssemblies)=True.

After internal discussion, we are strongly considering removing support for $(BundleAssemblies) in .NET 5, as it increases on-device memory use and slows down app startup times.

Read more comments on GitHub >

github_iconTop Results From Across the Web

System.IO.FileNotFoundException error to build Android ...
Error : Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Xamarin.iOS, Version=0.0.0.0, Culture: ...
Read more >
Debugging System.IO.FileNotFoundException - Cause and fix
The typical cause of this error is that the referenced assembly isn't on the file system. There can be multiple causes of this....
Read more >
system.IO.FileNotFoundException error when I open the . ...
I got a software which can be installed through Clickonce application deployment support library and can be started through .exe file.
Read more >
FileNotFoundException Class (System.IO)
Initializes a new instance of the FileNotFoundException class with a specified error message, and the file name that cannot be found.
Read more >
Xamarin Android Bug - Developer Community
Error The “LinkAssemblies” task failed unexpectedly. System.IO.FileNotFoundException: Could not load assembly 'FireWolf, Version=0.0.0.0, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found