大字符串常量会导致C#编译器崩溃

大字符串常量会导致C#编译器崩溃

本文介绍了大字符串常量会导致C#编译器崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个带有一些大字符串常量的C#应用​​程序,每当我尝试构建解决方案时,编译器崩溃时都没有错误消息。在

进一步分析时,当字符串常量大约为2100字符时,问题似乎发生了。我尝试将常量声明更改为字符串

变量声明,它工作正常。


有什么想法吗?


以下代码可用于重现错误:


const string TEST =

" 1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +

" 1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +

" 1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +

" 1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +

" 1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +

" 1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +

" 1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +

" 1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +

" 1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +

" 1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +

" 1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +

" 1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +

" 1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +

" 1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +

" 1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +

" 1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +

" 1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +

" 1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +

" 1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +

" 1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +

" 1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" ;;


问候

Gnik

I created a C# application with some large string constants and whenever I
try to build the solution the compiler crashes with no error message. On
further analysis the problem seems to occur when the string constant has
around 2100 character. I tried changing the constant declaration to a string
variable declaration and it works fine.

Any ideas?

The following code can be used to reproduce the error:

const string TEST =
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0";

Regards
Gnik

推荐答案






无法在这里重现。编译并执行正常。

-

Tom Porterfield



Not able to reproduce here. Compiles and executes fine.
--
Tom Porterfield





这篇关于大字符串常量会导致C#编译器崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 23:18