Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Service Stack:Type definitions should start with a '{', expecting serialized type 'AuthResponse', got string starting with

i am using the following code to athenticate the user using ServiceStack basic auth provider in my asp.net application and receiving serilization exception.Please answer if anyone has solve this problem.Thank you.

I am using the following code in my asp.net application:

<asp:Button ID="btnAuth" runat="server" OnClick="btnAuth_Click" Text="Authenticate"/>

I am recieving exception on clien.Post method in code behind file.

protected void btnAuth_Click(object sender, EventArgs e)
        {
            try
            {                
                var baseUrl = Request.Url.GetLeftPart(UriPartial.Authority) + "/api";
                var client = new JsonServiceClient(baseUrl);
                var authResponse = client.Post<AuthResponse>(new Auth { UserName = "admin", Password = "12345" });
                if (authResponse.ResponseStatus.ErrorCode == null)
                {
                   //Do Something here
                }
            }
            catch (WebServiceException ex)
            {
                throw ex;
            }
        }

Followin is Exeception Detail which i am recieving on clien.Post method:

[SerializationException: Type definitions should start with a '{', expecting serialized type 'AuthResponse', got string starting with: 
like image 483
Naeem Raza Avatar asked Nov 13 '22 05:11

Naeem Raza


1 Answers

Serialization exception that reads "expecting serialized type 'X', got string starting with:" means that the serializer tries to create an object from an empty string instead of a proper json-formatted string ("{Class:{Property:{Sub:value}}}").

In this case, most likely cause is server at baseUrl returning no response (interpreted as empty string) to a POST request. Misconfigured URL or exception on server side, maybe?

like image 151
user270576 Avatar answered Nov 15 '22 11:11

user270576