Mvvmcross: Xamarin Forms Images is not shown on Android when using mvvmcross

Created on 6 Apr 2018  路  8Comments  路  Source: MvvmCross/MvvmCross



Here is link to reproduce issue https://github.com/F0rc0sigan/MvvmCrossImageNotLoadingTestApp

Steps to reproduce :scroll:

  1. Setup Xamarin.Forms project with mvvmcross

  2. Add image on page

  3. Image is not shown, though without mvvmcross it is shown as expected

Expected behavior :thinking:

It should load image and show it on page

Actual behavior :bug:

It does not show image. In output it write
"FileImageSourceHandler: Could not find image or image file was invalid: File: xamarin_logo.png" Screenshot of problem: http://take.ms/YJ7aF
If i remove mvvmcross from project, then image is shown as expected

Related to this issue on StackOverflow https://stackoverflow.com/questions/48944590/xamarin-forms-not-displaying-images-in-mvvmcross-mvxcontentpage?noredirect=1#comment86318999_48944590

Configuration :wrench:

Debug

Version: 6.0.0-beta.7

Platform:

  • [ ] :iphone: iOS
  • [x] :robot: Android
  • [ ] :checkered_flag: WPF
  • [ ] :earth_americas: UWP
  • [ ] :apple: MacOS
  • [ ] :tv: tvOS
  • [x] :monkey: Xamarin.Forms
android forms bug

Most helpful comment

The issue appear to be that the top activity wasn't being returned at the point where the FormsApplication was initialized. I've adjusted the logic to use the first viewassembly, which is set when the Setup instance is created.

All 8 comments

Can you PR this sample to the playground?

@martijn00 Thanks for your quick response. I dont get what you mean. Implement sample in playground or just add my sample to playground folder as separate solution and create pull request?

I mean implement this in the playground.

I had the same problem. The core cause of it is that MvvmCoss Setup's FormsApplication property initializes Xamarin.Forms with the wrong assembly for resources. Thus, Xamarin.Form's ResourceManager will resolve Drawable and Resource class instances from Android.* namespace, not from yours. Hence, Xamarin.Forms will be trying to resolve images not from YourProject.Resources but from Android.Resources.
However, there is a fast fix for this if you want. In your MainActivity, before base.OnCreate() call, just initialize ResourceManager again like this ResourceManager.Init(GetType().Assembly);

Any chance someone can add an example of this to the playground forms droid sample and submit a PR that shows the issue. I can assist with a fix but would appreciate help creating a repro in the sample projects.

@nickrandolph In develop branch, playground project's RootPage.xaml contains image with MvvmCross logo which is not loaded. Instead, in debug logs, you receive [0:] FileImageSourceHandler: Could not find image or image file was invalid: File: MvvmCross
I suppose, it already shows the issue :)

Awesome. Thanks will investigate

The issue appear to be that the top activity wasn't being returned at the point where the FormsApplication was initialized. I've adjusted the logic to use the first viewassembly, which is set when the Setup instance is created.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

HaraldMuehlhoffCC picture HaraldMuehlhoffCC  路  3Comments

StephenBeirlaen picture StephenBeirlaen  路  4Comments

iqbalmineraltown picture iqbalmineraltown  路  3Comments

RonakPatel21 picture RonakPatel21  路  4Comments

a7ex picture a7ex  路  3Comments