Bug 13680 - NSDictionary.FromObjectsAndKeys(Object [] objects, NSObject [] keys, int count) ignores the "count" parameter
Summary: NSDictionary.FromObjectsAndKeys(Object [] objects, NSObject [] keys, int coun...
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 6.4.0
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-08-01 08:58 UTC by Adrian Gallero
Modified: 2013-08-06 17:27 UTC (History)
3 users (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 FIXED

Description Adrian Gallero 2013-08-01 08:58:05 UTC
NSDictionary.FromObjectsAndKeys(Object [] objects, NSObject [] keys, int count) will always insert the full objects[] and keys[] arrays, no matter what count you specify.

Steps to reproduce:
Write the following code in an even handler:

        partial void testdict(NSObject sender)
        {
            var keys = new object[]{1,2};
            var objs = new object[]{3,4};
            NSDictionary ns = NSDictionary.FromObjectsAndKeys(objs, keys, 1);
            Console.WriteLine(ns.Count);
        }

Actual Results: 2
Expected Results: 1

Note that NSDictionary.FromObjectsAndKeys(NSObject [] objects, NSObject [] keys, int count) works fine.
This code:
       partial void cttext(NSObject sender)
        {

            var keys = new NSObject[]{new NSNumber(1), new NSNumber(2)};
            var objs = new NSObject[]{new NSNumber(1), new NSNumber(4)};
            NSDictionary ns = NSDictionary.FromObjectsAndKeys(objs, keys, 1);
            Console.WriteLine(ns.Count);
        }

inserts 1 object as expected.
Comment 1 Rolf Bjarne Kvinge [MSFT] 2013-08-01 15:14:10 UTC
Fixed. The fix will be in 6.4.2.

maccore/master: e2759379f3b9fa7006eb42fc6dd1144a9d82555c
monotouch/master-3.0: 2a46fbb43e6ec2c1dfa885f3e9453d95942cbd90
monotouch/monotouch-6.4-series: cea601c38bc9e942ad837ac269e990962b6baa8f

QA: unit tests have been added too.
Comment 2 GouriKumari 2013-08-06 17:27:40 UTC
Retested. Now,  actual result of ns.Count is 1

Supplemental Info : http://screencast.com/t/GPMem6wkT

Test Env:

Xamarin Studio
Version 4.0.10 (build 7)
Installation UUID: fafd3486-1aec-4f9c-ab77-08bf4a000708
Runtime:
	Mono 3.2.2 ((no/4a17166)
	GTK 2.24.20
	GTK# (2.12.0.0)
	Package version: 302020000

Apple Developer Tools
Xcode 4.6.3 (2068)
Build 4H1503

Xamarin.iOS
Version: 6.4.1.14 (Trial Edition)
Hash: 1c428d5
Branch: 
Build date: 2013-06-08 05:38:40-0400