Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Asp.Net Core MVC site with Microsoft.ReportViewer.2015.Runtime #4910

Closed
mbharodia opened this issue Jun 26, 2016 · 19 comments
Closed

Asp.Net Core MVC site with Microsoft.ReportViewer.2015.Runtime #4910

mbharodia opened this issue Jun 26, 2016 · 19 comments
Assignees
Labels

Comments

@mbharodia
Copy link

mbharodia commented Jun 26, 2016

Hi,

I was porting my web site written in older MVC to Asp.Net Core MVC. I have a report using RDLC. That runs fine on older site but throws the following error on core MVC.

Failed to load expression host assembly. The source of error is Microsoft.ReportViewer.WebForms.
An exception of type 'Microsoft.Reporting.WebForms.LocalProcessingException' occurred in Microsoft.ReportViewer.WebForms.dll but was not handled in user code

I think it might have to do with some sort of security or permission while running the required DLLs for the report viewer. I have added Microsoft.ReportViewer.2015.Runtime package and it uses Microsoft.ReportViewer.Common.dll, Microsoft.ReportViewer.ProcessingObject.dll and Microsoft.ReportViewer.WebForms.dll.

Please also note that I am trying to generate a byte stream of pdf file using LocalReport's Render method. I have also tried adding the following attributes to the method responsible to call the above render call and generate a byte stream.

[FileIOPermissionAttribute(SecurityAction.Assert, Unrestricted = true)]
[SecurityPermission( SecurityAction.Assert, Unrestricted = true)]

The old and new MVC sites both target full .Net framework 4.6.1. The reportviewer runtime works with the older site but not with newer. The older site doe not need any security permission or attribute as mentioned above. Is there any recommendation on how to use runtime with Asp.Net Core MVC targeting full .Net framework 4.6.1?

@Eilon
Copy link
Member

Eilon commented Jun 28, 2016

@mbharodia can you share your project.json file?

@mbharodia
Copy link
Author

mbharodia commented Jun 29, 2016

Hi Elion,

{
"userSecretsId": "aspnet-CCClients.Core-8f5c9517-b59e-4aaf-8d2a-9372699c0552",

"dependencies": {
"Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview1-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview1-final",
"type": "build"
},
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc2-final",
"Microsoft.Extensions.Options.ConfigurationExtensions":"1.0.0-rc2-final",
"Microsoft.Extensions.Logging": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc2-final",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview1-final",
"type": "build"
},
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
"version": "1.0.0-preview1-final",
"type": "build"
},
"RestSharp": "105.2.3",
"NLog.Extensions.Logging": "1.0.0-rc2-final-2016-05-21",
"Microsoft.ReportViewer.2015.Runtime": "12.0.2.2402",
"CrystalReports": "13.0.5.891",
"AutoMapper":"4.2.1"
},

"tools": {
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
},
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
},
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview1-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
},
"Microsoft.Extensions.SecretManager.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
},
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview1-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
}
},

"frameworks": {
"net461": {
"dependencies": {
"CCClients.BusinessService": {
"target": "project"
},
"CCClients.Interfaces": {
"target": "project"
},
"CCClients.RepositoryService": {
"target": "project"
},
"EntityFramework": "6.1.3"
}
}
},

"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},

"publishOptions": {
"include": [
"wwwroot",
"Views",
"appsettings.json",
"web.config",
"nlog.config"
]
},

"scripts": {
"prepublish": [ "npm install", "bower install", "gulp all" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}

@mbharodia
Copy link
Author

Just a further note on the error I am getting. Here is the full error message.

Failed to load expression host assembly. Details: Type 'Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DataStoreErrorLogger+DataStoreErrorLog' in assembly 'Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' is not marked as serializable.

at Microsoft.ReportingServices.RdlExpressions.ReportRuntime.ProcessLoadingExprHostException(ObjectType assemblyHolderObjectType, Exception e, ProcessingErrorCode errorCode)
at Microsoft.ReportingServices.RdlExpressions.ReportRuntime.LoadCompiledCode(IExpressionHostAssemblyHolder expressionHostAssemblyHolder, Boolean includeParameters, Boolean parametersOnly, ObjectModelImpl reportObjectModel, ReportRuntimeSetup runtimeSetup)
at Microsoft.ReportingServices.OnDemandProcessing.Merge.Init(Boolean includeParameters, Boolean parametersOnly)
at Microsoft.ReportingServices.OnDemandProcessing.Merge.Init(ParameterInfoCollection parameters)
at Microsoft.ReportingServices.ReportProcessing.Execution.ProcessReportOdp.CreateReportInstance(OnDemandProcessingContext odpContext, OnDemandMetadata odpMetadata, ReportSnapshot reportSnapshot, Merge& odpMerge)
at Microsoft.ReportingServices.ReportProcessing.Execution.ProcessReportOdp.Execute(OnDemandProcessingContext& odpContext)
at Microsoft.ReportingServices.ReportProcessing.Execution.RenderReportOdpInitial.ProcessReport(ProcessingErrorContext errorContext, ExecutionLogContext executionLogContext, UserProfileState& userProfileState)
at Microsoft.ReportingServices.ReportProcessing.Execution.RenderReport.Execute(IRenderingExtension newRenderer)
at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.RenderReport(IRenderingExtension newRenderer, DateTime executionTimeStamp, ProcessingContext pc, RenderingContext rc, IChunkFactory yukonCompiledDefinition)
at Microsoft.Reporting.LocalService.CreateSnapshotAndRender(ReportProcessing repProc, IRenderingExtension renderer, ProcessingContext pc, RenderingContext rc, SubreportCallbackHandler subreportHandler, ParameterInfoCollection parameters, DatasourceCredentialsCollection credentials)
at Microsoft.Reporting.LocalService.Render(String format, String deviceInfo, String paginationMode, Boolean allowInternalRenderers, IEnumerable dataSources, CreateAndRegisterStream createStreamCallback)
at Microsoft.Reporting.WebForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings)

I am wondering why it is loading EntityFrameworkCore when I try to run LocalReport’s Render() method. I am sure I am missing something here. I think I am not looking for any logging at this moment at least.

From: Eilon Lipton [mailto:notifications@github.com]
Sent: Tuesday, June 28, 2016 3:18 PM
To: aspnet/Mvc Mvc@noreply.github.com
Cc: Mayur Bharodia mayur@interactiveinterfaces.ca; Mention mention@noreply.github.com
Subject: Re: [aspnet/Mvc] Asp.Net Core MVC site with Microsoft.ReportViewer.2015.Runtime (#4910)

@mbharodiahttps://github.com/mbharodia can you share your project.json file?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com//issues/4910#issuecomment-229186580, or mute the threadhttps://github.com/notifications/unsubscribe/AJ3Ywd3pfQlvqLpRuD1VhCCPmDiYiBAvks5qQY98gaJpZM4I-lGk.

@mbharodia
Copy link
Author

mbharodia commented Jun 29, 2016

error
[cid:image001.png@01D1D1FD.8E905610]

From: Eilon Lipton [mailto:notifications@github.com]
Sent: Tuesday, June 28, 2016 3:18 PM
To: aspnet/Mvc Mvc@noreply.github.com
Cc: Mayur Bharodia mayur@interactiveinterfaces.ca; Mention mention@noreply.github.com
Subject: Re: [aspnet/Mvc] Asp.Net Core MVC site with Microsoft.ReportViewer.2015.Runtime (#4910)

@mbharodiahttps://github.com/mbharodia can you share your project.json file?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com//issues/4910#issuecomment-229186580, or mute the threadhttps://github.com/notifications/unsubscribe/AJ3Ywd3pfQlvqLpRuD1VhCCPmDiYiBAvks5qQY98gaJpZM4I-lGk.

@mbharodia
Copy link
Author

When I removed app.UseDatabaseErrorPage() from Configure() method in Startup I was able to run the report. Any idea why? Thanks a lot for looking into this.

From: Eilon Lipton [mailto:notifications@github.com]
Sent: Tuesday, June 28, 2016 3:18 PM
To: aspnet/Mvc Mvc@noreply.github.com
Cc: Mayur Bharodia mayur@interactiveinterfaces.ca; Mention mention@noreply.github.com
Subject: Re: [aspnet/Mvc] Asp.Net Core MVC site with Microsoft.ReportViewer.2015.Runtime (#4910)

@mbharodiahttps://github.com/mbharodia can you share your project.json file?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com//issues/4910#issuecomment-229186580, or mute the threadhttps://github.com/notifications/unsubscribe/AJ3Ywd3pfQlvqLpRuD1VhCCPmDiYiBAvks5qQY98gaJpZM4I-lGk.

@Eilon
Copy link
Member

Eilon commented Jun 30, 2016

@mbharodia thanks for the detailed info!

@pranavkm can you investigate?

@pranavkm
Copy link
Contributor

pranavkm commented Jul 6, 2016

I tried generating a LocalReport with a Sql Server 2014 instance and it seemed to work fine (with or without the call to UseDatabaseErrorPage). I'm not super familiar with reporting, so it'd be great if you could look at what I was trying to do here and let me know if there's something I'm doing different \ incorrect that's causing things to work: https://github.com/pranavkm/reporting/blob/master/src/WebApplication3/Controllers/HomeController.cs#L16

@pranavkm
Copy link
Contributor

@mbharodia, have you had a chance to look at my repo as yet?

@rharmonjr
Copy link

I apologize if I am violating protocol by commenting on a closed thread but do not see a final resolution. I am experiencing the same problem, and resolution is the same - commenting out UseDatabaseErrorPage in Startup eliminates the error. Here's my code:

[HttpPost]
public ActionResult ContractDetails()

    {
        var dataSet = getData("Report_ContractDetails");

        var localReport = new LocalReport()
        {
            ReportPath = @"Reports\ContractDetails.rdlc",
            EnableExternalImages = false
        };

        localReport.DataSources.Add(new ReportDataSource("DataSet1", dataSet));
        var bytes = localReport.Render("PDF", null, out string mimeType, out string encoding, out string fileNameExtension, out string[] streams, out Warning[] warnings);

        return File(bytes, "application/pdf");
    }

private DataTable getData(string sqlView)

    {
        var dataSet = new DataSet();

        using (var sqlConnection = new SqlConnection(Startup.ConnectionString))
        {
            var sqlCommand =
                new SqlDataAdapter(sqlView, sqlConnection)
                {
                    SelectCommand = {CommandText = ("select * from " + sqlView)}
                };

            sqlConnection.Open();
            sqlCommand.Fill(dataSet);
            sqlConnection.Close();
        }

        return dataSet.Tables[0];
    }

@rynowak
Copy link
Member

rynowak commented Apr 24, 2017

@rharmonjr - can you please open a new issue and give us a full description of the problem you have?

@fer-rios
Copy link

fer-rios commented Feb 9, 2018

Hi @mbharodia ! I'd to know if you could make works the Report Viewer with .Net Core !?

@mbharodia
Copy link
Author

The web app I migrated in 2016 targeted Asp.Net Core (full .Net framework 4.6.1 support). This web app has been upgraded to use Asp.Net Core 2.0. I believe that it works. However, please note that I am not using report viewer to show reports on the browser. The report viewer simply uses RDLC to generate a byte stream of PDF that can be downloaded using browser. Having said this, I am not sure whether it works for a web app that supports only .Net Core. I am also showing the template that I used from Visual studio to make things clear that it uses full .Net framework

I added Microsoft.ReportViewer.2015.Runtime NuGet package to get required references for report viewer. You may try adding this reference to your web app and see if that works.

2018-02-09 11_00_19

@jkljajic
Copy link

jkljajic commented Apr 1, 2018

Hi, I have the same issue with Microsoft.ReportViewer.2015.Runtime but in my case is related to nlog provider,
if I implement this NLog.Extensions.Logging in dotnet core all report return same error about not marked for serialization.

Removing NLog.Extensions.Logging implementation all reports working normal

@scotteby
Copy link

Is anyone using subreports in their RDLC file?

I was able to get the main report to render after removing the .UseNLog() option in Startup.cs, but the subreport won't load. This is the error I get in the rendered pdf report:

The subreport 'Subreport' could not be found at the specified location C:\Source\Web\wwwroot
\Reports\Subreport.rdlc. Please verify that the subreport has been published and that the name is correct.

The subreport is in the same folder as the main report, and I even tried using the LocalReport.LoadSubreportDefinition method but get the same result.

This works find in my older ASP.NET MVC project.

@scotteby
Copy link

I was able to resolve my issue with subreports by using a newer version of ReportViewer. The ReportViewer.2015.Runtime is version 12, but I needed to use

Microsoft.ReportingServices.ReportViewerControl.WebForms, which is version 14.

So, I still have the issue with NLog. Has anyone figured out how to get these 2 to work together? Anyone try upgrading to the latest beta of .NET Core?

@scotteby
Copy link

I just tried this again with .Net Core 2.1 and still get the same error if I enable Nlog in Startup.cs:

Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: Failed to load expression host assembly. Details: Type 'Microsoft.AspNetCore.Mvc.Internal.MvcCoreLoggerExtensions+ActionLogScope' in assembly 'Microsoft.AspNetCore.Mvc.Core, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' is not marked as serializable.

@luisabreu
Copy link

+1 here with the same error. Btw, here's the complete stack:

Microsoft.Reporting.WebForms.LocalProcessingException: An error occurred during local report processing. ---> Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: Failed to load expression host assembly. Details: Type 'Microsoft.AspNetCore.Mvc.Internal.MvcCoreLoggerExtensions+ActionLogScope' in assembly 'Microsoft.AspNetCore.Mvc.Core, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' is not marked as serializable.
at Microsoft.ReportingServices.RdlExpressions.ReportRuntime.ProcessLoadingExprHostException(ObjectType assemblyHolderObjectType, Exception e, ProcessingErrorCode errorCode)
at Microsoft.ReportingServices.RdlExpressions.ReportRuntime.LoadCompiledCode(IExpressionHostAssemblyHolder expressionHostAssemblyHolder, Boolean includeParameters, Boolean parametersOnly, ObjectModelImpl reportObjectModel, ReportRuntimeSetup runtimeSetup)
at Microsoft.ReportingServices.OnDemandProcessing.Merge.Init(Boolean includeParameters, Boolean parametersOnly)
at Microsoft.ReportingServices.OnDemandProcessing.Merge.Init(ParameterInfoCollection parameters)
at Microsoft.ReportingServices.ReportProcessing.Execution.ProcessReportOdp.CreateReportInstance(OnDemandProcessingContext odpContext, OnDemandMetadata odpMetadata, ReportSnapshot reportSnapshot, Merge& odpMerge)
at Microsoft.ReportingServices.ReportProcessing.Execution.ProcessReportOdp.Execute(OnDemandProcessingContext& odpContext)
at Microsoft.ReportingServices.ReportProcessing.Execution.RenderReportOdpInitial.ProcessReport(ProcessingErrorContext errorContext, ExecutionLogContext executionLogContext, UserProfileState& userProfileState)
at Microsoft.ReportingServices.ReportProcessing.Execution.RenderReport.Execute(IRenderingExtension newRenderer)
at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.RenderReport(IRenderingExtension newRenderer, DateTime executionTimeStamp, ProcessingContext pc, RenderingContext rc, IChunkFactory yukonCompiledDefinition)
at Microsoft.Reporting.LocalService.CreateSnapshotAndRender(ReportProcessing repProc, IRenderingExtension renderer, ProcessingContext pc, RenderingContext rc, SubreportCallbackHandler subreportHandler, ParameterInfoCollection parameters, DatasourceCredentialsCollection credentials)
at Microsoft.Reporting.LocalService.Render(String format, String deviceInfo, String paginationMode, Boolean allowInternalRenderers, IEnumerable dataSources, CreateAndRegisterStream createStreamCallback)
at Microsoft.Reporting.WebForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings)
--- End of inner exception stack trace ---
at Microsoft.Reporting.WebForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings)
at Microsoft.Reporting.WebForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
at Microsoft.Reporting.WebForms.LocalReport.Render(String format, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
at Microsoft.Reporting.WebForms.Report.Render(String format, String deviceInfo, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
at Grm.GestaoFrotas.NetCore.Frotas.Results.PdfReportActionResult.ExecuteResultAsync(ActionContext context) in D:\code\work\tfsonline\GestaoFrotas\code\GestaoFrotas\Grm.GestaoFrotas.NetCore.Frotas\ActionViews\PdfReportActionResult.cs:line 39
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__20.MoveNext()

Not sure on how this got closed with any sort of explanation....

@snakefoot
Copy link

snakefoot commented Aug 12, 2018

NLog.Extensions.Logging ver. 1.2.1 has been released that improves support for BeginScope across AppDomain-boundary. See also NLog/NLog.Extensions.Logging#232

Please update to make RDLC work together with AspNetCore and NLog.

@amh1979
Copy link

amh1979 commented Aug 20, 2018

AspNetCore.Reporting this support LocalReport and ServerReport, may be useful to you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests