Encountering an issue while attempting to call a web2.0 API.
Error Message: "Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'NG_API_DNET_FRX.Models.mproject'."
The JSON data sent from the webpage (which utilizes Angular) is as follows:
{
"id": "3137",
"clientId": "2",
"Name": "MFAQ project1",
"EstimatedStartDate": "07/01/2022",
"EstimatedEndDate": "07/08/2022",
"ActualStartDate": "07/15/2022",
"ActualEndDate": "07/22/2022",
"EstimatedBudget": "44444.0000",
"ActualBudget": "55555.0000"
}
This is the representation of the JSON passed in, with double curly braces {{...}}:
{{
"id": 3137,
"clientId": 2,
"Name": "MFAQ project1",
"EstimatedStartDate": "07/13/2022",
"EstimatedEndDate": "6/8/2022",
"ActualStartDate": "6/15/2022",
"ActualEndDate": "6/22/2022",
"EstimatedBudget": 44444,
"ActualBudget": 55555
}}
Describing the target structure:
public class mproject
{
public int id;
public int clientId;
public string Name;
public string EstimatedStartDate;
public string EstimatedEndDate;
public string ActualStartDate;
public string ActualEndDate;
public decimal EstimatedBudget;
public decimal ActualBudget;
public string sbProperties;
public string projectType;
public mprojectRev[] Revisions;
}
[System.Web.Http.HttpPatch]
[Route("{itemId_}")]
public IHttpActionResult PatchItemById([FromUri] int itemId_, [FromBody] mproject webForm_ )
{
//if the parameter is of type mproject webform is null
//If i change the type to dynamic or object, and then try to //it, this is where i get the error
//mproject webForm_;
//try
//{
// webForm_ = (mproject)webForm_1;
//}
//catch (Exception ex)
//{
// return JSONStringResultExtension.JSONString(this, errorAsJSON(ex), HttpStatusCode.InternalServerError);
//
}
}
No inner exception reported. The input does not include 3 properties defined on mproject
, but I do not believe that to be the root cause, as it has worked before. Focusing on date-related issues for now.
In need of more insights on why the casting error persists rather than a direct solution. Seeking guidance on troubleshooting techniques.
Querying: What triggers this casting exception?
Interested in discovering resources offering detailed information about the casting error. Open to suggestions on effective troubleshooting approaches.