Bug 13993 - error BI0000: Unexpected error - Please file a bug report at http://bugzilla.xamarin.com
Summary: error BI0000: Unexpected error - Please file a bug report at http://bugzilla....
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools ()
Version: 6.9.5.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-08-15 01:36 UTC by Claudiu T
Modified: 2013-08-28 09:42 UTC (History)
2 users (show)

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

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 Claudiu T 2013-08-15 01:36:57 UTC
Project "/Users/claudiu/Projects/BrotherTouchPrinterBinding/BrotherTouchPrinterBinding/BrotherTouchPrinterBinding.csproj" (Build target(s)):
	Target PrepareForBuild:
		Configuration: Debug Platform: AnyCPU
	Target GenerateSatelliteAssemblies:
	No input files were specified for target GenerateSatelliteAssemblies, skipping.
	Target GenerateBindings:
		Tool /Developer/MonoTouch/usr/bin/btouch execution started with arguments: /unsafe /d:DEBUG ApiDefinition.cs /s:StructsAndEnums.cs /tmpdir:obj/Debug/ios/ /sourceonly:obj/Debug/ios//sources.list 
: error BI0000: Unexpected error - Please file a bug report at http://bugzilla.xamarin.com
		System.IndexOutOfRangeException: Array index is out of range.
		  at Generator.Generate (System.Type type) [0x00000] in <filename unknown>:0 
		  at Generator.Go () [0x00000] in <filename unknown>:0 
		  at BindingTouch.Main2 (System.String[] args) [0x00000] in <filename unknown>:0 
		  at BindingTouch.Main (System.String[] args) [0x00000] in <filename unknown>:0 
	Task "BTouch" execution -- FAILED
	Done building target "GenerateBindings" in project "/Users/claudiu/Projects/BrotherTouchPrinterBinding/BrotherTouchPrinterBinding/BrotherTouchPrinterBinding.csproj".-- FAILED
Done building project "/Users/claudiu/Projects/BrotherTouchPrinterBinding/BrotherTouchPrinterBinding/BrotherTouchPrinterBinding.csproj".-- FAILED


/Users/claudiu/Projects/BrotherTouchPrinterBinding/BrotherTouchPrinterBinding/BrotherTouchPrinterBinding.csproj (Build) ->
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Xamarin.ObjcBinding.CSharp.targets (GenerateBindings target) ->

	: error BI0000: Unexpected error - Please file a bug report at http://bugzilla.xamarin.com

	 0 Warning(s)
	 1 Error(s)

Time Elapsed 00:00:00.8032490

---------------------- Done ----------------------

Build: 1 error, 0 warnings
Comment 1 Sebastien Pouliot 2013-08-15 08:04:49 UTC
There's likely a binding mistake that trigger the bug. Can you attach your binding source files ? (you can mark them private) so we can reproduce the issue and ensure we report a more useful error ? Thanks
Comment 2 Claudiu T 2013-08-15 08:13:09 UTC
Bonjour Sebastien,

Thank you for the quick reply. I actually find the error myself early this morning, but I just didn't have time to update this bug. All is good now, so should I just change the status to Resolved | Invalid?

Comment 3 Sebastien Pouliot 2013-08-15 08:22:31 UTC
I'd prefer if you could give us the older code to reproduce the issue as the bug, as far as I'm concerned, it that the tool gives an inadequate error that is not helpful. 

IOW that should be fixed so other people won't run into the same issue (or at least gets something useful if they do).
Comment 4 Claudiu T 2013-08-15 08:38:39 UTC
Oui bien sûr Sebastien... Below is the content of the ApiDefinition.cs file that caused the btouch tool error.

using System;
using System.Drawing;
using MonoTouch.CoreGraphics;
using MonoTouch.ObjCRuntime;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace BRPTouch {
	[BaseType (typeof (NSObject), Name = "BRPtouchNetworkInfo")]
	public partial interface BrotherPrintTouchNetworkInfo {

		[Export ("strIPAddress", ArgumentSemantic.Copy)]
		string IPAddress { get; set; }

		[Export ("strLocation", ArgumentSemantic.Copy)]
		string Location { get; set; }

		[Export ("strModelName", ArgumentSemantic.Copy)]
		string ModelName { get; set; }

		[Export ("strSerialNumber", ArgumentSemantic.Copy)]
		string SerialNumber { get; set; }

		[Export ("strNodeName", ArgumentSemantic.Copy)]
		string NodeName { get; set; }

		[Export ("strMACAddress", ArgumentSemantic.Copy)]
		string MACAddress { get; set; }

	[BaseType (typeof (NSObject), Name = "BRPtouchNetwork",
       Delegates = new string[] {"WeakDelegate"},
		Events = new Type [] { typeof (BrotherPrintTouchNetworkDelegate), typeof(NSNetServiceBrowserDelegate) })]
	public partial interface BrotherPrinterTouchNetwork {

		[Export ("startSearch:")]
		int StartSearch (int nTimeout);

		[Export ("getPrinterNetInfo:")] 
		NSObject [] GetPrinterNetInfo ();

		[Export ("initWithPrinterName:")]
		void InitWithPrinterName (string strPrinterName);

		[Export ("setPrinterName:")]
		bool SetPrinterName (string strPrinterName);

		[Wrap ("WeakDelegate")][NullAllowed]
		BrotherPrintTouchNetworkDelegate Delegate { get; set; }

		NSObject WeakDelegate { get; set; }

	[BaseType (typeof (NSObject), Name = "BRPtouchNetworkDelegate")]
	public partial interface BrotherPrintTouchNetworkDelegate {

		[Export ("didFinishedSearch:")]
		void DidFinishedSearch (NSObject sender);
	[BaseType (typeof (NSObject), Name = "BRPtouchPrintInfo" )]
	public partial interface BrotherPrintTouchPrintInfo {

		[Export ("strPaperName", ArgumentSemantic.Retain)]
		string PaperName { get; set; }

		[Export ("ulOption")]
		uint Option { get; set; }

		[Export ("nPrintMode")]
		int PrintMode { get; set; }

		[Export ("nDensity")]
		int Density { get; set; }

		[Export ("nOrientation")]
		int Orientation { get; set; }

		[Export ("nHalftone")]
		int Halftone { get; set; }

		[Export ("nHorizontalAlign")]
		int HorizontalAlign { get; set; }

		[Export ("nVerticalAlign")]
		int VerticalAlign { get; set; }

		[Export ("nPaperAlign")]
		int PaperAlign { get; set; }

		[Export ("nExtFlag")]
		int ExtFlag { get; set; }

		[Export ("nAutoCutFlag")]
		int AutoCutFlag { get; set; }

		[Export ("nAutoCutCopies")]
		int AutoCutCopies { get; set; }

	[BaseType (typeof (NSObject), Name = "BRPtouchPrinterData")]
	public partial interface BrotherPrintTouchPrinterData {

		[Export ("getPrinterList:")]
		NSObject [] GetPrinterList ();

	[BaseType (typeof (NSObject), Name = "BRPtouchPrinter")]
	public partial interface BrotherPrintTouchPrinter {

		[Export ("setIPAddress:")]
		void SetIPAddress (string ipAddress);

		[Export ("sendFile::")]
		int SendFile (string strFile, int nTimeout);

		[Export ("sendData::")]
		int SendData (NSData dataData, int nTimeout);

		[Export ("sendFileEx:timeout:")]
		int SendFileEx (string strFile, int nTimeout);

		[Export ("sendDataEx:timeout:")]
		int SendDataEx (NSData dataData, int nTimeout);

		[Export ("initWithPrinterName:")]
		IntPtr Constructor (string strPrinterName);

		[Export ("setPrinterName:")]
		bool SetPrinterName (string strPrinterName);

		[Export ("isPrinterReady:")]
		bool IsPrinterReady ();

		[Export ("getPTStatus:")]
		int GetPtStatus (PTSTATUS status);

		[Export ("printImage:copy:timeout:")]
		int PrintImage (CGImage imageRef, int nCopy, int nTimeout);

		[Export ("setPrintInfo:")]
		int SetPrintInfo (BrotherPrintTouchPrintInfo printInfo);

		[Export ("setCustomPaperFile:")]
		bool SetCustomPaperFile (string strFilePath);

		[Export ("setEncryptKey:keyEx:")]
		bool SetEncryptKey (string strKey, string strKeyEx);

		[Export ("startPrint:")]
		int StartPrint ();

		[Export ("endPrint:")]
		void EndPrint ();
Comment 5 Sebastien Pouliot 2013-08-15 16:35:19 UTC
I could not reproduce your error. OTOH I had to make my own PTSTATUS definition, so it's possible it could be related to this. Could you share your StructsAndEnums.cs file ?

Also can you give me the exact version you're using ?

The easiest way to get exact version information is to use the "Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" button and copy/paste the version informations (you can use the "Copy Information" button).
Comment 6 Claudiu T 2013-08-15 22:33:04 UTC
I'll start with the version info:

=== Xamarin Studio ===

Version 4.0.12 (build 3)
Installation UUID: 8833c95e-1379-4019-adb9-323beacdb5ca
	Mono 3.2.0 ((no/7c7fcc7)
	GTK 2.24.20
	GTK# (
	Package version: 302000000

=== Apple Developer Tools ===

Xcode 4.6.3 (2068)
Build 4H1503

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 5a0fe54
Build date: 2013-30-07 08:24:03-0400

=== Xamarin.Mac ===

Xamarin.Mac: Not Installed

=== Xamarin.Android ===

Version: 4.8.1 (Starter Edition)
Android SDK: /Users/claudiu/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0   (API level 14)
		4.0.3 (API level 15)
Java SDK: /usr
java version "1.6.0_51"
Java(TM) SE Runtime Environment (build 1.6.0_51-b11-457-11M4509)
Java HotSpot(TM) 64-Bit Server VM (build 20.51-b01-457, mixed mode)

=== Build Information ===

Release ID: 400120003
Git revision: 593d7acb1cb78ceeeb482d5133cf1fe514467e39
Build date: 2013-08-07 20:30:53+0000
Xamarin addins: 25a0858b281923e666b09259ad4746b774e0a873

=== Operating System ===

Mac OS X 10.8.4
Darwin Claudius-MacBook-Pro.local 12.4.0 Darwin Kernel Version 12.4.0
    Wed May  1 17:57:12 PDT 2013
    root:xnu-2050.24.15~1/RELEASE_X86_64 x86_64

Next, the build error. I'm able to reproduce the error, which I found is related to the BaseType attribute for the BrotherPrinterTouchNetwork interface. If the Events and Delegates arguments are not having the same length, the error occurs:

[BaseType (typeof (NSObject), Name = "BRPtouchNetwork",
       Delegates = new string[] {"WeakDelegate"},
		Events = new Type [] { typeof (BrotherPrintTouchNetworkDelegate), typeof(NSNetServiceBrowserDelegate) })]
	public partial interface BrotherPrinterTouchNetwork {

I've removed the extra typeof(NSNetServiceBrowserDelegate) and everything built successfully. This was something I overlooked last night when I first did write the code, but noticed it later on.

I honestly don't think this is related to the PTSTATUS definition. Anyways, I'm including below the content of my StructsAndEnum.cs file:

public struct PTSTATUS {
		public byte	byHead;						
		public byte	bySize;						
		public byte	byBrotherCode;				
		public byte	bySeriesCode;				
		public byte	byModelCode;				
		public byte	byNationCode;				
		public byte	byFiller;					
		public byte	byFiller2;					
		public byte	byErrorInf;					
		public byte	byErrorInf2;				
		public byte	byMediaWidth;				
		public byte	byMediaType;				
		public byte	byColorNum;					
		public byte	byFont;						
		public byte	byJapanesFont;				
		public byte	byMode;						
		public byte	byDensity;					
		public byte	byMediaLength;				
		public byte	byStatusType;				
		public byte	byPhaseType;				
		public byte	byPhaseNoHi;				
		public byte	byPhaseNoLow;				
		public byte	byNoticeNo;					
		public byte	byExtByteNum;				
		public byte[] byHardWareSetting;		

	public enum Flags {
		FLAG_M_AUTOCUT = 0x40,
		FLAG_M_MIRROR = 0x80

	// Return value
	public enum ReturnValue {
		RET_FALSE = 0,
		RET_TRUE = 1

	public enum Flags2
		FLAG_K_DRAFT 	= 0x01, 
		FLAG_K_HALFCUT  = 0x04,
		FLAG_K_NOCHAIN  = 0x08,
		FLAG_K_SPTAPE   = 0x10,
		FLAG_K_HGPRINT  = 0x40,
		FLAG_K_COPY 	= 0x80

	public enum Flags3 {
		FLAG_PI_KIND    = 0x02,
	 	FLAG_PI_WIDTH   = 0x04,
		FLAG_PI_LENGTH  = 0x08,

	public enum TimeoutError {
		ERROR_TIMEOUT		= -3,		

	public enum Option {
		OPTION_AUTOCUT		= 0x00000001,
		OPTION_CUTATEND		= 0x00000002

	public enum PrintMode {
		PRINT_FIT			= 0x01

	public enum Orientation {
		ORI_LANDSCAPE		= 0x00,
	 	ORI_PORTRATE		= 0x01

	public enum Halftone {
		HALFTONE_BINARY    = 0x00,
	 	HALFTONE_DITHER    = 0x01,

	public enum HorizontalAlign {
		ALIGN_LEFT			= 0x00,
		ALIGN_CENTER		= 0x01,
		ALIGN_RIGHT			= 0x02

	public enum VerticalAlign {
		ALIGN_TOP			= 0x00,
		ALIGN_MIDDLE		= 0x01,
		ALIGN_BOTTOM		= 0x02

	public enum PaperAlign {

	public enum ReturnError {
		RET_ERR_OPTION			= -2,

	public enum PJ673Options {
		EXT_PJ673_ENCRYPT		= 0x01,
		EXT_PJ673_CARBON		= 0x02,
		EXT_PJ673_DASHPRINT		= 0x04,
		EXT_PJ673_NFD			= 0x08,
		EXT_PJ673_EOP			= 0x10,
		EXT_PJ673_EPR			= 0x20

	public struct PTDHEADER
		public long		dwMark;					
		public long		dwPTDVersion;			
		public long		dwPTDSize;				
		public long		dwPTDPaperInfoNum;		
		public long		dwModelInfoOffset;		
		public long		dwPaperInfoTopOffset;	
		public long		dwSourcePaperBlockSize;	
		public long		dwReserve;				

	public struct PTDMODELINFO
		public byte		bySeriesCode;					
		public byte		byModelCode;					
		public char[]		dmDeviceName;					
		public long		dwModelVersion;					
		public long		dwDeviceAbility01;				
		public long		dwDeviceAbility02;				
		public long		dwHeadPinNum;					
		public short		wMinCopies;						
		public short		wMaxCopies;						
		public short		wMinCutEveryNum;				
		public short		wMaxCutEveryNum;				
		public short		nDefaultPaperSize;				
		public short		nDefaultPaperLength;			
		public short		nDefaultPaperLengthRes;			
		public short		wResolutionNum;					
		public short[]		wResolutions;	
Comment 7 Sebastien Pouliot 2013-08-28 09:42:24 UTC
Fixed in maccore e7a4d3e27c724fb64064cc1d3af0553aebda9eea

StructsAndEnum.cs was not needed. Another issue (fixed now) made the exception not displayed on the console.

I added a check for matching the Delegates and Events so a more useful message will be shown in the future. E.g.

> error BI1023: btouch: The number of events and delegates must match for `BRPTouch.BrotherPrinterTouchNetwork`

Thanks for your help.