I am using signalr 2.2.2 in an MVC application. Everything works ok apart from the fact, that every time the application navigates to another page a console error in the following form is shown:
XML Parsing Error: no root element found
Location: http://localhost/signalr/abort?transport=serverSentEvents&clientProtocol=1.5&connectionToken=2elX1XZHXH0xmQaLZKyHUFW5Z2rb2DGRYEI...
This only happens in firefox. Does anybody know how to fix this? Thanks
Chosen solution You can do a clean reinstall and remove the Firefox program folder to ensure that all files are replaced. You may have to disable security software temporarily in case the problem persists. You can create a new profile as a quick test to see if your current profile is causing the problem.
If you get this error message try view the page source by pressing Ctrl + U Usually there is a " symbol in wrong place. And check your html syntax.
XML Parser ErrorWhen trying to open an XML document, a parser-error may occur. If the parser encounters an error, it may load an XML document containing the error description. The code example below tries to load an XML document that is not well-formed. You can read more about well-formed XML in XML Syntax.
Examine the Code. The SignalR chat application demonstrates two basic SignalR development tasks. It shows you how to create a hub. The server uses that hub as the main coordination object. The hub uses the SignalR jQuery library to send and receive messages.
It might be related to known Firefox-884693 issue. Based on some research (here and here), and searching through SignalR code, a fix would be to assign Content-Type
before response is sent back. So following files might have to be changed.
// src/Microsoft.AspNet.SignalR.Core/PersistentConnection.cs
private static Task FailResponse(IResponse response, string message, int statusCode = 400)
{
response.StatusCode = statusCode;
// response.ContentType = "text/plain"; // <--- ADD THIS LINE
return response.End(message);
}
// src/Microsoft.AspNet.SignalR.Core/Transports/WebSocketTransport.cs
private Task AcceptWebSocketRequest(Func<IWebSocket, Task> callback)
{
var accept = _context.Environment.Get<Action<IDictionary<string, object>, WebSocketFunc>>(OwinConstants.WebSocketAccept);
if (accept == null)
{
// Bad Request
_context.Response.StatusCode = 400;
// _context.Response.ContentType = "text/plain"; // <--- ADD THIS LINE
return _context.Response.End(Resources.Error_NotWebSocketRequest);
}
Action<IWebSocket> prepareWebSocket = socket => {
_socket = socket;
socket.OnClose = _closed;
socket.OnMessage = _message;
socket.OnError = _error;
};
var handler = new OwinWebSocketHandler(callback, prepareWebSocket, _maxIncomingMessageSize);
accept(null, handler.ProcessRequest);
return TaskAsyncHelper.Empty;
}
This would require submitting bug to open source project, forking, applying changes, testing it, creating pull request etc. which is longer project than I have time right now. If anyone wants to test this theory, thanks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With