Forum Xamarin.iOS

Binding Native NSUInteger[] Error

reknabreknab USMember ✭✭

When I use Objective Sharpie to generate bindings, the following method:

- (int)printPDFAtPath:(NSString *)pdfPath pages:(NSUInteger [])indexes length:(NSUInteger)length copy:(int)nCopy;

gets bound as

int PrintPDFAtPath(string pdfPath, nuint[] indexes, nuint length, int nCopy);

The resulting generated code then contains the following code:

var nsa_indexes = NSArray.FromNSObjects (indexes);

which fails due to the fact that nuints are not NSObjects

Error CS1502: The best overloaded method match for `Foundation.NSArray.FromNSObjects(params Foundation.NSObject[])' has some invalid arguments (CS1502)
Error CS1503: Argument `#1' cannot convert `System.nuint[]' expression to type `Foundation.NSObject[]' (CS1503)

Is there a recommended approach to dealing with conversions like this?



  • istallaistalla USMember

    Hi Robert,

    How did you resolved this issue, i am running through the same issue. Could you able to help?

  • dusanbukovackidusanbukovacki Member ✭✭

    Please, tell us ?! Thanks.

  • dusanbukovackidusanbukovacki Member ✭✭

    RekNab, did you solved the problem ?

  • reknabreknab USMember ✭✭

    Unfortunately, I never found a resolution to this issue. We ended up using a different SDK and that worked around the problem.

  • dusanbukovackidusanbukovacki Member ✭✭
    edited April 2018

    Can you tell me please wich SDK did you used ? Thanks a lot.

  • reknabreknab USMember ✭✭

    Yes -- we used the Brother Enhanced SDK available here:

    Instead of using printPDFAtPath from the Touch SDK, we used PrintPDFFilePathURL from the Enhanced SDK. You'll still need to remove the generated code from the generated bindings for the printPDFAtPath method as the will not compile.

  • dusanbukovackidusanbukovacki Member ✭✭
    edited April 2018

    Ok, thank you a lot. I will try with that SDK then. I had same problem to compile binding project but i have changed nuint[] to NSObject[] and then passed, but at the end of coding i got -48 error status code wich is ERROR_INVALID_PARAMETER and then i figure out that maybe that is problem, because it need uint instead NSObject, but who knows :-(

    And when you open in XCode native demo brother app, there is NSUInteger type...

    I think that i don't have another option to move on than to listen you. Btw, i am using the latest brother SDK and obviously there is a bug or i am doing something wrong.

  • dusanbukovackidusanbukovacki Member ✭✭
    edited April 2018

    And could you please just tell me how to download that SDK, because i am from Europe and cannot create account to download that SDK, there is only for USA users.

  • reknabreknab USMember ✭✭

    Unfortunately, that is the only way I know how to get the SDK. You may need to contact Brother directly outside of the US. It's worth noting that the Enhanced SDK is intended for the PJ,RJ, and TD Brother models. If you're not using one of those printers, it may not do you any good.

  • dusanbukovackidusanbukovacki Member ✭✭

    Damn, i am using QL-820NWB. Dunno, then i am in a really problem.

  • reknabreknab USMember ✭✭

    One option -- instead of using printPDFAtPath, I tried converting the PDF to a bitmap and then printed using the graphics methods. It worked, but we had other issues with that driver on a PJ printer, which is why we ultimately moved to the Enhanced SDK

    CGPDFDocument pdfDoc = CGPDFDocument.FromFile(localFile);
    if (pdfDoc != null)
      for (int i = 0; i < pdfDoc.Pages; i++)
        await UserNotification.SetWaitCursorMessageAsync(string.Format("Printing page {0} of {1}...", (i + 1), pdfDoc.Pages));
        Log.Info(string.Format("Printing page {0} of {1}..", i, pdfDoc.Pages));
        CGPDFPage page = pdfDoc.GetPage(i + 1);
        var pageImage = ConvertPdfPage(page);
        if (pageImage != null)
          var result = printer.PrintImage(pageImage.CGImage, 1);
          if (result != 0)
                // ERROR
                var err = string.Format("Print Error: {0}", result);
                throw new PrinterException(err);
    private UIImage ConvertPdfPage(CGPDFPage page)
        // increase image size for improved quality
        float RESIZE_FACTOR = 4.0f;
        CGRect pageRect = page.GetBoxRect(CGPDFBox.Media);
        UIGraphics.BeginImageContext(new CGSize(pageRect.Size.Width * RESIZE_FACTOR, pageRect.Size.Height * RESIZE_FACTOR));
        using (CGContext context = UIGraphics.GetCurrentContext())
            context.SetFillColor(1.0f, 1.0f, 1.0f, 1.0f);
            context.TranslateCTM(0.0f, pageRect.Size.Height * RESIZE_FACTOR);
            context.ScaleCTM(RESIZE_FACTOR, RESIZE_FACTOR * -1);
            CGAffineTransform transform = page.GetDrawingTransform(CGPDFBox.Media, pageRect, 0, true);
            UIImage img = UIGraphics.GetImageFromCurrentImageContext();
            return img;

    Hope this helps.

  • dusanbukovackidusanbukovacki Member ✭✭
    edited April 2018

    Hm, i don't think that will help me, sadly :-( I am using
    ----> bpsdki316(latest SDK) and trying to print PDF file, it is different SDK with yours. And also i am using
    Brother QL-820NWB, and yes, that this is the latest release of SDK. In ApiDefinition.cs my problem is here i guess

    // -(int)printPDFAtPath:(NSString *)pdfPath pages:(NSUInteger *)indexes length:(NSUInteger)length copy:(int)nCopy;
    int PrintPDFAtPath(string pdfPath, NSObject[] indexes, uint length, int nCopy);
    NSObject i changed manually to pass build but then i got this one in code: (that is currently in code now)

    -----> var printing = iOSprinter.PrintPDFAtPath(pdfFileIOS, indexes, 0, 1);

    and there i have got -'48' status error code wich is Invalid parameter :-( Everything else is good, StartCommunication got 'True' value, IsPrinterReady got 'True', also get printer information from the local network, everything works, until PrintPDFAtPath.
    But also i have suspicion as you did in the beginner of binding with:
    -----> int PrintPDFAtPath (string pdfPath, nuint[] indexes, nuint length, int nCopy);
    and could not solve this error: Argument 1: cannot convert from 'System.nuint[]' to 'Foundation.NSObject' !!!!!

    So, if you or anyone has the some advice, opinion or something, please hit me there. But 'THANKS' anyway for your time really.

  • dusanbukovackidusanbukovacki Member ✭✭
    edited April 2018

    I have used your code, and i solve error but now i have got new one ERROR_WRONG_LABEL_. Well, now it could be that maybe my Brother Printer QL-820NWB cannot print Image or this code is not good:
    iOSprintInfo.StrPaperName = "A7";

    Well, i comment your code and uncoment mine and now is the same problem with the label and from PrintPDFAtPath when i commented code for paperName and setPrintInfo, so possible i did not declarate paper in code very well for QL Series. But, in the bpsdki316 i cannot see label code for QL Series, damn. :-(

  • dusanbukovackidusanbukovacki Member ✭✭
    edited April 2018

    Hello m8, i have successfully print pdf file with my SDK and PrintPDFAtPath method, finnaly :-)
    The problem is in setting PaperName for right series and to change parameter on NSObject[], but thank you a lot. :-)
    So, i guess that you also can use that latest Brother SDK, you don't have to use Brother Enhanced SDK.
    But anyway, Thanks once time. If you need any help, just hit me :P

  • AnandVKAnandVK USMember ✭✭

    @reknab said:
    Yes -- we used the Brother Enhanced SDK available here:

    Instead of using printPDFAtPath from the Touch SDK, we used PrintPDFFilePathURL from the Enhanced SDK. You'll still need to remove the generated code from the generated bindings for the printPDFAtPath method as the will not compile.

    @reknab The URL"" mentioned in not working.

Sign In or Register to comment.