Tuesday, October 8, 2013

How to work around issue with using Visual Studio 2012 / Web Application to create a .rdlc report using Report Viewer Control

I don't know what I am missing, but as far as I can tell the Report Viewer in Visual Studio 2012 does NOT work properly when using a ASP.NET Web Forms Application. Notice I said APPLICATION, not Web SITE. To clarify, there is no issue you create a ASP.NET Web Forms Site Here is the scenario I will propose a work around to.

  1. Open Visual Studio 2012
  2. Create a new ASP.NET Web Forms Application (This is the critical choice to make this break)
  3. Create a report and call it Report1.rdlc
  4. Open your default page. The master page should have a Script Manager on it already. If it doesn't then you will need to add it.
  5. Drag the ReportViewer control from the Toolbox to the content area on the Default page (or other page).
  6. Use the SmartTag (the little box with a triangle in it on the upper right corner of the ReportViewer control to choose your report. This will create an ObjectDataSource with the improper configured.
  7. You can verify the ObjectDataSource is configured improperly by clicking the Refresh Schema task on the Smart Tag of the ObjectDataSource. It will generate an error similar to:

    The 'AdventureWorks2008R2DataSetTableAdapters.SalesOrderDetailTableAdapter' could not be loaded. If the type is located in teh App_Code folder, please check that it compiles. If the type is located in a complied assembly, please check that the assembly is referenced by the project.

    The type 'AdventureWorks2008R2DataSetTableAdapters.SalesOrderDetailsTableAdapter' could not be found'
  8. Reconfigure the ObjectDataSource and you will see that the problem is that it should have the namespace before the type (that it can't find). It is as if the Microsoft developer that did this functionality didn't realize the ObjectDataSource that would be created is different depending if you are using a ASP.NET Web Forms Application or a ASP.NET Web Forms Site.

  9. Run the application and you will get an error similar to this:

    An error occurred during local report processing.The report definition for report 'Report1' has not been specified Object reference not set to an instance of an object.
  10. To fix that issue, you need to select the Report Viewer and look at the Properties pane. 
  11. Scroll down to where it says LocalReport and expand that area using the Plus sign (+).
  12. Set the ReportPath property to Report1.rdlc (or whatever the filename is of your report).
  13. Run the application again. This time it will hopefully work. 

Alternatives
  1. Do everything in code.
  2. Don't use the smart tag - Create the ObjectDataSource first and make the bindings to the Collection and ReportPath yourself using the Properties panel (not the smart tag since the bug seems to be in the Smart Tag of the ReportViewer).

No comments: