Reputation: 2771
I have a Azure Mobile App Service (not old mobileservice), with multiple custom controllers, and the flow works perfectly.
Today an error occurred about Internal Server Error
.
I attached the debugger an stepped through the code, and the controller gets to the end without any errors and hits the return Ok
. Therefore I have not been able to find the root. But the client then gets the error that there is an internal server error.
I make a server call like:
DTO.UserDTO uploadImage = await ((App)Application.Current).MobileService.InvokeApiAsync<DTO.UsernameCheckDto, DTO.UserDTO>("user/blobStorageRetrieval", new DTO.UsernameCheckDto() { Username = ((App)Application.Current).InGameUserName }, System.Net.Http.HttpMethod.Post, null);
The custom controller ends with:
return Ok(new UserDTO()
{
MicrosoftId = stable_sid,
Username = stable_users.Username,
playerNames = playerNames,
playerScores = playerInts,
isCreated = true,
bestScore = stable_users.bestRunnerScore,
statsInformation = _statsInformation,
});
I have verified that all the variables are initialized. The Type UserDTO is referenced from the same Portable Library
. Can anybody hint how I can find the cause of this error? The controller has worked before without any changes.
Generic Error Message
"The request could not be completed. (Internal Server Error)" string
Response
{StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Server: Microsoft-IIS/8.0 Date: Fri, 30 Sep 2016 17:37:57 GMT X-Powered-By: ASP.NET Content-Length: 36 Content-Type: application/json; charset=utf-8 }} System.Net.Http.HttpResponseMessage
stack
StackTrace " at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.d__24.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.d__26.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.d__18.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.WindowsAzure.MobileServices.MobileServiceClient.d__69.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.WindowsAzure.MobileServices.MobileServiceClient.d__63 2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at Stonegaard_endless_runner.MainPage.d__7.MoveNext()" string
Searching Sid oh stackoverflow. And found an issue from 2 years ago. Web API converted to Azure Mobile Service not serializing all properties
I will try this tomorrow.
Upvotes: 2
Views: 881
Reputation: 2771
The solution was to add:
httpConfig.Formatters.JsonFormatter.SerializerSettings.DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Include;
httpConfig.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Include;
to Startup.MobileApp.cs
in the method ConfigureMobileApp
.
Upvotes: 2