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 10.0.0.0 and then changed the web.config to reference 10.0.0.0 as well:

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

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

<handlers>
<add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
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 9.0.0.0 as well as 10.0.0.0. I added the following to the web.config, which fixed it:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.ReportViewer.WebForms" publicKeyToken="b03f5f7f11d50a3a"/>
<bindingRedirect oldVersion="9.0.0.0" newVersion="10.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.ReportViewer.Common" publicKeyToken="b03f5f7f11d50a3a"/>
<bindingRedirect oldVersion="9.0.0.0" newVersion="10.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
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));
ReportViewer1.LocalReport.SetBasePermissionsForSandboxAppDomain(permissions);
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!

Advertisements