[Mono-bugs] [Bug 654482] New: Binding and using UIViewController OC library causes XmlSerializer constructor to fail

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Nov 17 17:57:41 EST 2010


https://bugzilla.novell.com/show_bug.cgi?id=654482

https://bugzilla.novell.com/show_bug.cgi?id=654482#c0


           Summary: Binding and using UIViewController OC library causes
                    XmlSerializer constructor to fail
    Classification: Mono
           Product: MonoTouch
           Version: unspecified
          Platform: Macintosh
        OS/Version: Mac OS X 10.6
            Status: NEW
          Severity: Critical
          Priority: P5 - None
         Component: Runtime
        AssignedTo: gnorton at novell.com
        ReportedBy: rcollins at boardbooks.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


Created an attachment (id=400944)
 --> (http://bugzilla.novell.com/attachment.cgi?id=400944)
Test Projects to demonstrate problem.

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US)
AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.44 Safari/534.7

It appears that the AOT is somehow processing my UIViewController Objective-C
class, imported into my MonoTouch project using the btouch tool. If, and only
if, I use my imported class, then the XmlSerializer constructor fails.
Presumably it is iterating through the classes which were identified as part of
a AOT compiler process, and does not like my bound class. As if you comment out
the lines where my bound class is created/used, the error goes away. See Steps
to Reproduce for details.

Reproducible: Always

Steps to Reproduce:
Target platform: iPad. My test projects (attached) to illustrate my problem
consist of the following:

1. An XCode/Objective-C iOS library project consisting of a TestViewController
class, declared as:

@interface TestViewController : UIViewController {}

with loadview and viewDidLoad implementations of:

- (void)loadView {
      UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 768,
1024)];
      view.backgroundColor = [UIColor blueColor];
      self.view = view;
      [view release]; }

- (void)viewDidLoad {
      [super viewDidLoad];
      UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(200, 188, 150,
21)];
      label.text = @"Objective-C View";
      [self.view addSubview:label];  }

TestViewController just creates and displays a blue UIView and displays the
text "Objective-C View".

2. A MonoTouch iPad Window-based project with the following:

a) A TestLib.cs file with the following contents:

using MonoTouch.Foundation; using MonoTouch.UIKit; using System;

namespace InteropTest {
            [BaseType (typeof (UIViewController))]
            interface TestViewController {}
}

This TestLib.cs file is not compiled by the project, but is fed into the btouch
tool, which produces a TestLib.dll as output, which is then added as a
reference to the project.

b) The output of the XCode project (libTestLib.a) is copied to the MonoTouch
project and is linked in with the following command in the MonoTouch project
options, iPhone Build, Extra Arguments:

-v -gcc_flags "-L${ProjectDir} -lTestLib -framework CoreGraphics -ObjC"

c) The contents of the main.cs file is as follows:

namespace InteropTest
{
    public class Application
    {
        static void Main (string[] args)
        {
            UIApplication.Main (args);
        }
    }

    public class MyTest
    {                       
       public int a { get; set; }
    }

    // The name AppDelegate is referenced in the MainWindow.xib file.
    public partial class AppDelegate : UIApplicationDelegate
    {
        // This method is invoked when the application has loaded its UI and
its ready to run
        public override bool FinishedLaunching (UIApplication app, NSDictionary
options)
        {                                   
              // Test 3: Comment out these 2 lines - XmlSerializer ctr should
now succeed.
              InteropTest.TestViewController controller = new
InteropTest.TestViewController();
              window.AddSubview (controller.View);

              // If you have defined a view, add it here:
              window.MakeKeyAndVisible ();

              // Test 2: Uncomment this line - exception thrown from this call.
              //System.Xml.Serialization.XmlSerializer xmlSerializer = new
System.Xml.Serialization.XmlSerializer (typeof(MyTest));


              return true;
         }
     }
}

3. The testing. Build the XCode project. Copy the libTestLib.a output into the
MonoTouch project folder, then build and run the MonoTouch project.

a) Test 1: You should see a blue screen with the "Objective-C View" text.
b) Test 2: Comment back in the line below the "Test 2: Uncomment this line"
comment. Build and run. You should get a crash on the line you commented back
in: NullReferenceException at
System.Xml.Serialization.XmlReflectionImporter.ImportIncludedTypes(System.Type
type, System.String defaultNamespace.
c) Test 3: Comment out the 2 lines of code immediately below the "Test 3:
Comment out these 2 lines" comment. Build and run. You should see the Main
application window (labelled Main Window) and critically, the line which
crashed in Test 2, should now succeed.

All we can determine is that the AOT compiler is somehow processing the
TestViewController class when it is used in the application. In this case it
crashing the XmlSerializer constructor.

Cheers.

Rohinton Collins
Diligent Boardbooks Member Services Ltd.


Actual Results:  
Test 2: You should get a crash on the line you commented back in:
NullReferenceException at
System.Xml.Serialization.XmlReflectionImporter.ImportIncludedTypes(System.Type
type, System.String defaultNamespace.

Expected Results:  
Should not crash.

I have reported this to the MonoTouch Forums and have emailed you directly at
monotouch at novell.com. This is a critical problem which is holding up the
integration of our project which is on an extremely tight schedule. Thanks!

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list