Hello Jon,

I had a similar problem with a different method (ReadFromUrl) where Cocoa was supplying NULL for the outError parameter in some cases, and it's not possible to convert null to an "out NSError" parameter in C#.

In the end I just didn't use the method from MonoMac and defined my own like this:

[Export("readFromURL:ofType:error:")]
private bool ReadFromUrl2(NSUrl absoluteUrl, string typeName, IntPtr pOutError)
{
    // Set this to an NSError object if an error occurs
    NSError nsError;

    // ...

    // Write the error to the out parameter
    if (pOutError != IntPtr.Zero)
    {
        if (nsError == null)
        {
            Marshal.WriteIntPtr(pOutError, IntPtr.Zero);
        }
        else
        {
            Marshal.WriteIntPtr(pOutError, nsError.Handle);
        }
    }
}


Maybe not the best way of solving it, but it worked for me!

Dan

On 25/04/2012 05:03, Jon Lipsky wrote:
Hi All,

I'm running into a strange problem that I though perhaps someone else might have run into and might have a solution for.

If I were writing a document based application in Objective-C and wanted to the user to be able to cancel the opening of a document, I could do something like this (which I can confirm works fine):

- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
    // Loading code here...

*outError = [NSErrorerrorWithDomain:NSCocoaErrorDomain code:NSUserCancelledError userInfo:nil];
returnNO;
}

The (what seems to me) obvious thing to do in MonoMac would be to implement this:

public override bool ReadFromData (NSData data, string typeName, out NSError outError)
{
// Loading code here...

outError = NSError.FromDomain(NSError.CocoaErrorDomain,1376);
return false;
}


However, when I do so, my app crashes with the following stack trace:


#0  0x9287dfd5 in __wait4 ()
#1  0x93be04ec in waitpid$UNIX2003 ()
#2 0x0009fe9b in mono_handle_native_sigsegv (signal=11, ctx=0xbfffea5c) at mini-exceptions.c:2192 #3 0x00004f6e in mono_sigsegv_signal_handler (_dummy=10, info=0xbfffea1c, context=0xbfffea5c) at mini.c:5917
#4 <signal handler called>
#5  0x9249cd44 in objc_msgSend ()
#6 0x991622cc in -[NSDocumentController(NSInternal) _fixedFailureReasonFromError:] () #7 0x9916b5f4 in -[NSDocumentController _willPresentOpeningError:forURL:] () #8 0x9916b197 in -[NSDocumentController _openDocumentsWithContentsOfURLs:presentErrors:completionHandler:] ()
#9  0x9915f749 in -[NSDocumentController openDocument:] ()
(Rest of stack trace omitted)

Has anyone else run into this problem, and if so were you able to find a solution/workaround?

Thanks,
Jon...


_______________________________________________
Mono-osx mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/mono-osx

_______________________________________________
Mono-osx mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/mono-osx

Reply via email to