Hello,<div><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I started looking at it and there are two ways of approaching the problem that I found.<br></blockquote><div><br></div><div>Oops, good catch!</div><div><br></div><div>I got a fix very similar to yours, they now both use [New] and I removed the code that checked, as the underlying runtime should be catching that anyways;</div>
<div><br></div><div>Miguel </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
1) The easiest was the following:<br>
<br>
Add the following to foundation.cs for interface NSMutableDictionary specifying [New]<br>
<br>
        [Export (&quot;dictionaryWithObjects:forKeys:&quot;)]<br>
        [Static,New]<br>
        NSMutableDictionary FromObjectsAndKeys (NSObject [] objects, NSObject [] Keys);<br>
<br>
*** Note ***    If [New] is not specified it will not work correctly because it uses the base NSDictionary method and the Dictionary returned is not Mutable.<br>
<br>
Also commenting out the following code in NSMutableDictionary.cs<br>
<br>
        public static NSMutableDictionary FromObjectsAndKeys (NSObject [] objects, NSObject [] keys)<br>
        {<br>
            if (objects.Length != keys.Length)<br>
                throw new ArgumentException (&quot;objects and keys arrays have different sizes&quot;);<br>
            return FromObjectsAndKeys (objects, keys);<br>
        }<br>
<br>
2)  The second approach was keeping the ArgumentException check in NSMutableDictionary.cs and defining a new internal method in foundation.cs<br>
<br>
NSMutableDictionary.cs<br>
<br>
        public static NSMutableDictionary FromObjectsAndKeys (NSObject [] objects, NSObject [] keys)<br>
        {<br>
            if (objects.Length != keys.Length)<br>
                throw new ArgumentException (&quot;objects and keys arrays have different sizes&quot;);<br>
            return FromObjectsAndKeysInternal (objects, keys);<br>
        }<br>
<br>
foundation.cs<br>
<br>
        [Export (&quot;dictionaryWithObjects:forKeys:&quot;)]<br>
        [Static,Internal]<br>
        NSMutableDictionary FromObjectsAndKeysInternal (NSObject [] objects, NSObject [] Keys);<br>
<br>
<br>
I chose the second approach to keep the ArgumentException check in with the least amount of changes.<br>
<br>
Either one works.<br>
<br>
I have attached the diff if you choose the second one.<br>
<br>
Shouldn&#39;t NSDictionary include the same ArgumentException check as NSMutableDictionary if that is the way you decide?  Just for consistency if anything.<br>
<br>
Kenneth<div><div></div><div class="h5"><br>
<br>
<br>
<br>
On 11/16/10 12:47 AM, Miguel de Icaza wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I am working with a mutable dictionary with bindings to an ArrayController<br>
and am having problems creating a NSMutableDictionary using the<br>
FromObjectsAndKeys.<br>
</blockquote>
Are you running the latest version from GitHub?<br>
<br>
On Friday or so, Geoff fixed an important bug with arrays in the Monomac<br>
runtime.<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
It works for a NSDictionary but not when creating a NSMutableDictionary.<br>
<br>
The example code below shows what I am talking about.<br>
<br>
        var objects = new NSObject[3] {new NSString(&quot;AAAAA&quot;),<br>
                                                new NSString(&quot;BBBBB&quot;),<br>
                                                new NSString(&quot;CCCCCC&quot;)};<br>
<br>
        var keys = new NSObject[3] {new NSString(&quot;firstkey&quot;),<br>
                                                new NSString(&quot;secondkey&quot;),<br>
                                                new NSString(&quot;thirdkey&quot;)};<br>
                        <br>
        var dict2 = NSDictionary.FromObjectsAndKeys(objects,keys);<br>
                        <br>
        //var dict = NSMutableDictionary.FromObjectsAndKeys(objects, keys);<br>
        var dict = NSMutableDictionary.FromDictionary(dict2);<br>
                        <br>
        myContentArray.AddObject(dict);<br>
<br>
The implementation between NSDictionary.cs and NSMutableDictionary.cs are<br>
different for that method and not sure why.<br>
<br>
Any help would be appreciated<br>
<br>
Kenneth<br>
<br>
----------------------------------<br>
If you uncomment the //var dict =<br>
NSMutableDictionary.FromObjectsAndKeys(objects, keys); it gives the<br>
following error:<br>
<br>
Stacktrace:<br>
<br>
   at (wrapper managed-to-native)<br>
MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr_int<br>
(intptr,intptr,intptr,intptr,int)&lt;0x00004&gt;<br>
   at (wrapper managed-to-native)<br>
MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr_int<br>
(intptr,intptr,intptr,intptr,int)&lt;0x00004&gt;<br>
   at MonoMac.Foundation.NSMutableDictionary.FromObjectsAndKeys<br>
(MonoMac.Foundation.NSObject[],MonoMac.Foundation.NSObject[],int)&lt;0x00067&gt;<br>
   at MonoMac.Foundation.NSMutableDictionary.FromObjectsAndKeys<br>
(MonoMac.Foundation.NSObject[],MonoMac.Foundation.NSObject[])&lt;0x00028&gt;<br>
   at NSTableViewBinding.TestWindowController.AwakeFromNib ()&lt;0x001f8&gt;<br>
   at (wrapper native-to-managed) object.92f48794-05ff-4e21-bcf0-61c0dd4bf42b<br>
(MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector)&lt;0x000cc&gt;<br>
   at (wrapper managed-to-native)<br>
MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper (intptr,intptr)<br>
&lt;0x00004&gt;<br>
   at (wrapper managed-to-native)<br>
MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper (intptr,intptr)<br>
&lt;0x00004&gt;<br>
   at MonoMac.AppKit.NSWindowController.get_Window ()&lt;0x00079&gt;<br>
   at NSTableViewBinding.TestWindowController.get_Window ()&lt;0x00012&gt;<br>
   at NSTableViewBinding.AppDelegate.FinishedLaunching<br>
(MonoMac.Foundation.NSObject)&lt;0x00038&gt;<br>
   at (wrapper native-to-managed) object.00860f4e-27a8-4ca0-aa64-ae2828705416<br>
(MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.Foundation.NSObject)<br>
&lt;0x00118&gt;<br>
   at (wrapper managed-to-native)<br>
MonoMac.AppKit.NSApplication.NSApplicationMain (int,string[])&lt;0x00004&gt;<br>
   at (wrapper managed-to-native)<br>
MonoMac.AppKit.NSApplication.NSApplicationMain (int,string[])&lt;0x00004&gt;<br>
   at MonoMac.AppKit.NSApplication.Main (string[])&lt;0x00015&gt;<br>
   at NSTableViewBinding.MainClass.Main (string[])&lt;0x00015&gt;<br>
   at (wrapper runtime-invoke)&lt;Module&gt;.runtime_invoke_void_object<br>
(object,intptr,intptr,intptr)&lt;0x00043&gt;<br>
<br>
</blockquote>
<br>
<br>
</blockquote>
</div></div></blockquote></div><br></div>