0

I have the following declarations in my code which works fine in .net frame work 2.0, Recently i upgraded the project to frame work 4.0 and Im getting the build error saying

"Embedded statement cannot be a declaration"

Any idea what is wrong here ?

const int sNoPrompt = 0x1;
const int sUseFileName = 0x2;
const Int32 sEmbedFonts = 0x10;
const int MultilingualSupport = 0x80;
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Kurubaran
  • 8,696
  • 5
  • 43
  • 65
  • Please show sample that reproduces the error. Or search by error code yourself to see more info on the error. – Alexei Levenkov May 15 '13 at 07:13
  • Also check out http://blogs.msdn.com/b/spike/archive/2010/02/16/compiling-application-gives-embedded-statement-cannot-be-a-declaration-or-labeled-statement.aspx and http://stackoverflow.com/questions/15946679/embedded-statement-error – Alexei Levenkov May 15 '13 at 07:15
  • 1
    Works perfectly fine in my test. Please give a little bit more code, for instance, the class where the code is contained. – Kai May 15 '13 at 07:17

3 Answers3

3

I figured it out, There was a IF statment right above the declaration without curly braces. Whcih was causing the error. I just removed the IF as it wasn't necessary in my case. now it works fine.

Kurubaran
  • 8,696
  • 5
  • 43
  • 65
2

The code is working perfectly in framework 4.0, May be you had issue in other lines of the code.

0

I was using the following code before which was working fine.

if (output == "Success")
   terminate();

Configuration config = 
      ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
var setting = config.AppSettings.Settings["PATH"];

Because of a change in requirement, i commented out the function call terminate()

if (output == "Success")
   //terminate();

Configuration config = 
      ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
var setting = config.AppSettings.Settings["PATH"];

This throws the error Embedded statement cannot be a declaration or labeled statement in the config variable declaration line. And another error is thrown Use of unassigned local variable 'config' in the setting variable declaration line.

Since terminate() is commented, it tries to take the next single statement as the if condition block.

The solution is to comment out full if condition block.

//if (output == "Success")
   //terminate();

Configuration config = 
      ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
var setting = config.AppSettings.Settings["PATH"];

Another solution is to put curly braces depending on the requirement.

if (output == "Success")
{
   //terminate();

    Configuration config = 
       ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
    var setting = config.AppSettings.Settings["PATH"];
}
senthilraja
  • 167
  • 2
  • 11