Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
Created attachment 5962 [details]
I get an ArgumentNullException with this code:
var attributedString = new NSAttributedString("Hello, World!", foregroundColor: null);
That is unexpected because the default value for the foregroundColor (along with every other attribute argument) is null.
The reason I want this is that I am writing a method that does something like this:
private static void AppendStringToAttributedString(NSMutableAttributedString attributedString, string appendString, UIColor foregroundColor = null)
using (var attributedAppendString = new NSAttributedString(appendString, foregroundColor: foregroundColor))
I want to be able to call it like this:
using (var attributedString = new NSMutableAttributedString())
AppendStringToAttributedString("World!", foregroundColor: UIColor.Red);
The exception prevents me from doing this. :|
This should be fixed in both NSAttributedString and NSMutableAttributedString, and ideally anywhere else where this pattern exists.
After deploying attached sample on simulator we are getting same issue.
Exception Detail: https://gist.github.com/saurabh360/04e71a37998744db0750
IDE Log : https://gist.github.com/saurabh360/0d270b0c89a9fea74cef
The ObjC API uses an NSDictionary  and XI added a strongly-typed `UIStringAttributes` overload.
Internally this returns a NSDictionary (for consumption by the ObjC API) but can return `null` if no member is set (that code is used elsewhere).
Sadly  does not specify allowing null so there's no [NullAllowed] in the bindings. OTOH it likely does allow null (most similar API does, but I'll confirm/test that) and adding a [NullAllowed] would fix this (otherwise I'll fix the 2nd code part, which returns a null instead of an empty dictionary).
A nil NSDictionary is accepted by the ObjC API.
Fixed in master 83a12543a40bb24299ed45ed60fe01732b322e98
QA: unit tests added in the same revision
I have checked this issue on following builds:
Xamarin Studio : 4.2.4 (build 32)
Xamarin.iOS : 18.104.22.168 (Trial Edition)
Release ID: 402040032
Git revision: a160c35dac9ab9fd32eeadaa171216316d5a5133
Build date: 2014-03-12 13:55:08-04
Xamarin addins: a779416ceabd54981ce812771a4061c942e8b872
I observe that now I am not getting an ArgumentNullException with the following code:
"var attributedString = new NSAttributedString("Hello, World!", foregroundColor:null);"
I have check this issue with attached project for "NSAttributedString" and "NSMutableAttributedString" and these are working fine.
This issue is working fine.Hence, I am closing this issue.
Please let me know if I have to check anything else.