Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSRS external image not displayed when value set by expression

I am using Microsoft.ReportViewer.WebForms version 11 via an aspx page embedded in an MVC application. The report is rendered directly as a PDF from the report viewer.

Problem

I have a tablix that displays external images. The images don't display if the URL to the image is calculated from an expression or set from a column in the database. The image only displays if I hardcode the URL directly in the report. Obviously this is not a solution, but it shows that the report is capable of accessing the URL and rendering the image.

I get these warnings from rendering the report:

The ImageData for the image ‘LinkedImage’ is invalid. Details: Invalid URI: The format of the URI could not be determined.

The value of the ImageData property for the image ‘LinkedImage’ is “”, which is not a valid ImageData.

What I've tried

  1. I've double checked the URL that gets generated and it is correct. I've even made it the click action a hyperlink to the image and it goes to the image correctly.

  2. Initially I was concatenating the URL in the expression but after this didn't work I had the SQL Query build the entire URL. It still doesn't display.

  3. I have tried setting a flag:

    reportViewer.LocalReport.EnableExternalImages = true;
    
  4. Using .NET Reflector to generate PDB files I was able to step through the code of the report viewer. There is a flag on the value object called "IsExpression" which is set to false when the report renders. I don't know much about the inner workings of the Report viewer so I don't know if this is a red herring.

  5. I've changed the output format to HTML and it still doesn't display. The image markup (as seen in Chrome developer tools) renders as:

    <img onload="this.fitproportional=true;this.pv=0;this.ph=0;" height="5px" width="1px" src=(unknown)>
    
  6. I've tried setting the MIMEType value to the correct value for each image. (Thanks Mike Honey for the suggestion)

  7. I have tried the different Sizing values of AutoSize, Fit, FitProportional, and Clip.

  8. I both repaired and reinstalled entirely the ReportViewer runtime installation using the installer here: https://www.microsoft.com/en-gb/download/details.aspx?id=35747

  9. I have run the website from my local Visual Studio instance and a deployed version in a website on another server (same installed ReportViewer version) and the problem persists.

I'd like to draw attention to number 4. Could there be a configuration which is causing the ReportViewer code to not see the value as an expression?

Code

Here is the markup in the RDL:

<Image Name="LinkedImage">
    <Source>External</Source>
    <Value>=Fields!imageUrl.Value</Value>
    <Sizing>FitProportional</Sizing>                               
    <Style>
        <Border>
            <Style>None</Style>
        </Border>
    </Style>
</Image>

Here's an example URL (host removed from example):

http://---------/images/FEE40608-0457-E511-A17F-00155D145C00/FFE40608-0457-E511-A17F-00155D145C00.jpg

Am I missing something? Thanks!

like image 444
Bill Avatar asked May 24 '19 08:05

Bill


1 Answers

I've gotten to the bottom of it finally. This issue turned out to be caused by a bespoke ReportProcessor class that has been added to the MVC application that manipulates the RDL before the rendering even takes place. Specifically it removes the = character from the Value node of Image nodes in the RDL. It didn't occur to me that the report wasn't getting to the rendering stage in its original condition. I'll pay the price of that with the Reputation I spent!

This issue will be unique to people who have introduced a different ReportProcessor that does manipulation of the RDL in this way, so I don't know how useful it will be for people finding this question on SO. I'll leave it here as it could be used as a list of things to check.

Sorry for wasting everyone's time. Thanks to Mike-Honey, user1429080 and AndrewE for their time and effort.

like image 167
Bill Avatar answered Nov 09 '22 00:11

Bill