ASP.NET to Mono - getting a HTTP 500. Error processing request. System.ArgumentNullException: Argument cannot be null - mono

I'm working on my first ASP.NET to Mono port. I built a test site with several functionalities to test. One is just a simple form post. The error I'm getting is this:
Argument cannot be null. Parameter name: inputString
Description: HTTP 500. Error processing request.
Stack Trace:
System.ArgumentNullException: Argument cannot be null.
Parameter name: inputString
at System.Web.UI.ObjectStateFormatter.Deserialize (System.String inputString) [0x00000] in :0
at System.Web.UI.LosFormatter.Deserialize (System.String input) [0x00000] in :0
I tried to debug by commenting out all the code that dealt with a session variable or form input (Request.Form) but still got the error. I now have even all the code inside the page load commented out but still no dice.
This form was/is working fine as ASP.NET on IIS. Maybe there's a configuration I didn't do?
** EDIT **
I was able to pinpoint the problem to a custom Page class that I use to inherit from System.Web.UI.Page where I have overriden some of the base methods. When I switch back to System.Web.UI.Page, the error goes away. I do need my custom Page class. The error occurs when I do a form post/postback; initial load works fine.

* Problem solved * It was in the LosFormatter.Deserialize method. I had it checking if the string passed was null then revised it to use string.IsNullOrEmpty instead. Maybe it doesn't like empty strings either.

Related

FromForm annotation not supported in MapPost()ed methods?

.NET 6, purely WebAPI project. I have an endpoint method that is expecting a urlencoded form in the POST data. The method is added to the routing table by app.MapPost("/myendpoint", MyClass.MyEndpoint) in the program's startup file; it's not in a controller. The method currently goes:
[Consumes("application/x-www-form-urlencoded")]
[HttpPost]
public static async Task<IResult> MyEndpoint([FromForm]FormData TheForm)
where FormData is a record with the expected form fields.
I've tried some other annotations. The framework just won't let me consume the form. When invoked, the method either returns HTTP error 415, or, in some iterations, an exception is thrown somewhere in the pipeline saying that "Expected a supported JSON media type but got "application/x-www-form-urlencoded"."
Is urlencoded form parameter binding even supported in WebAPI? I would even settle for the form contents as a string, won't mind parsing myself (HttpUtility.ParseQueryString to the rescue).
For the time being, I read Request.Body from the HTTP context' request body, but that's crude and also error prone, as the context is known to go poof sometimes in async methods.
EDIT: also tried placing .Accepts<FormData>("application/x-www-form-urlencoded") on the MapPost() line. Same result.
Tried replacing the body parameter with [FromBody]byte [] Body, [FromBody]string Body.

An exception of type 'System.NullReferenceException' occurred in Podio.NET.dll

Since 6 July 2018 we have been receiving the following error when making API requests to Podio:
An exception of type 'System.NullReferenceException' occurred in
Podio.NET.dll
but was not handled in user code...
Line: PodioClient.AuthenticateWithApp(AppId, AppToken);
We haven't changed anything in our code.
This has basically just started happening. I can confirm we are using TLS 1.2.
Could someone shed some light on this issue?
We are using the libraries from here - http://podio.github.io/podio-dotnet/
Please use newest Podio .Net Nuget packages that are now published:
https://www.nuget.org/packages/Podio/
https://www.nuget.org/packages/Podio.Async/
Check them out :)
We have to forced the application to read TLS 1.2 from server by adding the code below at the beginning of the application:
'ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
But sometime the application is fail and return errors below, see screenshot attached.
Podio Errors
'2018-07-13 13:51:51.5860 ERROR Object reference not set to an instance of an object. Object reference not set to an instance of an object at PodioAPI.Podio.Request[T](RequestMethod requestMethod, String url, Object requestData, Object options). at PodioAPI.Podio.Get[T](String url, Dictionary`2 requestData, Object options) at PodioAPI.Services.FileService.DownloadFile(FileAttachment fileAttachment)'

Different 404 pages being returned from ASP.NET MVC 4

I have got a plain ASP.NET MVC 4 Internet application. When I go to /NotFound, I get his error page:
while if I go to /Home/About/something/nonexistent, I get
Can anyone tell me what's happening under the hood?
I've gone in GetControllerInstance of the DefaultControllerFactory class in System.Web.Mvc and I can see:
throw new HttpException(404,
String.Format(
CultureInfo.CurrentCulture,
MvcResources.DefaultControllerFactory_NoControllerFound,
requestContext.HttpContext.Request.Path));
but I can't figure out where that exception is being handled. Am I on the right track there?
The first case is a .NET error page - because your /NotFound URL is covered by your routes, but the controller isn't found. In other words, MVC handles the request because it has routes that match it (e.g. "{controller}/{action}/{id}" where all three parameters are optional or have defaults), but then finds that it's in over its head.
Assuming you're using the default routes, the exception is indeed thrown by GetControllerInstance - because there's no NotFoundController.
Going instead to "/Home/NotFound" would throw a similar exception (also a 404 HttpException) from Controller.HandleUnknownAction, because "NotFound" now is used as the action name.
In your second case, the URL doesn't match any route, so MVC doesn't handle it - instead IIS tries to handle it itself, and shows its own 404 page, because it also doesn't find any other handlers or actual files at the path indicated by the URL.
As for how to handle all those cases, this stackoverflow question should help.
The short version of where the exception thrown from GetControllerInstance is handled is "it isn't - in any place that you have control of". You can either use the global Application_Error method in global.asax, or use one of the many other approaches in the linked question (for example, replacing the controller factory with one that has GetControllerInstance overridden to add exception handling closer to where the problem occurs).

Bizarre WebAPI issue with action names

I've countered a very strange problem with my web service that I'm building with MVC4 / WebAPI.
Basically, I have one method called 'GetChildNodes' which, when I request it, gives me a 405: Method Not Allowed status code. If I rename this to 'Test', it works. If I rename it to 'GCN', it works. If I rename it to 'GetChildNode', I get the same error.
I've checked and double checked and each attempt, successful and unsuccessful, were requested properly but with varying results. I'm at a total loss as to how the method name can make any difference. I've tried restarts, reboots, it makes no difference.
Any clues would be appreciated!
If it helps, this is how I'm configuring the service:
config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{action}");
Fairly standard, I think.
Urgh, it was the prefix - 'Get' - which seems to tell WebAPI that the action is called from a GET request. Easily remedied by adding the 'HttpPost' (in System.Web.Http) attribute to the method.
[HttpGet]
[ActionName("GetChildNode")]
public ReturnValue GetChildNode()

Struts2 error handling - exception stack not found

I've encountered a strange thing. I have configured exception handling in struts 2.1.8 like stated here, only that I redirect to an action instead to JSP (to send emails...).
So, in the action I have
ActionContext ac = ActionContext.getContext();
String stackTrace = null;
if(ac.getValueStack().findValue("exceptionStack") != null) {
stackTrace = ac.getValueStack().findValue("exceptionStack").toString();
} else {
stackTrace = "Stack trace not found!";
}
I had to make this if-else because sometimes the value is null. I haven't found the difference why sometimes I get the stack trace and sometimes I don't. All the errors happen in Struts2.
Did anyone had similar problem? Can anybody directs me where is the problem?
if you map exception with chain result type you'll keep the same request and so the same ValueStack.
First, ValueStack is per-request (each thread has its own), so redirecting to a new action will cause you to lose any data you had in the previous request's ValueStack.
With that said, what is your goal here? The link you provided explains how to map different types of exceptions to custom error pages (or results). Why doesn't that work for you? You mention you want to send emails -- are you sending an email notification about the actual exception (and stack trace)?
If you can expand a bit about what you are trying to do, then perhaps we can give you some guidance.