I am getting this error trying to call a web2.0 api call.
Message : "Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'NG_API_DNET_FRX.Models.mproject'."
Here is the JSON that is being sent in from the webpage. The website uses Angular.
{
"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"
}
Here is the JSON representation of what is passed in. I got this by hovering on the routine parameter and copying from the watch....
Note the double squigly {{...}} surrounding the object. JSONLint complains about this but it seems to be consistent across all the calls and web api deals with it.
?? is this my problem ??
{{
"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
}}
Here is 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);
//
}
}
There is no inner exception.
The value passed in does not include 3 properties defined on mproject
.
I do not believe that is the problem because I have had success in that scenario before.
I am working w/ dates today... that is most likely where the problem is.
While I of course would love someone to solve my problem for me, what I really need is to get more information on the exception so I know what is causing the problem.
So the question is : Why is this cast throwing an exception
What would really help is learning where can I find more information about why this cast is throwing an exception. If someone has troubleshooting techniques, I would love those as well.