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.

[Xamarin.Forms Android] Error loading SVG Image through Data Binding

See original GitHub issue

It appears that data binding is possible for SVGs. I’m taking a different approach loading SVGs through data binding.

I have them all in a file structure like the below

Assets
   > Images
       > image-name.svg

Then I have the Images bound in my XAML

<ffimageloadingsvg:SvgCachedImage 
 WidthRequest="50" 
 HeightRequest="50" 
 Source="{Binding ImageSource}"/>

And a ViewModel containing the path data for the SVGs. I’ve tried several approaches as you can see (commented most out for testing purposes) and they all fail 😢 .

MenuItems = new ObservableCollection<MenuItem>(new[]
            {                   
                    new MenuItem { Id = 1,
                        Title = "Facility Info",
                        CommandParameters = "",
                        ImageSource = Xamarin.Forms.ImageSource.FromResource("resource://myMTC.Assets.Images.user.svg") },
                    //new MenuItem { Id = 2,
                    //    Title = "Workshops",
                    //    CommandParameters = "",
                    //    ImageSource = SVG_ASSET_PATH + "user.svg" },
                    //new MenuItem { Id = 3,
                    //    Title = "Feedback",
                    //    CommandParameters = "",
                    //    ImageSource = Xamarin.Forms.ImageSource.FromResource("myMTC.Assets.Images.user.svg") },
                    //new MenuItem { Id = 4,
                    //    Title = "Artifacts",
                    //    CommandParameters = "",
                    //    ImageSource = Xamarin.Forms.ImageSource.FromFile("ms-appx:///Assets/Images/user.svg") },
                    //new MenuItem { Id = 4,
                    //    Title = "Action Items",
                    //    CommandParameters = "",
                    //    ImageSource = new Uri(SVG_ASSET_PATH + "Droid.saction-items.svg") },
            });

It appears the error is rooted somewhere in the ImagerLoaderTask API

ffimageloading\source\FFImageLoading.Common\Work\ImageLoaderTask.cs:463

--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <401c12b575cb4781b0a9e010ed5a0221>:0 
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <401c12b575cb4781b0a9e010ed5a0221>:0 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <401c12b575cb4781b0a9e010ed5a0221>:0 
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <401c12b575cb4781b0a9e010ed5a0221>:0 
08-23 14:41:49.328 I/mono-stdout( 5366):   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <401c12b575cb4781b0a9e010ed5a0221>:0 
08-23 14:41:49.328 I/mono-stdout( 5366):   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <401c12b575cb4781b0a9e010ed5a0221>:0 
08-23 14:41:49.328 I/mono-stdout( 5366):   at FFImageLoading.Work.ImageLoaderTask`2+<RunAsync>d__109[TImageContainer,TImageView].MoveNext () [0x00435] in C:\projects\ffimageloading\source\FFImageLoading.Common\Work\ImageLoaderTask.cs:463 

Running Release > 2.2.10-pre-428.

VS2017 Enterprise (using preview sometimes too)

on

Windows 10 Enterprise v1703 OS Build 15063.540 64 bit

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
daniel-luberdacommented, Aug 29, 2017

If you use assets located in PCL you can use following image sources:

  • "resource://myMTC.Assets.Images.user.svg" (string)
  • new EmbeddedResourceImageSource("myMTC.Assets.Images.user.svg")
  • ImageSource.FromResource("myMTC.Assets.Images.user.svg") (least efficient one)

If it’s located in a different assembly than your app, then you must also specify correct assembly:

  • "resource://myMTC.Assets.Images.user.svg?assembly=[FULL ASSEMBLY NAME]" (string)
  • new EmbeddedResourceImageSource("myMTC.Assets.Images.user.svg", assembly)
  • ImageSource.FromResource("myMTC.Assets.Images.user.svg", assembly) (least efficient one)

That’s all.

1reaction
daniel-luberdacommented, Aug 30, 2017

There are built in converters, just pass a string resource://myMTC.Assets.Images.user.svg. EmbeddedResourceImageSource is also Xamarin.Forms.ImageSource

Read more comments on GitHub >

github_iconTop Results From Across the Web

Xamarin.Forms Error loading SVG Image using Data ...
I'm using the Xamarin.FFImageLoading.Svg.Forms Nuget package. I have the Image Bindings in my XAML where I'm using a ListView.ItemTemplate to ...
Read more >
Xamarin Forms - using SVG images with SkiaSharp
Load the resource SVG as a stream from the assembly. Create an SKSvg object and load it with the stream. Draw it as...
Read more >
Newest 'ffimageloading' Questions - Stack Overflow
SVG image Download URL Link is not working in FFImageLoading in Xamarin Forms [duplicate]. I have stored the image in google drive and...
Read more >
How to Load SVG from URL in Android ImageView?
Steps for Loading SVG Image from URL. Step 1: Create a new Android Studio Project. For creating a new Android Studio project just...
Read more >
Image - .NET MAUI
The .NET MAUI Image displays an image that can be loaded from a local file, a URI, or a stream.
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