alanjuden / MvcReportViewer

Custom Report Viewer control to replace MS Report Viewer on MVC projects (also works on .NET Core as a Report Viewer).
MIT License
173 stars 109 forks source link

dotnetcore 3.0 #92

Open usamabadr opened 5 years ago

usamabadr commented 5 years ago

the code runs well on netcore 2.2 but on netcore 3.0 RC1 gives check report parameters

Edilber commented 5 years ago

I am using this open source, but how that you say, in net core 3.0 release, give me an error at load report, System.MissingMethodException: Method not found: 'Microsoft.AspNetCore.Mvc.JsonResult Microsoft.AspNetCore.Mvc.Controller.Json. Any has resolved this? help!!

martinvaler commented 4 years ago

In .NET Core 3.0, I had to change the ViewReportPage() method.

ReportController.cs / ViewReportPage(): var jsonResult = Json( ... , new System.Text.Json.JsonSerializerOptions());

technomanuj commented 4 years ago

Facing the same problem as written by Edilber. alanjuden, Please do help !

PillowMetal commented 4 years ago

This issue reported by @usamabadr is caused by the fact that Newtonsoft.Json is no longer included in the .NET Core 3.x framework.. Core apps now use System.Text.Json by default.

There are two solutions, one involves modifying the ReportController from Alan's code as @martinvaler pointed out, and the other involves including a package reference and modifying your startup to instruct MVC to use Newtonsoft JSON.

Option #1: To reiterate @martinvaler's solution, in MvcReportViewer/ReportController/ViewReportPage method, completely replace the following code

new Newtonsoft.Json.JsonSerializerSettings() { ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver() });

with...

new System.Text.Json.JsonSerializerOptions());

Option #2: First add a package reference to your .csproj file for your project in the ItemGroup that contains your other package references...

<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0" />

Then, in your Startup.cs/ConfigureServices method, instruct MVC to use Newtonsoft JSON...

services.AddMvc().AddNewtonsoftJson();

This is compatible with all new MVC service registration methods as well (AddControllers, AddControllersWithViews, AddRazorPages) if you have switched over to the more granular methods along with endpoint routing... I just used the most common example here

Personally, I prefer option #1 to let .NET Core use it's new System.Text.Json package.

As far as the issue reported by @Edilber I never encountered that, but the class and method you reference still exist in .NET Core 3.x, so I would assume that the package reference that includes them is not being picked up somehow, which is in the Microsoft.AspNetCore.Mvc namespace and is already a using directive in the ReportController.

Realize that if your project file is referencing

<Project Sdk="Microsoft.NET.Sdk.Web">

then the metapackage Microsoft.AspNetCore.App is implicitly included which includes the entire .NET Core standard framework, however, if your project references something else, like...

<Project Sdk="Microsoft.NET.Sdk">

then you must explicitly include the metapackage in your project file with...

`

`

Sorry, can't be of much more help without knowing where and when this error is occurring for you

thoseposers commented 4 years ago

I'm running into the same issue as @Edilber. Could it be because in dotnetcore 3.0 the Controller.Json changed from Json(Object, JsonSerializerSettings) to Json(Object, Object)?

https://docs.microsoft.com/ru-ru/dotnet/api/microsoft.aspnetcore.mvc.controller.json?view=aspnetcore-3.1

Edilber commented 4 years ago

Hi, I had changed follow code for resolve my problem:

var jsonResult = Json( new { CurrentPage = contentData.CurrentPage, Content = content, TotalPages = contentData.TotalPages } //new Newtonsoft.Json.JsonSerializerSettings() //{ // ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver() //} This code is in public JsonResult ViewReportPage(string reportPath, int? page = 0)

Method of ReportController.cs, AlanJuden Project.

In my Startup.cs file, I put the follow configuration: `services.AddControllers() .AddMvcOptions(opt => opt.EnableEndpointRouting = false) .AddNewtonsoftJson(options => { // Use the default property (Pascal) casing options.SerializerSettings.ContractResolver = new DefaultContractResolver();

             });`

int the public void ConfigureServices(IServiceCollection services) Method.

I hope that help you @thoseposers

I have changed the design too, because it was in boostrap 3, but now I change to Boostrap 4.

justindbaur commented 4 years ago

@Edilber Hi, would you be able to share your version of this project you used, I would love an updated design for bootstrap 4.

Edilber commented 4 years ago

@justindbaur In this file you can find this design Boostrap4. CoreHtmlHelpers.zip

ghost commented 3 years ago

@Edilber Hi, I am trying to port this to bootstrap 4 and I am getting a method not found error on the following "SetParameters" line. Any thoughts? var contentData = new ReportExportResult(); var definedParameters = ReportServiceHelpers.GetReportParameters(model, true); contentData.SetParameters(definedParameters, model.Parameters); parameters = contentData.Parameters;

Edilber commented 3 years ago

What is the file where you are getting this error? You must have all project of AlanJuden, only replace the file CoreHtmlHelpers.cs

RodFoulcher commented 3 years ago

Have also had this problem while trying to upgrade from .net core 2.1 to 5.0 and eventually solved it in a different way.

Please refer: https://stackoverflow.com/questions/69188236/how-do-i-overcome-missingmethodexception-please-am-running-out-of-ideas/69231885#69231885

Hope this helps someone else.

rinkayadav commented 1 year ago

thanks its resolve but now im getting another exception related to jsonresult . System.InvalidOperationException: Property 'JsonResult.SerializerSettings' must be an instance of type 'Newtonsoft.Json.JsonSerializerSettings'. at Microsoft.AspNetCore.Mvc.NewtonsoftJson.NewtonsoftJsonResultExecutor.GetSerializerSettings(JsonResult result) at Microsoft.AspNetCore.Mvc.NewtonsoftJson.NewtonsoftJsonResultExecutor.ExecuteAsync(ActionContext context, JsonResult result) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.gLogged|22_0(ResourceInvoker invoker, IActionResult result) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.gAwaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.gLogged|17_1(ResourceInvoker invoker) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker) at Microsoft.AspNetCore.Routing.EndpointMiddleware.gAwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

RodFoulcher commented 1 year ago

@rinkayadav Sorry but havent updated to 6.0 so cant help much. If you are really stuck then suggest you update your 2.0 to 5.0 and apply changes I made to see if that works for you. If it does then you have a brand new problem to solve.

rinkayadav commented 1 year ago

Thank u for your suggestion and help now its working fine .

Edilber commented 1 year ago

@rinkayadav You must change the result type of ViewReportPage method in ReportController.cs from AlanJuden's Project to:

var jsonResult = Json( new { CurrentPage = contentData.CurrentPage, Content = content, TotalPages = contentData.TotalPages }.

return jsonResult;

Greetings!!