Bug 30619 - InvalidOperationException when setting Button text
Summary: InvalidOperationException when setting Button text
Status: RESOLVED DUPLICATE of bug 30566
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 5.2
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2015-05-30 16:21 UTC by Johann Dirry
Modified: 2015-06-02 12:56 UTC (History)
1 user (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 Johann Dirry 2015-05-30 16:21:47 UTC
I have recently installed Visual Studio 2015 RC1 and wanted to test the Android Support (API Level 21). However, I got an UnsupportedOperationException with the example code:

    var button = FindViewById<Button>(Resource.Id.MyButton);
    var @string = $"{_count++} clicks!";
    button.Text = @string; // throws exception 'java.lang.UnsupportedOperationException: Use StringFactory instead.'

The following Workaround works, but it's rather clumpsy:

    var button = FindViewById<Button>(Resource.Id.MyButton);
    var @string = $"{_count++} clicks!";
    button.SetText(@string.ToCharArray(), 0, @string.Length); // works
Comment 1 Jonathan Pryor 2015-06-02 12:56:59 UTC
The problem is that you're running on Android-M, and Android-M doesn't like how we create java.lang.String instances:


Google says they'll have an actual fix in a future release, and we'll be providing a workaround for the current Android-M behavior in a future release.

*** This bug has been marked as a duplicate of bug 30566 ***