I'm use ASP.NET MVC end I take this error only in FF. Why I take this error message? What is the cause of this? I don't understand where the source of this error. Anyone have any thoughts?
11 Answers
Check this link for more information
Based on my research, the error message is only generated by FireFox when the render page is blank in Internet. For some reason, .NET generates a response type of "application/xml" when it creates an empty page. Firefox parses the file as XML and finding no root element, spits out the error message.
in other words, this is a known Firefox issue
-
In internet explorer, I don't get the error but it only does not work like expected. Jan 7, 2019 at 14:08
-
2
For some reason, .NET generates a response type of "application/xml" when it creates an empty page
This is not true, there is no Content-Type in empty response Mar 27, 2019 at 10:12 -
-
Getting this when using Discord via Browser >< Solution is to set
privacy.webrtc.legacyGlobalIndicator
to false. Apr 6 at 8:29
I changed the type of return value in Action method and it worked. More details can be found in my article on this topic.
Changed from
return Ok();
to
return Json("Ok");
-
2You could also return NoContent(); Which is more or less equivalent to return StatusCode(204); return Ok(null); will also make Firefox happy. The difference between the two is explained very well here: stackoverflow.com/questions/59861379/…– Kevin UIJan 26, 2021 at 21:14
public IActionResult MethodName()
{
// YOUR CODE
return StatusCode(204);
}
Code 204 -The server successfully processed the request, and is not returning any content
For more details about status code check this page: List of HTTP status codes
I fixed this in my app by setting the Content-Type
header on the server to text/plain
. Like this in Node:
res.setHeader('Content-Type', 'text/plain');
Use whatever MIME type is appropriate for your data, ie application/json
, etc.
I've seen the XML Parsing error: no root element
error in a few different situations. It's typically present in the Firefox developer console only.
Returning a
200 OK
response code with an empty body. Your server should instead return a204 No Content
response code.Returning a
204 No Content
response code and then attaching content to the response. Your server should instead return a200 OK
response code.Returning an incorrect
Content-Type
. Set it to the same type that's used in your response body (JSON, XML, plaintext, etc.), or it could get parsed incorrectly.
If none of these fixes your issue, I would review all of your response headers for correctness. Other fields like Content-Length
could presumable interfere as well.
This is the top Google result for this error message and I don't see an answer covering another tricky case yet, so here goes:
This will also happen if your SVG is served correctly, but is missing the closing </svg>
tag! For example, in case the response is only served partially, because it is a streaming response and it errors out mid-way…
I resolved my problem with
return NoContent();
It seems more clear When you want to return nothing.
This can happen too, if you have a [ValidateAntiForgeryToken] attribute on your controller action and try to submit the form without an actual token. You can render the token explicitly with
@Html.AntiForgeryToken()
which is the preferred solution or remove the validation attribute.
We were getting this error when POSTing an axios call. And our test server was not in the
allowed-origin:
list of hosts. Adding our server to allowed-origin in the application.yml resolved the issue.
I fixed by returning OkObjectResult instead of Ok().
Old Code:
Return Ok();
New Code:
return new OkObjectResult(true);
Note: OkObjectResult can be used after adding namespace Microsoft.AspNetCore.Mvc.Infrastructure.
If you go to about:config
and set:
privacy.webrtc.legacyGlobalIndicator = false
The warning won't appear.