• GoDaddy Community
  • Websites + Marketing | Website Builders
  • Websites + Marketing | Website Builders

    cancel
    Showing results for 
    Show  only  | Search instead for 
    Did you mean: 
    Highlighted

    WebAPI failed to return a List when hosted on Godaddy

    We've a simple webAPI returns list of custom object, when calling the method it returns the below error:

    The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.

    The code has run normally in the dev environment:

     

        public class TestController : ApiController
        {
            public List<Person> GetService()
            {
                List<Person> result = new List<Controllers.Person>();
                result.Add(new Person() { Name = "Koko", Age = 40 });
                result.Add(new Person() { Name = "Koko2", Age = 50 });
                result.Add(new Person() { Name = "Koko3", Age = 50 });
                return result;
            }
        }
    
        public class Person
        {
            public string Name { get; set; }
            public int Age { get; set; }
        }

    We're hosting the WebAPI under Windows Delux hosting, under a subdomain, the other webAPI methods that return none list types are working fine, please advise.

     

    Below the stack trace of the detailed exception:

    Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.",
    "ExceptionType": "System.Security.SecurityException",
    "StackTrace": " at System.Delegate.DelegateConstruct(Object target, IntPtr slot)\r\n at Newtonsoft.Json.Utilities.LateBoundReflectionDelegateFactory.CreateParametrizedConstructor(MethodBase method)\r\n at Newtonsoft.Json.Utilities.CollectionUtils.ResolveEnumableCollectionConstructor(Type collectionType, Type collectionItemType)\r\n at Newtonsoft.Json.Serialization.JsonArrayContract..ctor(Type underlyingType)\r\n at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateArrayContract(Type objectType)\r\n at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)\r\n at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)\r\n at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n at System.Net.Http.Formatting.JsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)\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.Web.Http.WebHost.HttpControllerHandler.<WriteBufferedResponseContentAsync>d__1b.MoveNext()

     

    1 REPLY 1
    Highlighted

    Re: WebAPI failed to return a List when hosted on Godaddy

    I have same issue