سؤال

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.

هل كانت مفيدة؟

المحلول 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.

نصائح أخرى

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>

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.

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.

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.

This error occured first time, definition is invalid. When I debug again, the error changing into :

AspNetCore.Reporting.LocalProcessingException: An error occurred during local report processing.;The process cannot access the file 
'C:\Users\OPTIMUS PRIME\AppData\Local\Temp\b75e496e6c4d453fbf39526dd5952c14.xls.tmp' because it is being used by another process. 
---> System.IO.IOException: The process cannot access the file 'C:\Users\OPTIMUS PRIME\AppData\Local\Temp\b75e496e6c4d453fbf39526dd5952c14.xls.tmp' 
because it is being used by another process. at System.IO.FileSystem.DeleteFile(String fullPath) 
at System.IO.File.Delete(String path) 
at AspNetCore.ReportingServices.Rendering.ExcelRenderer.ExcelGenerator.BIFF8.StructuredStorage.CreateSingleStreamFile(Stream source, String streamName, String clsId, Stream output, Boolean forceInMemory) 
at AspNetCore.ReportingServices.Rendering.ExcelRenderer.Excel.BIFF8.BIFF8Generator.SaveSpreadsheet(Stream outputStream, Stream backgroundImage, UInt16 backgroundImageWidth, UInt16 backgroundImageHeight) 
at AspNetCore.ReportingServices.Rendering.ExcelRenderer.MainEngine.Save(Stream output) 
at AspNetCore.ReportingServices.Rendering.ExcelRenderer.ExcelRenderer.Render(Report report, NameValueCollection reportServerParameters, NameValueCollection deviceInfo, NameValueCollection clientCapabilities, Hashtable& renderProperties, CreateAndRegisterStream createAndRegisterStream) 
--- End of inner exception stack trace --- 
at AspNetCore.Reporting.InternalLocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings) 
at AspNetCore.Reporting.InternalLocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings) 
at AspNetCore.Reporting.InternalLocalReport.Render(String format, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings) at AspNetCore.Reporting.LocalReport.Execute(RenderType renderType, Int32 pageIndex, Dictionary`2 parameters, String findString) 
at ProjectName.Controllers.ReportController.ReportBrandingAsync(String Cabang, String DisplayProgram, String Brand, String DateFrom, String DateTo) 
in ProjectDirName\Controllers\ReportController.cs:line 267

I try to run :

LocalReport localReport = new LocalReport(path);
localReport.AddDataSource("dsBranding", oResult);
var result = localReport.Execute(RenderType.Excel, extension, parameters, mimeType);

And because the error is so weird, changing twice but I am not doing anything, then I try to check my disk that C drive is full.

enter image description here

Trying to delete some files freeing some space, and not changing code, the report is fine again

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top