<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Miguel<br>
    <br>
    Refreshed from master and verified that it works.<br>
    <br>
    Thanks<br>
    <br>
    Kenneth<br>
    <br>
    On 11/16/10 6:43 AM, Miguel de Icaza wrote:
    <blockquote
      cite="mid:AANLkTi=T1_29AxaXRfHUiqen8WwGEpjcogXF7Nr2GyYy@mail.gmail.com"
      type="cite">Hello,
      <div><br>
        <div class="gmail_quote">
          <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
            0.8ex; border-left: 1px solid rgb(204, 204, 204);
            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&nbsp;</div>
          <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
            0.8ex; border-left: 1px solid rgb(204, 204, 204);
            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>
            &nbsp; &nbsp; &nbsp; &nbsp;[Export ("dictionaryWithObjects:forKeys:")]<br>
            &nbsp; &nbsp; &nbsp; &nbsp;[Static,New]<br>
            &nbsp; &nbsp; &nbsp; &nbsp;NSMutableDictionary FromObjectsAndKeys (NSObject []
            objects, NSObject [] Keys);<br>
            <br>
            *** Note *** &nbsp; &nbsp;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>
            &nbsp; &nbsp; &nbsp; &nbsp;public static NSMutableDictionary FromObjectsAndKeys
            (NSObject [] objects, NSObject [] keys)<br>
            &nbsp; &nbsp; &nbsp; &nbsp;{<br>
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (objects.Length != keys.Length)<br>
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new ArgumentException ("objects and
            keys arrays have different sizes");<br>
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return FromObjectsAndKeys (objects, keys);<br>
            &nbsp; &nbsp; &nbsp; &nbsp;}<br>
            <br>
            2) &nbsp;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>
            &nbsp; &nbsp; &nbsp; &nbsp;public static NSMutableDictionary FromObjectsAndKeys
            (NSObject [] objects, NSObject [] keys)<br>
            &nbsp; &nbsp; &nbsp; &nbsp;{<br>
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (objects.Length != keys.Length)<br>
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new ArgumentException ("objects and
            keys arrays have different sizes");<br>
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return FromObjectsAndKeysInternal (objects,
            keys);<br>
            &nbsp; &nbsp; &nbsp; &nbsp;}<br>
            <br>
            foundation.cs<br>
            <br>
            &nbsp; &nbsp; &nbsp; &nbsp;[Export ("dictionaryWithObjects:forKeys:")]<br>
            &nbsp; &nbsp; &nbsp; &nbsp;[Static,Internal]<br>
            &nbsp; &nbsp; &nbsp; &nbsp;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't NSDictionary include the same ArgumentException
            check as NSMutableDictionary if that is the way you decide?
            &nbsp;Just for consistency if anything.<br>
            <br>
            Kenneth
            <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: 0pt 0pt
                  0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204);
                  padding-left: 1ex;">
                  Hello,<br>
                  <br>
                  <blockquote class="gmail_quote" style="margin: 0pt 0pt
                    0pt 0.8ex; border-left: 1px solid rgb(204, 204,
                    204); 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: 0pt 0pt
                    0pt 0.8ex; border-left: 1px solid rgb(204, 204,
                    204); 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>
                    &nbsp; &nbsp; &nbsp; &nbsp;var objects = new NSObject[3] {new
                    NSString("AAAAA"),<br>
                    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;new
                    NSString("BBBBB"),<br>
                    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;new
                    NSString("CCCCCC")};<br>
                    <br>
                    &nbsp; &nbsp; &nbsp; &nbsp;var keys = new NSObject[3] {new
                    NSString("firstkey"),<br>
                    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;new
                    NSString("secondkey"),<br>
                    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;new
                    NSString("thirdkey")};<br>
                    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>
                    &nbsp; &nbsp; &nbsp; &nbsp;var dict2 =
                    NSDictionary.FromObjectsAndKeys(objects,keys);<br>
                    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>
                    &nbsp; &nbsp; &nbsp; &nbsp;//var dict =
                    NSMutableDictionary.FromObjectsAndKeys(objects,
                    keys);<br>
                    &nbsp; &nbsp; &nbsp; &nbsp;var dict =
                    NSMutableDictionary.FromDictionary(dict2);<br>
                    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>
                    &nbsp; &nbsp; &nbsp; &nbsp;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>
                    &nbsp; 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>
                    &nbsp; 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>
                    &nbsp; at
                    MonoMac.Foundation.NSMutableDictionary.FromObjectsAndKeys<br>
(MonoMac.Foundation.NSObject[],MonoMac.Foundation.NSObject[],int)&lt;0x00067&gt;<br>
                    &nbsp; at
                    MonoMac.Foundation.NSMutableDictionary.FromObjectsAndKeys<br>
(MonoMac.Foundation.NSObject[],MonoMac.Foundation.NSObject[])&lt;0x00028&gt;<br>
                    &nbsp; at
                    NSTableViewBinding.TestWindowController.AwakeFromNib
                    ()&lt;0x001f8&gt;<br>
                    &nbsp; at (wrapper native-to-managed)
                    object.92f48794-05ff-4e21-bcf0-61c0dd4bf42b<br>
(MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector)&lt;0x000cc&gt;<br>
                    &nbsp; at (wrapper managed-to-native)<br>
                    MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper
                    (intptr,intptr)<br>
                    &lt;0x00004&gt;<br>
                    &nbsp; at (wrapper managed-to-native)<br>
                    MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper
                    (intptr,intptr)<br>
                    &lt;0x00004&gt;<br>
                    &nbsp; at MonoMac.AppKit.NSWindowController.get_Window
                    ()&lt;0x00079&gt;<br>
                    &nbsp; at
                    NSTableViewBinding.TestWindowController.get_Window
                    ()&lt;0x00012&gt;<br>
                    &nbsp; at
                    NSTableViewBinding.AppDelegate.FinishedLaunching<br>
                    (MonoMac.Foundation.NSObject)&lt;0x00038&gt;<br>
                    &nbsp; 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>
                    &nbsp; at (wrapper managed-to-native)<br>
                    MonoMac.AppKit.NSApplication.NSApplicationMain
                    (int,string[])&lt;0x00004&gt;<br>
                    &nbsp; at (wrapper managed-to-native)<br>
                    MonoMac.AppKit.NSApplication.NSApplicationMain
                    (int,string[])&lt;0x00004&gt;<br>
                    &nbsp; at MonoMac.AppKit.NSApplication.Main
                    (string[])&lt;0x00015&gt;<br>
                    &nbsp; at NSTableViewBinding.MainClass.Main
                    (string[])&lt;0x00015&gt;<br>
                    &nbsp; 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>
    </blockquote>
  </body>
</html>