Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnetcore 3.0 #92

Open
usamabadr opened this issue Oct 7, 2019 · 15 comments
Open

dotnetcore 3.0 #92

usamabadr opened this issue Oct 7, 2019 · 15 comments

Comments

@usamabadr
Copy link

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

@Edilber
Copy link

Edilber commented Oct 28, 2019

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
Copy link

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

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

@technomanuj
Copy link

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

@PillowMetal
Copy link

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...

<ItemGroup> <FrameworkReference Include="Microsoft.AspNetCore.App" /> </ItemGroup>

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

@thoseposers
Copy link

thoseposers commented Jun 12, 2020

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
Copy link

Edilber commented Jun 12, 2020

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
Copy link

@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
Copy link

Edilber commented Jul 14, 2020

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

@ghost
Copy link

ghost commented Nov 11, 2020

@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
Copy link

Edilber commented Nov 12, 2020

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

@RodFoulcher
Copy link

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
Copy link

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.g__Logged|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.g__Awaited|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.g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

@RodFoulcher
Copy link

@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
Copy link

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

@Edilber
Copy link

Edilber commented Jan 10, 2023

@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!!

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

No branches or pull requests

9 participants