Search code examples
xamarinxamarin.androidportable-class-library

Portable class library object properties cannot be evaluated


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 -

  1. Xamarin.Android, reference Services, and Dto
  2. 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)
  3. 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)

solution structure

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.

enter image description here

Email and Password properties are public.

Thanks, Marvin


Solution

  • The comment from @Jack helps me to figure out the culprit. In Xamarin.Android property settings->Android options->linker, currently it is set to "SDK and User assemblies". I changed it to "SDK Assemblies Only" and this solved the problem.