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 ()
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)

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 for Bug 41512 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

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.