AdaptiveCards icon indicating copy to clipboard operation
AdaptiveCards copied to clipboard

Rendering to image shouldn't crash when referenced images can't load

Open qpongo opened this issue 9 years ago • 4 comments

It would be nice if ImageRenderer handled unresolved urls a little more gracefully...

Here's the hack that I added to \AdaptiveCards\source\dotnet\Library\AdaptiveCards.Xaml.WPF\Rendering\ImageRenderer.cs for my purposes in case it helps.

        protected async Task GetImage(string url)
        {
            using (WebClient client = new WebClient())
            {
                byte[] data;
                try
                {
                    data = await client.DownloadDataTaskAsync(url).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    // Return a transparent 1x1 pixel PNG when there is a problem
                    data = Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=");
                }
                lock (Images)
                    Images[url] = data;
            }
        }

qpongo avatar Jul 20 '17 13:07 qpongo

Repro:

  1. create a card with some image that has a bad url
  2. Render it to an image... ImageRenderer renderer = new ImageRenderer(new HostConfig(), String.Empty); Stream stream = await renderer.RenderAdaptiveCardAsync(card, 600);

Expected: to get something back with placeholders or even just with the image missing

Actual: the card is not rendered at all (no image) -- library internally has an uncaught exception

qpongo avatar Jul 20 '17 14:07 qpongo

@almedina-ms can you pick this up?

shalinijoshi19 avatar Jul 06 '19 00:07 shalinijoshi19

I think this issue doesn't repro anymore

NotCrashing

almedina-ms avatar Jul 09 '19 17:07 almedina-ms

@qpongo can you please check with our latest 1.2.0 bits whether this issue still repro's for you? Thanks.

shalinijoshi19 avatar Jul 09 '19 21:07 shalinijoshi19