I upgraded a couple of my web app projects to Visual Studio 2010 this week. Generally speaking, I’ve been impressed with how smoothly the transition has been, with the usual exception of ReportViewer. After allowing VS2010 to automatically update my .rdlc files, I changed my web pages to reference and then changed the web.config to reference as well:

<compilation debug="true" targetFramework="4.0">
<add assembly="Microsoft.ReportViewer.WebForms, Version=, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="Microsoft.ReportViewer.Common, Version=, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>

<add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false"/>

<add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
When I tried to run this, I got a “The type ‘Microsoft.Reporting.WebForms.ReportViewer’ exists in both….” error, indicating that it was still finding as well as I added the following to the web.config, which fixed it:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity name="Microsoft.ReportViewer.WebForms" publicKeyToken="b03f5f7f11d50a3a"/>
<bindingRedirect oldVersion="" newVersion=""/>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity name="Microsoft.ReportViewer.Common" publicKeyToken="b03f5f7f11d50a3a"/>
<bindingRedirect oldVersion="" newVersion=""/>
Then I hit the big problem, one that kept me busy for the best part of a day. When I ran my new version on my development PC, all the expressions which evaluated fields from my dataset showed #ERROR. I tried creating some really simple expressions (e.g. myfield.Value.ToString()) but they also came back #ERROR. Expressions without data fields worked OK. Eventually I noticed that there was an error in the Output window in VS2010: “Request for the permission of type ‘System.Security.Permissions.SecurityPermission” had failed. I confess to not really understanding much about how .net module permissions work, but on Googling this error, it became clear that changes in the .net 4.0 execution permissions were causing this error. Eventually, the Microsoft documentation turned up this bit of code:
PermissionSet permissions = new PermissionSet(PermissionState.None);
permissions.AddPermission(new SecurityPermission(PermissionState.Unrestricted));
permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
Which did the trick, thankfully. I have no idea how it works, and I don’t understand what the original problem was, but hopefully this post will avoid someone else getting as downhearted as I was this afternoon!