Second "contains" action crashes application

I’m using sips (the command line version of image events) to retrieve the type of file and the bit depth (the last one can’t be done with image events).
I retrieve the format (jpeg or tiff) and the bitspersample (8bit or 16bit) and use a contains to get the info.

			set ImgInfo to (do shell script "sips -g format -g bitsPerSample " & quoted form of theItem)
			set lookingfor to "tiff"
			set Imgformat to ImgInfo contains lookingfor --true when tiff
			set lookingfor to "16"
			set sixteenbit_input to ImgInfo contains lookingfor

However, the second contains makes my application crash with an “Applescript error NSInternalScriptError (8)”.
I already tried to split the code like

			set ImgInfo to (do shell script "sips -g format" & quoted form of theItem)
			set lookingfor to "tiff"
			set Imgformat to ImgInfo contains lookingfor --true when tiff
			set ImgInfo to (do shell script "sips -g bitsPerSample " & quoted form of theItem)
			set lookingfor to "16"
			set sixteenbit_input to ImgInfo contains lookingfor

This second code snippet also crashes. Reversing the code, first bitdepth than file type, doesn’t change anything: the second one crashes.
Using other variable names in the second step doesn’t make a difference either: it still crashes.

Why does this happen?

Update: the debug message is “2008-12-06 17:50:21.050 ImageFuser[428] *** -[NSCFArray length]: selector not recognized [self = 0x3e6490]”

Hi,

I tried the scripts in normal AppleScript and both worked fine.
Is the portion of the script in any reference tell block like

tell window "main"

These tell blocks can cause problems, if they contain lines which actually don’t need any target like shell scripts

Thanks for your reply.
I copied the code to the Applescript editor (and added a line with a filename before it) and it ran fine.

I deleted the original code and copied (the already copied) code back into my original script inside my XCode project. Now it works!

Obviously something must have been “corrupt”: some hidden character or who knows what.

Is there a way to check my code for these kind of weird things (a hidden/corrupt character recognizer?). It took me hours and in the end I only had to copy it back & forth to solve it (thanks to your hint)

not that I am aware of