locked
Xamarin.Forms for UWP - Image not shown in Release Mode RRS feed

  • Question

  • User211233 posted

    Hi,

    I saw that I'm not alone to have this problem, but in spit of my read, I couldn't resolve it.. The Images are shown in Debug mod, but not in Release mod..

    There is the code which allows me to load an Image of my PCL project (PROJECT.Images.PICTURE_NAME.png)

    [ContentProperty("Source")]
    public class ImageSourceExtension : IMarkupExtension
    {
        public string Source { get; set; }
    
        public object ProvideValue(IServiceProvider serviceProvider)
        {
            if (Source == null)
            {
                return null;
            }
            // Do your translation lookup here, using whatever method you require
            var imageSource = ImageSource.FromResource("PROJECT.Images." + Source);
    
            return imageSource;
        }
    }
    

    Then, in my xaml, an Image looks like:

    <Image Source="{extension:ImageSource LogoPROJECT.png}"/>
    

    extension is coming from the top of my xaml file:

    xmlns:extension="clr-namespace:PROJECT.Sources.Extensions;assembly=PROJECT"
    
    Tuesday, August 30, 2016 11:24 AM

Answers

  • User21407 posted

    Good news! Someone submitted this same issue to Bugzilla earlier this year and Jason Smith provided an answer: https://bugzilla.xamarin.com/show_bug.cgi?id=39685

    You must use one of the overloads for ImageSource.FromResource that takes in the resolvingType, or sourceAssembly

    This is a direct contradiction to what is in the Xamarin.Forms documentation:

    Image.FromResource only looks for images in the same assembly as the code calling FromResource.

    NOT ON UWP!!

    Xamarin, seriously. This has to be documented somewhere. This is just ridiculous and irresponsible.

    Using this method now displays the image with & without the .NET Native option checked. ImageSource.FromResource("[MyPCLName].[FolderName].EmbeddedResourceImage.png", typeof(App));

    I think the reason this issue rears its head in Release mode, is that by default when a new UWP project is added to a solution, the .NET Native option is unchecked in Debug mode, but checked in Release mode. As people switch to release mode they're unknowingly enabling this option.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, October 7, 2016 4:59 PM

All replies

  • User21407 posted

    Isn't this crazy!?! I noticed the same issue last week. It appears that any image that was being loaded with ImageSource.FromResource() just doesn't appear at all. Loading images using ImageSource.FromFile() works just fine.

    The only solution I found was to un-check the "Compile with .NET Native Toolchain" setting in the UWP project properties > build tab. Then the images appeared. So weird.

    I should mention, this issue happens for me in BOTH debug and release build modes if I don't uncheck that box.

    Tuesday, August 30, 2016 10:37 PM
  • User211233 posted

    Thank you, I'll check that tomorow :) "Compile with .NET Native Toolchain" doesn't work at all for me, an error is thrown..

    https://forums.xamarin.com/discussion/74172/xamarin-forms-uwp-error-ilt0042-arrays-of-pointer-types-are-not-currently-supported#latest

    Wednesday, August 31, 2016 12:44 AM
  • User211233 posted

    Hi @TomSoderling !

    So, about the "Compile with .NET Native Toolchain"'s problem, i found a solution, however, ImageSource.FromFile() doesn't work at all, "Compile with .NET Native Toolchain" either actived or not..

    I tried x86/x64 for build release.

    My Image is located in the PCL part. PROJECT_NAME.Images.MY_PICTURE.png

    Wednesday, August 31, 2016 11:55 AM
  • User240075 posted

    Have you tried to load the image by code not by binding?

    I'm having some similar issue, on Android, and I think it's the binding image from resource process having problem/bugs.

    I have two image holder in one page, and one is binding another one is load directly from resource by code. And 1st one doesn't work, 2nd one does.

    Thursday, September 1, 2016 7:34 AM
  • User211233 posted

    You know what, I put ImageSource.FromResource without the "Compile with .NET Native Toolchain", it works ^^

    Thursday, September 1, 2016 7:41 AM
  • User21407 posted

    @Emixam23 Just a word of warning about UN-checking the "Compile with .NET Native too chain option" - I discovered yesterday that builds with that option unchecked can't be uploaded to the Windows App store :( It will give you this error message: "Package acceptance validation error: This package wasn't built for submission to the Store. Make sure you're uploading a Release build with the .NET Native tool chain enabled."

    Even more unfortunately, is that the Windows App Certification Kit (WACK) tool doesn't warn you about it at all!! You have to get all the way to the app upload step before it tells you it's required, which is totally stupid.

    Another issue is that having the option unchecked will also cause WACK validation failures. See this for more details: https://forums.xamarin.com/discussion/79788/uwp-windows-app-certification-error-suggests-applying-linker-options-but-how#latest

    Long story short, I'm back to seeing this issue with images in the app. Every image in my PCL that has Build Action:EmbeddedResource set and is being loaded using ImageSource.FromResource fails to display at all. See attached images

    Friday, October 7, 2016 3:48 PM
  • User21407 posted

    Good news! Someone submitted this same issue to Bugzilla earlier this year and Jason Smith provided an answer: https://bugzilla.xamarin.com/show_bug.cgi?id=39685

    You must use one of the overloads for ImageSource.FromResource that takes in the resolvingType, or sourceAssembly

    This is a direct contradiction to what is in the Xamarin.Forms documentation:

    Image.FromResource only looks for images in the same assembly as the code calling FromResource.

    NOT ON UWP!!

    Xamarin, seriously. This has to be documented somewhere. This is just ridiculous and irresponsible.

    Using this method now displays the image with & without the .NET Native option checked. ImageSource.FromResource("[MyPCLName].[FolderName].EmbeddedResourceImage.png", typeof(App));

    I think the reason this issue rears its head in Release mode, is that by default when a new UWP project is added to a solution, the .NET Native option is unchecked in Debug mode, but checked in Release mode. As people switch to release mode they're unknowingly enabling this option.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, October 7, 2016 4:59 PM
  • User211233 posted

    Hi,

    What the hell it works ! Thank man !

    Friday, October 7, 2016 9:48 PM
  • User70571 posted

    Thanks was seeing this too!

    Tuesday, October 11, 2016 6:50 PM