If I try to load a image like described below in a Page I get a thread exception.

The image "Logo.png" is part of the PCL Library With build action 'BundleResource'.

var imageLogo = new Image
Source = ImageSource.FromResource("Logo.png")

Do I have to move the Resource to each Application (Android, iOS and Windows Phone ? )



  • TheRealJasonSmithTheRealJasonSmith USXamarin Team Xamurai

    Can you show us the exception and the code where you are loading it? Also the build action in your PCL should be Embedded Resource

  • RolfHjemdahl.6124RolfHjemdahl.6124 NOMember ✭✭

    Code is :

    var imageLogo = new Image
    Source = ImageSource.FromResource("Logo.png")

    [System.ArgumentNullException] {System.ArgumentNullException: Value cannot be null.
    Parameter name: streamSource
    at System.Windows.Media.Imaging.BitmapSource.SetSourceInternal(Stream streamSource)
    at System.Windows.Media.Imaging.BitmapImage.SetSourceInternal(Stream streamSource)
    at System.Windows.Media.Imaging.BitmapSource.SetSource(Stream streamSource)
    at Xamarin.Forms.Platform.WinPhone.StreamImagesourceHandler.d__0.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
    at Xamarin.Forms.Platform.WinPhone.ImageRenderer.d__0.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.AsyncMethodBuilderCore.b__0(Object state)} System.ArgumentNullException

  • StephaneDelcroixStephaneDelcroix USInsider, Beta ✭✭✭✭

    ImageSource.FromResource () loads images included as EmbeddedResource.
    If you want to load a bundle/asset, use ImageSource.FormFile().

    our wrong, the documentation is kidding for this:

  • RolfHjemdahl.6124RolfHjemdahl.6124 NOMember ✭✭

    In my Project (PCL), I have the Image included as am EmbeddedResource. But still the exeption occure.

    My code is :

    var imageLogo = new Image { Source = ImageSource.FromResource("Logo.png") };

    and Logo.png is a part of the PCL Project, With EmbeddedResource set for its build type.

  • RolfHjemdahl.6124RolfHjemdahl.6124 NOMember ✭✭

    Put together a simple project with an embedded image.

    Using Visual Studio 2013.

    Try to run it in the win phone simulator.

  • RolfHjemdahl.6124RolfHjemdahl.6124 NOMember ✭✭

    Worked perfect.

    Thank you.

  • RolfHjemdahl.6124RolfHjemdahl.6124 NOMember ✭✭

    How can I scale a image to the width of the actual screen size for all platforms ?

  • RolfHjemdahl.6124RolfHjemdahl.6124 NOMember ✭✭

    Thamk's for the information.

    Do you have any idea how to get the device screen size in the PCL (Xamarin.Forms) library ?

  • MarkSmith.8123MarkSmith.8123 USXamarin Team, University, XamUProfessors Xamurai
  • RolfHjemdahl.6124RolfHjemdahl.6124 NOMember ✭✭

    This issue can be closed

  • powerdudepowerdude USMember ✭✭


    I'm working on a WP app and I get the streamSource error mentioned above. I'm on

  • CraigDunnCraigDunn USXamarin Team Xamurai

    See the working with images doc.

    Does the sample work for you?

    Having you confirmed (using the debugging embedded images code that your resources are embedded correctly?

  • powerdudepowerdude USMember ✭✭

    Hi @CraigDunn, Yes, i've tried everything, even the sample after i upgraded it to 6257, and it gives me the same error. Uncomment the EmbeddedImagesXaml line and it'll fail.

    I've attached the updated zip since the original was a bit messed up with package locations and referred to 6197.

  • powerdudepowerdude USMember ✭✭

    Hi @Craigdunn,

    Can you confirm if this is a bug or not or if i'm doing something wrong?


  • anveanve DEMember ✭✭✭

    @FlyingOverClouds: How do you get the string for the shared project at runtime or through the project itself?

Sign In or Register to comment.