An error occurred during local report processing.The definition of the report ' is invalid

I am new to using SSRS. I am using a .rdlc file for report generation in a PDF with VS 2012. When I tried to set the parameters like

ReportParameter param = new ReportParameter(kvp.Key, kvp.Value);
LocalReport.SetParameters(param);

This throws an exception:

An error occurred during local report processing..The definition of the report '' is invalid.. Could not load file or assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Access is denied.

More details:

{Microsoft.Reporting.WebForms.LocalProcessingException: An error occurred during local report processing. ---> Microsoft.Reporting.DefinitionInvalidException: The definition of the report '' is invalid. ---> System.IO.FileLoadException: Could not load file or assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Access is denied.
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(String assemblyName, String typeName)
   at System.AppDomain.CreateInstance(String assemblyName, String typeName)
   at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
   at System.AppDomain.CreateAppDomainManager()
   at System.AppDomain.Setup(Object arg)
   at System.AppDomain.nCreateDomain(String friendlyName, AppDomainSetup setup, Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, IntPtr parentSecurityDescriptor)
   at System.AppDomainManager.CreateDomainHelper(String friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
   at System.AppDomainManager.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
   at System.AppDomain.InternalCreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
   at System.AppDomain.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
   at Microsoft.Reporting.ReportCompiler.CreateCompilationTempAppDomain()
   at Microsoft.Reporting.ReportCompiler.CompileReport(ICatalogItemContext context, Byte[] reportDefinition, Boolean generateExpressionHostWithRefusedPermissions, ControlSnapshot& snapshot)
   --- End of inner exception stack trace ---
   at Microsoft.Reporting.ReportCompiler.CompileReport(ICatalogItemContext context, Byte[] reportDefinition, Boolean generateExpressionHostWithRefusedPermissions, ControlSnapshot& snapshot)
   at Microsoft.Reporting.LocalService.GetCompiledReport(PreviewItemContext itemContext, Boolean rebuild, ControlSnapshot& snapshot)
   at Microsoft.Reporting.LocalService.CompileReport()
   at Microsoft.Reporting.LocalService.Microsoft.Reporting.ILocalProcessingHost.CompileReport()
   at Microsoft.Reporting.WebForms.LocalReport.EnsureExecutionSession()
   --- End of inner exception stack trace ---
   at Microsoft.Reporting.WebForms.LocalReport.EnsureExecutionSession()
   at Microsoft.Reporting.WebForms.LocalReport.SetParameters(IEnumerable1 parameters)
   at Microsoft.Reporting.WebForms.Report.SetParameters(ReportParameter parameter)

What am I missing. In some posts, it 's been advised to use missing Microsoft.ReportViewer.PorcessingObjectMode.dll. I did that so I have all the required dlls like:

-    Microsoft.ReportViewer.Common.dll
-    Microsoft.ReportViewer.WebForms.dll
-    Microsoft.ReportViewer.ProcessingObjectModel.dll

are there.

I referred to this post. But still I could not get this done.


Solution 1:

I faced the same issue when i deployed an application to azure. After several hours of debugging, i noticed that Microsoft.SqlServer.Types was not the same version with other reporting dlls. Hence you should make sure these dlls are of the same version. Edit their dependency in Web.config as shown below

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
        <assemblyIdentity name="Microsoft.ReportViewer.DataVisualization" publicKeyToken="89845dcd8080cc91" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.ReportViewer.Common" publicKeyToken="89845dcd8080cc91" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

Solution 2:

In my case , In the local environment the report was working but not in staging environment . the reason is , the folder which i published my code doesn't have the .rdlc file itself . That caused this error.

  1. Now I copy pasted the .rdlc file in the appropriate staging folder and it worked .

or

  1. Before do publish your application , right click on the .rdlc file and goto properties then choose content under Build Action . Then publish the application and check the folder , .rdlc file will be there.

  2. Now move this from your dev environment to other environment.

Hope this might help somebody.

Solution 3:

The easy way to do it , go into the properties of your

".rdlc" file and change the Build Action to "Content "

, Copy To Output Directory to "Copy Always " ,

and if you change the version number of "Microsoft.ReportViewer.WebForms" , "Microsoft.ReportViewer.ProcessingObjectModel" , "Microsoft.ReportViewer.Common"

make sure you go into the properties and make specific version to be true under property . We explored all the solutions and Finally This worked.

Solution 4:

EDIT: Solution seem to be that the report defintion was not loaded. It can be done for example by

var reportStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("ReportName.rdlc"); 
localReport.LoadReportDefinition(reportStream);

Old suggestion - not applicable here:

Honestly, there might be different things. First of all, setting parameters is special. If your projects runs in .NET 4 or higher the reporting engine will run within a different app domain than your application. So you have to set permissions that the parameters can be used. Otherwise it rejects all parameter.

var report = new LocalReport();
report.SetBasePermissionsForSandboxAppDomain(new PermissionSet(PermissionState.Unrestricted));

Another issue could be that you are using a different ReportViewer version on your development machine than on the deployment machine.

Solution 5:

For me it was because I hadn't added a reference to the reporting assemblies (Microsoft.ReportViewer.*) to the project.

For some reason it worked when running from VS, but running the actual published site would result in this error.