Bug 1538 - iOS5 UIDocument.Save() binding problem
Summary: iOS5 UIDocument.Save() binding problem
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 5.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2011-10-17 17:00 UTC by Craig Dunn
Modified: 2011-10-18 13:24 UTC (History)
2 users (show)

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

Sample that can trigger bug (8.35 KB, application/zip)
2011-10-17 17:00 UTC, Craig Dunn

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:

Description Craig Dunn 2011-10-17 17:00:27 UTC
Created attachment 711 [details]
Sample that can trigger bug

the attached project contains a MonkeyDocument : UIDocument
i'm trying to follow the 'subclassing notes' in the apple docs[1] ~ in the simulator i can fake-write (ie.manually) the document and open it successfully, but *saving* always results in an NSObjectWrapped problem. 
  at MonoTouch.ObjCRuntime.Runtime.GetNSObject (intptr) <0x00083>
  at MonoTouch.ObjCRuntime.Runtime.GetNSObjectWrapped (intptr) <0x0001b>
  at (wrapper native-to-managed) MonoTouch.ObjCRuntime.Runtime.GetNSObjectWrapped (intptr) <0xffffffff>
  at MonoTouch.UIKit.UIDocument.Save (MonoTouch.Foundation.NSUrl,MonoTouch.UIKit.UIDocumentSaveOperation,MonoTouch.UIKit.UIOperationHandler) <0x00107>

The code that causes the error is in the attachment MonkeyDocument.cs and MonkeyDocViewController.cs

EMAIL FROM MDI (for reference):
This seems to be a bug in our binding.

There are a couple of problems, I mapped the:

NSError **result 

In a few places as "out NSError foo", and this seems to be causing some problems.    The first problem is that we should probably have made this a "ref NSError foo" and not an out.   The second problem seems to be that the monotouch_trampoline does not know how to cope with the refs or outs for NSErrors, although I thought we had support for this.

Replacing the API with IntPtr ptrToNSError makes the code not crash once, but then further invocations to Save fail (perhaps this is expected).

[1] https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIDocument_Class/UIDocument/UIDocument.html%23//apple_ref/c/tdef/UIDocumentSaveOperation
Comment 1 Miguel de Icaza [MSFT] 2011-10-18 13:24:02 UTC
This problem is fixed, the MonoTouch code did not cope with ref/out parameters that were set to null.

The sample contains one problem: creating instances of NSError without an ErrorDomain creates half-baked NSError objects.   I have added some error reporting to avoid this practice.

in this case, if you do not want to return an error, you should just assign null to the error return, do not use new NSError () alone