我的代码中有以下声明,它可以在.NET框架工作2.0中正常工作,最近我将项目升级到了框架4.0,并且我得到了构建错误,说嵌入式声明不能声明.Net 2.0 vs 4.0
“嵌入语句不能是声明”
任何想法,这里有什么问题?
const int sNoPrompt = 0x1;
const int sUseFileName = 0x2;
const Int32 sEmbedFonts = 0x10;
const int MultilingualSupport = 0x80;
我的代码中有以下声明,它可以在.NET框架工作2.0中正常工作,最近我将项目升级到了框架4.0,并且我得到了构建错误,说嵌入式声明不能声明.Net 2.0 vs 4.0
“嵌入语句不能是声明”
任何想法,这里有什么问题?
const int sNoPrompt = 0x1;
const int sUseFileName = 0x2;
const Int32 sEmbedFonts = 0x10;
const int MultilingualSupport = 0x80;
我明白了,在声明之上有一个IF声明,没有大括号。这是造成错误的原因。我刚刚删除了IF,因为在我的情况下这没有必要。现在它工作正常。
该代码在框架4.0中运行完美,可能是您在其他代码行中遇到了问题。
我之前使用下面的代码工作正常。
if (output == "Success")
terminate();
Configuration config =
ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
var setting = config.AppSettings.Settings["PATH"];
由于需求的变化,我注释掉的函数调用结束()
if (output == "Success")
//terminate();
Configuration config =
ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
var setting = config.AppSettings.Settings["PATH"];
这引发错误嵌入语句不能在配置变量声明声明或标记语句线。并且抛出另一个错误在设置变量声明行中使用未分配的局部变量“config”。
由于terminate()被注释,它会尝试将下一条语句作为if条件块。
解决方案是注释掉满条件块。
//if (output == "Success")
//terminate();
Configuration config =
ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
var setting = config.AppSettings.Settings["PATH"];
另一种解决方法是根据需要放置花括号。
if (output == "Success")
{
//terminate();
Configuration config =
ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
var setting = config.AppSettings.Settings["PATH"];
}
请显示重现错误的示例。或者自行搜索错误代码,以查看有关错误的更多信息。 –
还可以查看http://blogs.msdn.com/b/spike/archive/2010/02/16/compiling-application-gives-embedded-statement-cannot-be-a- declarative或orlabeled -statement。 aspx和http://stackoverflow.com/questions/15946679/embedded-statement-error –
在我的测试中工作得很好。请给出更多的代码,例如代码所在的类。 – Kai