Bug 41512 - [PlainString] attribute doesn't work on parameters on protocol methods
Summary: [PlainString] attribute doesn't work on parameters on protocol methods
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll (show other bugs)
Version: XI 9.8 (tvOS / C7)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
Depends on:
Reported: 2016-06-05 00:51 UTC by Israel Soto [MSFT]
Modified: 2016-07-19 13:40 UTC (History)
3 users (show)

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


Description Israel Soto [MSFT] 2016-06-05 00:51:31 UTC
Created attachment 16197 [details]
[PlainString] usage sample

When you are binding an Objective-C class method with `const char *` as parameter, you need to add [PlainString] attribute to C# parameter so, when you pass a string, it passes, literally, a string and not the reference of a NSString.

// @interface CStringTest : NSObject
[BaseType (typeof (NSObject), Name = "CStringTest")]
interface CString
	// - (void)CStringMethodWithMessage:(const char *)message;
	[Export ("CStringMethodWithMessage:")]
	void CStringMethod ([PlainString] string message);

But when you have a protocol method with `const char *` as parameter and you add [PlainString] attribute to C# parameter, it compiles but it crashes at runtime:

// @protocol CStringDelegate <NSObject>
[BaseType (typeof (NSObject))]
interface CStringDelegate
	// @required - (void)CStringRequiredMethodWithMessage:(const char*)message;
	[Export ("CStringRequiredMethodWithMessage:")]
	void CStringAbstractMethod ([PlainString] string message);

Does this is a bug?

I attached a sample that has the Xcode project, Binding project and a sample that reproduce the bug.

Israel Soto
Comment 1 Alex Soto [MSFT] 2016-06-07 05:54:51 UTC
> Does this is a bug?

Yes, you found a missing feature, thanks for the report! I can reproduce it with the test case you provided.

Note You need to log in before you can comment on or make changes to this bug.