LocalReport in full .net class library referenced in .net core project

2

I'm trying to build a service to export a rdlc Localreport from one of my actions in my webapi. Webapi is built on .net core 3.1

I know that reportviewer is not compatible with .net core, so to try and mitigate that I've got a class library project added to my project based on .net framework 4.7.2. Added the reference to the class library to my .net core webapi, so far so good. I'm able to call methods from my class library, no problem.

Now try adding LocalReport to a class in my class library....

using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Reports
{
    public class RenderAction
    {
        public void GetOrderReport()
        {
            string codeBase = Assembly.GetExecutingAssembly().CodeBase;
            UriBuilder uri = new UriBuilder(codeBase);
            string path = Uri.UnescapeDataString(uri.Path);
            string p = Path.GetDirectoryName(path);
            string reportPath = Path.Combine(p, "Reports","Order.rdlc");

            if (!File.Exists(reportPath)) { return; }

            var report = new LocalReport();


        }
    }
}

intellisense prompted to install Microsoft.Reporting.Viewer so I did so... When calling my function in runtime, I get the following error when creating the new instance of localreport:

System.MissingMethodException
  HResult=0x80131513
  Message=Method not found: 'Void System.AppDomainSetup.set_ActivationArguments(System.Runtime.Hosting.ActivationArguments)'.
  Source=Microsoft.ReportViewer.Common
  StackTrace:
   at Microsoft.Reporting.ReportRuntimeSetupHandler.InitAppDomainPool(Evidence sandboxEvidence, PolicyManager policyManager)
   at Microsoft.Reporting.LocalService..ctor(ILocalCatalog catalog, Evidence sandboxEvidence, PolicyManager policyManager)
   at Microsoft.Reporting.ControlService..ctor(ILocalCatalog catalog)
   at Microsoft.Reporting.WebForms.LocalReport..ctor()
   at Myproject.Reports.RenderAction.GetOrderReport() in C:\Users\RudiGroenewald\source\repos\Myproject-Api-Common\Myproject_Api_Common\Myproject_Reports\RenderAction.cs:line 24
   at Myproject.Api.Common.Controllers.ReportsController.Get() in C:\Users\RudiGroenewald\Source\Repos\Myproject-Api-Common\Myproject_Api_Common\Myproject_Api_Common\Controllers\ReportsController.cs:line 22
   at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<<InvokeActionMethodAsync>g__Logged|12_1>d.MoveNext()

It seems like some sort of dll version mismatch or something... a bit stumped really.

Is it just not possible to get this working? My alternative is to have a full .net webapi, just for reportwriting, which I prefer not to do. Any thoughts on what I'm doing wrong?

core
reportviewer
asked on Stack Overflow Aug 10, 2020 by Tjopsta

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0