12

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!

Community
  • 1
  • 1
Bill
  • 821
  • 7
  • 14
  • 1
    It may be a completely unrelated problem, however from my experience I avoid .jpg's like the plague in SSRS for this reason: https://stackoverflow.com/questions/15654779/ssrs-cant-properly-render-some-images-within-pdf SSRS for me has been know to cause weird un-replicatable issues with jpgs – Pants May 24 '19 at 14:53
  • 1
    Thanks @ChanceFinley. I tried with some PNG files with no luck – Bill May 28 '19 at 10:19
  • 1
    Just guessing here, but could it be that some kind of authentication header/cookie is required in order to access the image on the server? If so, you'd be able to access it by entering the URL in the browser (you are likely logged in) but the report engine may not be able to access it... – user1429080 Jun 04 '19 at 06:23
  • @user1429080 I don't think that's it. If I hardcode the URL to the image it displays it fine without any authentication. It seems it's only when it's an expression or direct from a data field when it's a problem. – Bill Jun 05 '19 at 07:02
  • @Bill Makes sense, so probably something else then... – user1429080 Jun 05 '19 at 11:02
  • 1
    Ok let’s try something, what happens if you use a regular picturebox and use URL from your database? Let’s see if it displays there that way we know the urls you’re getting are indeed correct – traveler3468 Jun 05 '19 at 22:22
  • @AndrewE Thanks, I just tried it and if I take the url manually from the dataset and hardcode it into the Value the image displays fine. However if I change the standalone image to use an expression it produces the same behaviour as previously. I used the expression `=First(Fields!imageUrl.Value, "AnswerData")`. So again it seems like it's the fact it's an expression that's the problem. I've verified the URL produced in the dataset is correct by rendering it in a textbox in the report. – Bill Jun 06 '19 at 09:04
  • Have you tried binding it and assigning it to the parameter? Rather than just whatever it gets from the dataset I’m guessing you have created with the wizard. – traveler3468 Jun 06 '19 at 09:06
  • Does that mean passing the URL in as a parameter of the report to see if that renders correctly? I can give that a go. As far as the creation of it goes, I wrote the query in SSMS and then put it into a report I've been editing in Visual Studio 2013 with Business Intelligence tools installed. I'm about to try a new report with a very basic dataset of just image URLs – Bill Jun 06 '19 at 09:26

2 Answers2

3

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.

Bill
  • 821
  • 7
  • 14
0

In the properties of the Image object, I would check that the MIMEType property has been correctly set, e.g. image/jpeg.

My understanding is that your web browser is smart enough to guess correctly without this information, but the SSRS rendering engine is not that smart.

Mike Honey
  • 14,523
  • 1
  • 24
  • 40