Bug 30530 - Non-Mutable setters should throw a nicer NotImplementedException
Summary: Non-Mutable setters should throw a nicer NotImplementedException
Status: RESOLVED ANSWERED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: 2.4.0 (C6)
Hardware: Macintosh Mac OS
: Lowest normal
Target Milestone: ---
Assignee: Chris Hamons
URL:
Depends on:
Blocks:
 
Reported: 2015-05-28 04:32 UTC by David Lilley
Modified: 2015-10-06 17:32 UTC (History)
1 user (show)

Tags:
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:
Status:
RESOLVED ANSWERED

Description David Lilley 2015-05-28 04:32:26 UTC
The Following Code Produces a NotImplemementedException

NSParagraphStyle aNSParagraphStyle = NSParagraphStyle.DefaultParagraphStyle;
aNSParagraphStyle.LineBreakMode = NSLineBreakMode.TruncatingTail;
Comment 1 David Lilley 2015-05-28 05:23:11 UTC
The Subclassed version works: NSMutableParagraphStyle;

NSMutableParagraphStyle aNSParagraphStyle = new NSMutableParagraphStyle();
aNSParagraphStyle.LineBreakMode = NSLineBreakMode.TruncatingTail;

From Apple Docs thats worth noting in case anyone uses this work around

IMPORTANT

A paragraph style object should not be mutated after adding it to an attributed string; doing so can cause your program to crash.
Comment 2 Chris Hamons 2015-05-28 10:07:22 UTC
As you pointed out from the docs, what you are doing is invalid. You can not call any setters on non-mutable styles. 

We could make the exception nicer, but the root problem is a mis-use of the API.
Comment 3 Chris Hamons 2015-10-06 17:32:27 UTC
We do this consistently this way throughout our mutable APIs.