1

I'm getting this error:

Could not copy the file "obj\x86\Debug\TitleGenerator.exe" because it was not found.

When I try to compile, but it doesn't make any sense. The only thing I changed was to add the following lines of code to help me debug an issue:

#if DEBUG
                if( title.Culture == null || title.Religion == null )
                {

                }
#endif

If I remove those lines, it compiles with no issue. If I change the if statement to if ( true ) {} it compiles fine.

Restarting Visual Studio doesn't help. I've also tried restarting my PC. As far as I can tell, the .Net framework, and Visual Studio are both up to date.

I'm using Visual Studio 2012, a target framework of 3.5, with the Default language level, CSS version 3.0

[Edit] It's now started working again. All I did was to remove output of title.TitleID from the output to the log.

Meaning I changed things like Log( " --Title in Ignore List: " + title.TitleID ); to Log( " --Title in Ignore List" );

The contents of title are decided during runtime, and it's the object of a foreach loop over a list.

Even more strangely, if I add this class to the project:

public class DebugBreak
{
    [Conditional("DEBUG")]
    public static void TitleIDBreak( Title title, string id )
    {
        if ( title.TitleID == id )
            System.Diagnostics.Debugger.Break();
    }
}

But don't even do anything with it, then it works. I don't even have to call the method. Just changing the build action of the file from None to Compile makes it work.

Measter
  • 68
  • 2
  • 8

3 Answers3

1

This is commonly caused by Avast.

If you are running that antivirus, add an exclusion for your project folder.

I've searched for this several times in the past. Its a file access issue, so it may not be your code at all.

0

What type is title? Is it even defined? Statements are checked for semantics even if DEBUG is not defined.

I'm guessing your code is not compiling.

C# does not use a "pre-processor" like early C compilers where the file was changed before the compiler even saw it.

Hogan
  • 69,564
  • 10
  • 76
  • 117
  • The title object is checked before that, and works fine. I'm not getting any errors are warnings apart from that one. I also get that error if I try to check if another object is null. – Measter Aug 14 '13 at 17:30
  • Code between #if #endif does not get compiled if the condition isn't met. http://msdn.microsoft.com/en-us/library/4y6tbswk.aspx – CodeCaster Aug 14 '13 at 17:34
  • @Measter - is this really your code? Have you put a `;` in for the empty statement? – Hogan Aug 14 '13 at 17:47
  • I've put empty if statements in code before while debugging, and have had no issue. It's actually started working again now. All I changed was some references to title.titleID in logging output. – Measter Aug 14 '13 at 18:40
  • @Hogan can you explain what you mean by 'checked for semantics'? – CodeCaster Aug 15 '13 at 05:24
  • @CodeCaster - It has to be legal code which **would** compile, but is not compiled – Hogan Aug 15 '13 at 10:30
  • @CodeCaster - That looks like mono to me, but I could be wrong. – Hogan Aug 15 '13 at 11:21
  • Their compiler adheres to the C# spec (relevant section: 2.5) as wel as MS's compiler: _"pre-processing directives can be used to include or exclude sequences of tokens and can in that way affect the meaning of a C# program"_. Code between `#if /*...*/ #endif` is *not seen* by the compiler if the condition isn't met, nor 'checked for semantics'. :-) – CodeCaster Aug 15 '13 at 11:37
  • @CodeCaster - You are right, it is the pre-processor directives which must be lexically correct. But it is possible to put text into the cause the compiler to fail. – Hogan Aug 15 '13 at 15:43
0

There's nothing wrong with the code you have written based purely on what you've posted.

One thing you can try is to use a Conditional attribute for your debugging. Something like:

[Conditional("DEBUG")]
static void TitleCheck(Title title)
{
    if( title.Culture == null || title.Religion == null )
    {
        System.Diagnostics.Debugger.Break();
    }
}


private void MyProductionFunction(Title title)
{
    // Do some stuff

    TitleCheck(title); //<< This function call will be omitted completely if 'debug' conditional isn't met.

    // Do more stuff
}
McAden
  • 13,714
  • 5
  • 37
  • 63