0

I am facing a pretty weird issue, and I can't understand even after hours of research, so that's why I am sharing this problem.

I created a little Windows Form which is working perfectly on my computer, both with a Debug version and a release version. Everything was pretty nice, until I tried to launch it on the computer which is supposed to really use it. I got the famous CLR20r3 error, so I search on Internet and saw various possible causes :

  • References used by the software might not be on the computer which is running the software, so I added all the references as local copies.
  • It could be a .NET issue, so I uninstall and re-installed it.
  • It might be some specific CPU weird standard, so I tried to deploy it for x86 only.

But none of those solutions worked. After hours and hours of trials, compilations and reseaches, I found the cause : I have this specific part in my code, which is supposed to remove any extra-spaces from logs strings :

for(int i = 0; i < lastlogs.Length; i++)
{
    RegexOptions options = RegexOptions.None;
    Regex regex = new Regex("[ ]{2,}", options);
    lastlogs[i] = regex.Replace(lastlogs[i], " ");
}

If I comment out this part, the code is running perfectly. I added a reference to System.Text.RegularExpressions, but I can't see it in the assemblies list, so I suppose it is some kind of build-in Windows assembly. But if that's the case, it's strange that the software crashes because it can't find it...

I would like to understand why this crash is happening, and if anyone have a possible way to solve this problem.

Louis 'LYRO' Dupont
  • 1,052
  • 4
  • 15
  • 35
  • System.Text.RegularExpressions is part of System.DLL. See the documentation for the Regex class. –  Aug 08 '17 at 13:19
  • 1
    I take it there's an exception being thrown when calling the regex.Replace? What are the exception details? – Russell Troywest Aug 08 '17 at 13:22
  • Thanks @Amy for your answer, but it seems that System.DLL can't be added as a local copy neither. That's why I find it's a strange behaviour. – Louis 'LYRO' Dupont Aug 08 '17 at 13:23
  • 1
    System.DLL is in the GAC. There's no reason to add it as a local copy. –  Aug 08 '17 at 13:23
  • @RussellTroywest When I run this with my developement PC, there is absolutely no exception. Since the test PC doesn't have Visual Studio on it, I can't really test that, but the only exception I can see is this CLR20r3 – Louis 'LYRO' Dupont Aug 08 '17 at 13:25
  • 3
    Of course you can see the exception. Use a try/catch block, and log the exception. Also log the variables in use at the time of the exception, such as `i` and `lastLogs[i]`, so you can know the conditions under which the exception was thrown. –  Aug 08 '17 at 13:25
  • You might be able to get the details from the event viewer on the machine that the software is failing on. – Russell Troywest Aug 08 '17 at 13:26
  • I'm going to guess that that at some point lastLogs[i] is null and replace is throwing an ArgumentNullException. You need to get the exception details though and work out what's going on. – Russell Troywest Aug 08 '17 at 13:28
  • 1
    Possible duplicate of [Remove all whitespace from C# string with regex](https://stackoverflow.com/questions/16346146/remove-all-whitespace-from-c-sharp-string-with-regex) – Dennis Christian Aug 08 '17 at 13:29
  • @RussellTroywest thanks a lot that was exactly the case, I forgot to check for null entries, which was raising the Argument.NullException. Thanks a lot. – Louis 'LYRO' Dupont Aug 08 '17 at 13:31
  • 2
    @DennisChristian If you have read the question you obviously saw that the issue is absolutely not about removing whitespaces with regex but about a compiled programm error. – Louis 'LYRO' Dupont Aug 08 '17 at 13:32
  • 1
    FYI a CLR20r3 error is usually code related. See: https://stackoverflow.com/q/4052770/3740093 – Visual Vincent Aug 08 '17 at 17:58

0 Answers0