RegEx crash on Xamarin.Android but not on Xamarin.iOS

ShawnCastrianni.5092ShawnCastrianni.5092 US ✭✭✭
edited January 2014 in General

The following single line of code works on iOS but crashes on Android:

Regex rg = new Regex("<img.*?src\\s*=\\s*[\"']data:image/([^;]+);base64,([^\"']*)[\"'].*?/>");

The crash on Android is:

Object reference not set to an instance of an object
at System.Text.RegularExpressions.PatternCompiler.BeginLink (System.Text.RegularExpressions.LinkRef lref) [0x00000] in <filename unknown>:0 
at System.Text.RegularExpressions.PatternCompiler.EmitBalanceStart (Int32 gid, Int32 balance, Boolean capture, System.Text.RegularExpressions.LinkRef tail) [0x00000] in <filename unknown>:0 
at System.Text.RegularExpressions.Syntax.CharacterClass.Compile (ICompiler cmp, Boolean reverse) [0x00000] in <filename unknown>:0 
at System.Text.RegularExpressions.Syntax.Group.Compile (ICompiler cmp, Boolean reverse) [0x00000] in <filename unknown>:0 
at System.Text.RegularExpressions.Syntax.Group.Compile (ICompiler cmp, Boolean reverse) [0x00000] in <filename unknown>:0 
at System.Text.RegularExpressions.Syntax.RegularExpression.Compile (ICompiler cmp, Boolean reverse) [0x00000] in <filename unknown>:0 
at System.Text.RegularExpressions.Regex.CreateMachineFactory (System.String pattern, RegexOptions options) [0x00000] in <filename unknown>:0 
at System.Text.RegularExpressions.Regex.InitNewRegex () [0x00000] in <filename unknown>:0 
at System.Text.RegularExpressions.Regex.Init () [0x00000] in <filename unknown>:0 
at System.Text.RegularExpressions.Regex..ctor (System.String pattern, RegexOptions options) [0x00000] in <filename unknown>:0 
at System.Text.RegularExpressions.Regex..ctor (System.String pattern) [0x00000] in <filename unknown>:0 
at RigInfoMobile.Services.EditorialArticle.ComputeBase64ImageCache () [0x0002a] in /TFS/MvvmCross/Applications/ActivityTracker/RigInfoMobile.Common/Services/EditorialArticle.cs:46 

My version info is:

=== Xamarin Studio ===

Version 4.2.2 (build 2)
Installation UUID: 88c39191-efa4-491f-a4c5-ebd6337dcfd6
Runtime:
    Mono 3.2.5 ((no/964e8f0)
    GTK+ 2.24.20 theme: Raleigh
    GTK# (2.12.0.0)
    Package version: 302050000

=== Apple Developer Tools ===

Xcode 5.0.2 (3335.32)
Build 5A3005

=== Xamarin.Android ===

Version: 4.10.1 (Enterprise Edition)
Android SDK: /Users/scastrianni/Library/Developer/Xamarin/android-sdk-mac_x86
    Supported Android versions:
        4.2 (API level 17)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Xamarin.Mac ===

Xamarin.Mac: Not Installed

=== Xamarin.iOS ===

Version: 7.0.5.2 (Enterprise Edition)
Hash: 9c42159
Branch: 
Build date: 2013-02-12 20:04:08-0500

=== Build Information ===

Release ID: 402020002
Git revision: c5f82958ae7d9af652b44b87ceff777b3ad19b91
Build date: 2013-11-19 15:35:40+0000
Xamarin addins: a4044fee09138f6fd031a9944b7caaeb51e57e80

=== Operating System ===

Mac OS X 10.8.5
Darwin Shawns-MacBook-Pro.local 12.5.0 Darwin Kernel Version 12.5.0
    Sun Sep 29 13:33:47 PDT 2013
    root:xnu-2050.48.12~1/RELEASE_X86_64 x86_64

Posts

  • Strange. If I move that line of code to the app startup section, it works fine on Android. If I put a breakpoint near that line of code back in the place where it crashes, sometimes it works. The place where it crashes is running on a separate thread. Is there some kind of threading issue with regex?

  • QuakeulfQuakeulf NOMember ✭✭✭

    I still have this issue.

  • AshleyGazichAshleyGazich USXamarin Team Xamurai

    @Quakeulf

    This thread is quite old and may not be relevant for the issue you are having. For troubleshooting a new scenario, I would recommend creating a new forum discussion or question. Thanks!

  • QuakeulfQuakeulf NOMember ✭✭✭

    The Regex-functionality has not changed over the years and is unlikely to change over the next years either.

    The problem comes when I implement it like this using System.Text.RegularExpressions:

    if (Regex.Match(entry.Text, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$").Success) { //Valid } else { // Invalid }

    I got this code from another user on these fora. This crashes the app every time it gets used. I've only tried on Android SDK 7.0 with minimum SDK set to 6.0.

Sign In or Register to comment.