2

I am trying to understand why VS loses all keyword higlighting after this line of code. The code will compile but it will through exeptions.

the string is a base64string represenation of an image. If you remove the first letter VS recognizes that the characters are a valid string, compiles and no exceptions. Interestingly enough, the string is 32,742. If you add 32,743..its a no-go. I assume it is related to

  1. a limit to how you can initialize a string
  2. a need to use a different data type like char.

Anyone have an idea..I just stumbled upon this and now I am curious.

Bob

string g = "Any string greater that 32,742 characters suddenly disables all keyword highlighting and code will fail......";
H H
  • 263,252
  • 30
  • 330
  • 514
boblautenbach
  • 53
  • 1
  • 8
  • 4
    3) too big of a context for visual studio to parse for keyword highlighting? – crashmstr Mar 20 '14 at 19:55
  • 10
    3a) and a reason to put it into an external file. Really, such a long text has *no* place within source code. – poke Mar 20 '14 at 19:56
  • 1
    possible duplicate of [does c# string has length limit](http://stackoverflow.com/questions/4486261/does-c-sharp-string-has-length-limit) – Scott Mar 20 '14 at 19:56
  • I am not one hundred percent sure but I seem to have a vague recollection that Microsoft program databases (debug information) have a line length limit of 32 thousand 700 and some characters. – 500 - Internal Server Error Mar 20 '14 at 19:56
  • 1
    Works fine here (Visual Studio 2013 Ultimate on Win8.1) – Sylence Mar 20 '14 at 19:57
  • 2
    It's not really a C# limit, more of a Visual Studio limit. I'm sure there's a lot of code that goes into the syntax highlighting and intellisense and other such things. There could be data types and variables with limits on them within that code, for any number of reasons. (Performance, maintainability, etc.) Two things to consider are: 1) How often does this *really* come up? 2) Is it worth it for the Visual Studio team to "fix" this? – David Mar 20 '14 at 19:58
  • 1
    That length is strikingly close to 65536 / 2 – Millie Smith Mar 20 '14 at 20:04
  • When your string exceed a certain number of lines, you should really re-think whether or not you want that string inside your code.. – theGreenCabbage Mar 20 '14 at 20:11
  • 1
    @Scott why link to another post that is also a duplicate? Need to practice your recursion ;) Possible duplicate with better answer: http://stackoverflow.com/questions/140468/what-is-the-maximum-possible-length-of-a-net-string – DLeh Mar 20 '14 at 20:29
  • Sylence..I am using VS 2012..let me try vs2013 as well..it could be just a bug in VS 2012 – boblautenbach Mar 20 '14 at 20:35
  • tried in Vs2013 and it stil did not work. – boblautenbach Mar 20 '14 at 20:39
  • This is not to answer the question, but why are you putting a base 64 encoded image into source code in the first place? Add the image as a resource and use the standard resource manipulation code to extract the image. – Eric Lippert Mar 20 '14 at 21:46
  • Out of curiosity, what exceptions are thrown at runtime? I see the "syntax highlighting disappears" portion of the issue, but the program compiles and runs without issue. – dlev Mar 20 '14 at 23:39

0 Answers0