4
votes

I wrote a code to parse json string in my android xamarin app.

            var request = HttpWebRequest.Create(myUrl);
            request.ContentType = "application/json";
            request.Method = "GET";
            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {            
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    Console.Out.WriteLine("Error fetching data. Server returned status code: {0}", response.StatusCode);
                }
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                {
                    string content = reader.ReadToEnd();
                    if (string.IsNullOrWhiteSpace(content))
                    {
                        Console.Out.WriteLine("Response contained empty body...");
                    }
                    else
                    {                        
                        List<BillsTableFields> billList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<BillsTableFields>>(content);                        
//return block
                    }
                }
            }    

but it throws a build error. Any help would be appreciated as I am a new to xamarin and I can't find any support anywhere else. The build error I got is given below

C:\Program Files\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(5,5): Error MSB4018: The "LinkAssemblies" task failed unexpectedly.

Mono.Cecil.ResolutionException: Failed to resolve System.Diagnostics.TraceLevel

at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)

at Mono.Linker.Steps.MarkStep.MarkField(FieldReference reference)

at Mono.Linker.Steps.MarkStep.InitializeFields(TypeDefinition type)

at Mono.Linker.Steps.MarkStep.InitializeType(TypeDefinition type)

at Mono.Linker.Steps.MarkStep.InitializeAssembly(AssemblyDefinition assembly)

at Mono.Linker.Steps.MarkStep.Initialize()

at Mono.Linker.Steps.MarkStep.Process(LinkContext context)

at Mono.Linker.Pipeline.Process(LinkContext context)

at MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context)

at Xamarin.Android.Tasks.LinkAssemblies.Execute()

at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()

at Microsoft.Build.BackEnd.TaskBuilder.d__20.MoveNext() (MSB4018) (LoginApptest)

1

1 Answers

3
votes

If the linker fails with "failed to find type blah blah", then this normally means you are using a desktop .Net library somewhere in your app. If it is JSON.Net, remove the desktop assembly and use the version of JSON.Net on the component store (this is Xamarin's version of NuGet, except some things are paid).

I would also make sure you have the latest version of Xamarin.Android.