I have a problem serializing pcl class object because the class objects property is cannot be evaluated. The structure of my solution is having three projects -
- Xamarin.Android, reference Services, and Dto
- PCL (for Services), reference Dto (target frameworks: .Net Framework 4.5, ASP.Net Core 1.0, Windows 8, Windows Phone 8.1, Xamarin.Android, Xamarin.iOS, Xamarin.iOS(Classic)
- PCL (for Dto)) (target frameworks: .Net Framework 4.5, ASP.Net Core 1.0, Windows 8, Windows Phone 8.1, Xamarin.Android, Xamarin.iOS, Xamarin.iOS(Classic)
I have one method in my service class like -
public async Task<HttpResponseMessage> SignIn(string username, string password)
{
var user = new Dto.UserLogin(username, password);
var serialize = Newtonsoft.Json.JsonConvert.SerializeObject(user);
var content = new StringContent(serialize);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
HttpResponseMessage response = null;
using (var client = GetClient("{urlhere}", username, "POST"))
{
response = await client.PostAsync("api/{methodname}", content);
}
return response;
}
The code above does not throw error and can instantiate the "user" variable. However the problem was that when the serialization line happens, it serialize nothing. It seems like the "user" object is cannot access or show the two properties "Email" and "Password". But I can access them in debug using "user.Email". I've attached a screenshot of it.
Email and Password properties are public.
Thanks, Marvin

