Bug 35503 - The class `System.Net.Http.StringContent' has no constructors defined
Summary: The class `System.Net.Http.StringContent' has no constructors defined
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 9.4 (iOS 9.2)
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-11-03 12:28 UTC by Cody Beyer (MSFT)
Modified: 2015-11-03 21:55 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Cody Beyer (MSFT) 2015-11-03 12:28:29 UTC
### Description

The following sample app demonstrates an issue that only surfaces when running on an iOS device. The app attempts to serialize and then deserialize a JSON string

### Sample


### Error


### Steps to Reproduce

1. Download sample
2. Deploy to iOS Device
3. Click Log In

### Expected Result

Message Box should appear displaying "true" to indicate JSON task worked

### Actual Results

Error is thrown as described above

### Versions

=== Xamarin Studio ===

Version 5.9.8 (build 0)
Installation UUID: 73204efb-3f52-4561-bfd0-1a9af26f9341
	Mono 4.0.5 ((detached/1d8d582)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400050001

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/codybeyer/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Apple Developer Tools ===

Xcode 7.1 (9079)
Build 7B91b

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 1f068b4
Branch: master
Build date: 2015-10-27 18:59:21-0400

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 509080000
Git revision: cc5f6e5658589ca7f46210c57fad947e75f30abd
Build date: 2015-10-21 19:27:41-04
Xamarin addins: d77f191bd7d3451adf837b85b38f2b7c60004400

=== Operating System ===

Mac OS X 10.11.1
Darwin Codys-MBP.router 15.0.0 Darwin Kernel Version 15.0.0
    Sat Sep 19 15:53:46 PDT 2015
    root:xnu-3247.10.11~1/RELEASE_X86_64 x86_64
Comment 1 Sebastien Pouliot 2015-11-03 13:48:34 UTC
Most serialization, including JSON, use reflection which is not linker-friendly. You'll need to protect what your code requires thru reflection.
Comment 3 Balakrishnan 2015-11-03 15:28:02 UTC
Hi Sebastien,

You meant to say not to use JSON with Xamarin, Is it possible to use older version of JSON to overcome this Issue?. Is it any other solution/workaround to overcome this issue?

In my case I need to post the data and get the Response as JSON only, So that I am worrying.

Thanks & Regards
Comment 4 Sebastien Pouliot 2015-11-03 21:55:26 UTC
Hello Balakrishnan,

Sorry, support should have spotted this without opening a bug report.

Do not worry you can use JSON/serialization with Xamarin. However the managed linker uses static analysis to detect what's needed at runtime. Anything that use reflection (like most serialization libraries) needs a bit of help so the information is available.

In your case it's not JSON but your use of `dynamic` that cause issues. Apple does not allow a JIT to be used so everything that needs to execute on device must be AOT'ed.

That means some features, like dynamic, needs to be interpreted - and that requires reflection (not linker friendly). As interpretation is rather slow and would require extra steps to ensure nothing else gets removed you're much better using code like:

		class Data {
			public string Username;
			public string Password;

        private async void btnLoginClicked(object sender, EventArgs e)
            // inline code to test IOS starts here.
			var obj = new Data ()
				Username = EmailText.Text,
                Password = PasswordText.Text,

note: since it's faster the simulator does not have the managed linker enabled (it's more productive this way). It's different for device where it's both faster (and a lot smaller) to have the linker enabled by default on all SDK assemblies. This is part of why testing regularly on devices is very important.