Project Type: Mobile Apps / Class Library / Xamarin.Forms portable
I'm trying to serialise an object into JSON format by DataContractJsonSerializer:
DataContractJsonSerializer serializer = new DataContractJsonSerializer (type);
Stream s = new MemoryStream ();
serializer.WriteObject (stream, graph);
When I post the data to the server, internal server error returns because content is empty but the same logic works other than Xamarin.Forms projects:
HttpContent httpContent = new StreamContent (s);
HttpResponseMessage httpResponseMessage = await httpClient.PostAsync (uri, httpContent);
Besides I want to close stream s by:
s.Close ();
But XS throws:
Type `System.IO.Stream' does not contain a definition for `Close' and no extension method `Close' of type `System.IO.Stream' could be found. Are you missing an assembly reference? (CS1061)
This is a library project and has:
.NET Portable Subset
From Packages
System.Net.Http
System.Net.Http.Extensions
System.Net.Http.Primitives
Xamarin.Forms.Code
Xamarin.Forms.Xaml
as references.
Is it really a missing assembly issue or does System.IO.Stream class have issues?