C# 嵌入式语句不能是.Net 2.0 vs 4.0的声明
我的代码中有以下声明,它们在.NETFramework2.0中运行良好,最近我将项目升级到Framework4.0,我得到的构建错误是 “嵌入语句不能是声明” 你知道这里怎么了吗C# 嵌入式语句不能是.Net 2.0 vs 4.0的声明,c#,declaration,C#,Declaration,我的代码中有以下声明,它们在.NETFramework2.0中运行良好,最近我将项目升级到Framework4.0,我得到的构建错误是 “嵌入语句不能是声明” 你知道这里怎么了吗 const int sNoPrompt = 0x1; const int sUseFileName = 0x2; const Int32 sEmbedFonts = 0x10; const int MultilingualSupport = 0x80; 代码在framework 4.0中运行得很好,可能是您在代码的其
const int sNoPrompt = 0x1;
const int sUseFileName = 0x2;
const Int32 sEmbedFonts = 0x10;
const int MultilingualSupport = 0x80;
代码在framework 4.0中运行得很好,可能是您在代码的其他行中遇到了问题。代码在framework 4.0中运行得很好,可能是您在代码的其他行中遇到了问题。我发现,声明上方有一个IF语句,没有大括号。是什么导致了这个错误。我只是删除了IF,因为它在我的情况下是不必要的。现在它可以正常工作了。我发现,声明上方有一个IF语句,没有大括号。是什么导致了这个错误。我只是删除了IF,因为它在我的情况下是不必要的。现在它可以正常工作了。我之前使用的代码工作正常
if (output == "Success")
terminate();
Configuration config =
ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
var setting = config.AppSettings.Settings["PATH"];
由于需求的变化,我注释掉了函数调用terminate()
这会引发错误嵌入语句不能是配置变量声明行中的声明或标记语句。另一个错误是在设置变量声明行中使用未分配的局部变量“config”时抛出的
由于terminate()已注释,因此它尝试将下一条语句作为if条件块
解决方案是注释掉full 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"];
}
我使用了下面的代码,在这之前它工作得很好
if (output == "Success")
terminate();
Configuration config =
ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
var setting = config.AppSettings.Settings["PATH"];
由于需求的变化,我注释掉了函数调用terminate()
这会引发错误嵌入语句不能是配置变量声明行中的声明或标记语句。另一个错误是在设置变量声明行中使用未分配的局部变量“config”时抛出的
由于terminate()已注释,因此它尝试将下一条语句作为if条件块
解决方案是注释掉full 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"];
}
请出示重现错误的样本。或者自己搜索错误代码,以查看有关错误的更多信息。也请检查并在我的测试中运行良好。请提供更多的代码,例如,包含代码的类。请显示重现错误的示例。或者自己搜索错误代码,以查看有关错误的更多信息。也请检查并在我的测试中运行良好。请提供更多的代码,例如,包含代码的类。