Bug 7933 - Setting the KeyValue on NSObjects throws an error
Summary: Setting the KeyValue on NSObjects throws an error
Status: RESOLVED INVALID
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 6.1.x
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-10-23 01:06 UTC by James Clancey
Modified: 2012-10-24 02:26 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
TestCase (4.43 KB, application/zip)
2012-10-23 01:06 UTC, James Clancey
Details


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 INVALID

Description James Clancey 2012-10-23 01:06:04 UTC
Created attachment 2776 [details]
TestCase

If you try setting the NSDictionary KeyValue setting on an NSObject it blows up with the following error 


Unhandled Exception:
0   KeyValueBug                         0x0008ed2e mono_handle_exception_internal_first_pass + 2190
1   KeyValueBug                         0x00090772 mono_handle_exception_internal + 1602
2   KeyValueBug                         0x000912bf mono_handle_exception + 47
3   KeyValueBug                         0x000d4232 mono_x86_throw_exception + 306
4   ???                                 0x0b496f8f 0x0 + 189362063
5   CoreFoundation                      0x013c8318 __handleUncaughtException + 728
6   libobjc.A.dylib                     0x0401b0b9 _ZL15_objc_terminatev + 86
7   libc++abi.dylib                     0x0435ca65 _ZL19safe_handler_callerPFvvE + 13
8   libc++abi.dylib                     0x0435cacd __cxa_bad_typeid + 0
9   libc++abi.dylib                     0x0435dbc2 _ZL23__gxx_exception_cleanup19_Unwind_Reason_CodeP17_Unwind_Exception + 0
10  libobjc.A.dylib                     0x0401af89 _ZL26_objc_exception_destructorPv + 0
11  CoreFoundation                      0x013c7fb1 -[NSException raise] + 17
12  Foundation                          0x01a06711 -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
13  Foundation                          0x01987ec8 _NSSetUsingKeyValueSetter + 140
14  Foundation                          0x019879b7 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
15  UIKit                               0x02772573 -[UIView(CALayerDelegate) setValue:forKey:] + 168
16  Foundation                          0x019d7d06 -[NSObject(NSKeyValueCoding) setValuesForKeysWithDictionary:] + 259
at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging.void_objc_msgSend_IntPtr (intptr,intptr,intptr) <IL 0x0000b, 0x00074>
at MonoTouch.Foundation.NSObject.SetValuesForKeysWithDictionary (MonoTouch.Foundation.NSDictionary) [0x0001c] in /Developer/MonoTouch/Source/monotouch/src/Foundation/NSObject.g.cs:393
at KeyValueBug.MyViewController.ViewDidLoad () [0x0002a] in /Users/Clancey/Projects/KeyValueBug/KeyValueBug/AppDelegate.cs:45
at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) <IL 0x00047, 0x00128>
21  KeyValueBug                         0x0000a732 mono_jit_runtime_invoke + 722
22  KeyValueBug                         0x0016c1ce mono_runtime_invoke + 126
23  KeyValueBug                         0x0020eb88 monotouch_trampoline + 3688
24  UIKit                               0x02803817 -[UIViewController loadViewIfRequired] + 536
25  UIKit                               0x02803882 -[UIViewController view] + 33
26  UIKit                               0x02752a25 -[UIWindow addRootViewControllerViewIfPossible] + 66
27  UIKit                               0x02752dbf -[UIWindow _setHidden:forced:] + 368
28  UIKit                               0x02752f55 -[UIWindow _orderFrontWithoutMakingKey] + 49
29  UIKit                               0x0275bf67 -[UIWindow makeKeyAndVisible] + 65
at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging.void_objc_msgSend (intptr,intptr) <IL 0x0000a, 0x00064>
at MonoTouch.UIKit.UIWindow.MakeKeyAndVisible () [0x00010] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIWindow.g.cs:124
at KeyValueBug.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication,MonoTouch.Foundation.NSDictionary) [0x00025] in /Users/Clancey/Projects/KeyValueBug/KeyValueBug/AppDelegate.cs:31
at (wrapper runtime-invoke) <Module>.runtime_invoke_bool__this___object_object (object,intptr,intptr,intptr) <IL 0x00059, 0x00185>
34  KeyValueBug                         0x0000a732 mono_jit_runtime_invoke + 722
35  KeyValueBug                         0x0016c1ce mono_runtime_invoke + 126
36  KeyValueBug                         0x0020eb88 monotouch_trampoline + 3688
37  UIKit                               0x0271f7b7 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 266
38  UIKit                               0x0271fda7 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1248
39  UIKit                               0x02720fab -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 805
40  UIKit                               0x02732315 -[UIApplication handleEvent:withNewEvent:] + 1022
41  UIKit                               0x0273324b -[UIApplication sendEvent:] + 85
42  UIKit                               0x02724cf8 _UIApplicationHandleEvent + 9874
43  GraphicsServices                    0x04d0ddf9 _PurpleEventCallback + 339
44  GraphicsServices                    0x04d0dad0 PurpleEventCallback + 46
45  CoreFoundation                      0x012b4bf5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
46  CoreFoundation                      0x012b4962 __CFRunLoopDoSource1 + 146
47  CoreFoundation                      0x012e5bb6 __CFRunLoopRun + 2118
48  CoreFoundation                      0x012e4f44 CFRunLoopRunSpecific + 276
49  CoreFoundation                      0x012e4e1b CFRunLoopRunInMode + 123
50  UIKit                               0x027207da -[UIApplication _run] + 774
51  UIKit                               0x0272265c UIApplicationMain + 1211
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x00056, 0x001f5>
at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
at KeyValueBug.Application.Main (string[]) [0x00000] in /Users/Clancey/Projects/KeyValueBug/KeyValueBug/Main.cs:17
at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00049, 0x0012e>
56  KeyValueBug                         0x0000a732 mono_jit_runtime_invoke + 722
57  KeyValueBug                         0x0016c1ce mono_runtime_invoke + 126
58  KeyValueBug                         0x00170354 mono_runtime_exec_main + 420
59  KeyValueBug                         0x00175745 mono_runtime_run_main + 725
60  KeyValueBug                         0x00067985 mono_jit_exec + 149
61  KeyValueBug                         0x00203e92 main + 1986
62  KeyValueBug                         0x00003735 start + 53

[ERROR] FATAL UNHANDLED EXCEPTION: MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSUnknownKeyException Reason: [<UIButton 0xb374130> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key styleId.
  at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend_IntPtr (intptr,intptr,intptr)
  at MonoTouch.Foundation.NSObject.SetValuesForKeysWithDictionary (MonoTouch.Foundation.NSDictionary keyedValues) [0x0001c] in /Developer/MonoTouch/Source/monotouch/src/Foundation/NSObject.g.cs:393 
  at KeyValueBug.MyViewController.ViewDidLoad () [0x0002a] in /Users/Clancey/Projects/KeyValueBug/KeyValueBug/AppDelegate.cs:45 
  at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend (intptr,intptr)
  at MonoTouch.UIKit.UIWindow.MakeKeyAndVisible () [0x00010] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIWindow.g.cs:124 
  at KeyValueBug.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x00025] in /Users/Clancey/Projects/KeyValueBug/KeyValueBug/AppDelegate.cs:31 
  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38 
  at KeyValueBug.Application.Main (System.String[] args) [0x00000] in /Users/Clancey/Projects/KeyValueBug/KeyValueBug/Main.cs:17 

Application Terminated with error: The simulated application quit.




related to https://bugzilla.xamarin.com/show_bug.cgi?id=7932
Comment 1 Sebastien Pouliot 2012-10-23 08:41:11 UTC
> If you try setting the NSDictionary KeyValue setting on an NSObject it blows up
> with the following error 

No, the issue is not settings key/values into an NSDictionary. e.g.

    var d1 = NSDictionary.FromObjectAndKey(new NSString("button1"),new NSString("styleId"));

^ that works.

You get the (Objective-C) exception when you do:

    button1.SetValuesForKeysWithDictionary(d1);

The message (from the ObjC exception) makes this looks like the key is unknown to an UIButton. IOW it looks legit, what are you trying to do ? is there a sample you're basing yourself on ?
Comment 2 James Clancey 2012-10-24 02:26:03 UTC
You are right this is an invalid bug.