Open usamabadr opened 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!!
In .NET Core 3.0, I had to change the ViewReportPage() method.
ReportController.cs / ViewReportPage():
var jsonResult = Json( ... , new System.Text.Json.JsonSerializerOptions());
Facing the same problem as written by Edilber. alanjuden, Please do help !
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
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)?
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.
@Edilber Hi, would you be able to share your version of this project you used, I would love an updated design for bootstrap 4.
@justindbaur In this file you can find this design Boostrap4. CoreHtmlHelpers.zip
@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;
What is the file where you are getting this error? You must have all project of AlanJuden, only replace the file CoreHtmlHelpers.cs
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.
Hope this helps someone else.
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.
@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.
Thank u for your suggestion and help now its working fine .
@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!!
the code runs well on netcore 2.2 but on netcore 3.0 RC1 gives check report parameters