Can't Build Program Because It's Being Held Hostage by Another Program

0

I know this has been asked before, but none of the questions I've looked at seem to answer my question. So, with that, and to assure I've done my homework before someone gets on me, let me tell you what I've done to cause the error, and what I've tried to fix the problem.

This all started two days ago. I created a spritesheet animator program so that I can quickly edit sprite sheets. I'm still in the process of adding some aesthetic touches to the program, but with the functionality working more or less, I didn't really get around to it. That day, though, I figured I could add an icon to it, at least. So I made it, attached it to the program, and watched it appear on the taskbar in all its beauty.

Now I tend to use the program a lot, but it's not finished yet, so I haven't "Released" it yet. I thought that I could just pin it to my taskbar, and just have the reference be to the bin/Debug version of the program. However, I found that when I did this, the icon, which I had been tweaking that day, was not showing up properly (totally different problem not related to this one). So I had to pin and unpin the program multiple times. I knew that sometimes, on some systems, the icon won't change or appear on the taskbar properly until after you restart the computer. So at the end of the day, I shut it down, and restarted the next day. It didn't work.

At that point, it didn't seem all that important to me, so I just decided to postpone the edit and continue with my spritesheet work. After a while, I wanted to see it in action, so I fired up my animator via the taskbar. That was when Avast! started up trying to analyze the thing, to see if it was a virus. I figured "OK. It's not a virus, but you'll find out in a little bit." A little bit passed (about an hour), and the thing never finished. After multiple tries to get the accursed over-cautious virus protection to leave my program alone, I decided to unpin it and run it from the IDE. It worked fine at that point. I re-pinned it afterwards, and it would run normally from either option: via IDE or from the taskbar.

After another day and restart, I decided that I had enough of the ugly icon, and edited it one more time. I put it into the program, but when I tried to build, it hung there for longer than usual, then came back saying something like this:

Unable to copy file "obj\x86\Debug\SpriteSheetAnimator.exe" to "bin\x86\Debug\SpriteSheetAnimator.exe". The process cannot access the file 'bin\x86\Debug\SpriteSheetAnimator.exe' because it is being used by another process.

Following this message were warning messages, detailing how many times it tried to build it (10 times).

Here starts the methods of trying to fix the problem, if you've read this far.

  • I thought that was weird, so I decided to just clean it and rebuild. I got this from the attempted cleaning:

Unable to delete file "C:...\bin\x86\Debug\SpriteSheetAnimator.exe". Access to the path 'C:...\bin\x86\Debug\SpriteSheetAnimator.exe' is denied.

  • Ok. This sucks. So after trying to manually delete the \bin and \obj folders, I found that it still wouldn't let me, for the same reasons.

Those were a day ago. Today I tried these:

  • I found that processes could have a handle on the files, so after some research I found handle.exe from SysInternalSuite could fix the problem. I tried to enter "handle -c 18 -y -p 5946" into a command prompt. It didn't work, and all I got back from handle was an error:

T

That's it. No typo or omitted letters. "T"-- that's all I got as an error.

  • I also found that I could just delete the threads using Process Explorer from the same suite. Somehow I had three of them, even though the program is not multi-threaded. Anyway it didn't matter; when I tried to kill them, it said I didn't have access.

So that's it. I can't think of anything else to do.

I'm using Windows 8.1 with VS2013.

Handle is version 4.0

If you want the handle dump let me know, and I'll add it. It's really junky, and all this may get erased for being to long.

Sage Kelly

Posted 2015-09-24T14:49:22.527

Reputation: 1

Ok, so did you ensure you still actually have write permission to that folder/file? And that the file is not marked Read-only? Have you tried rebooting and attempted deleting again? Did you attempt to use Process Explorer to figure out what's holding that file's handle? – Ƭᴇcʜιᴇ007 – 2015-09-24T14:58:34.637

>

  • Reboot. 2. use your IDEs Clean option. 3. Configure the icon as a resource inside your project, and apply it at complile/build time, if you are going to reference the copy that is built and rebuilt every time you make a change. 4. your AV issue is unrelated, so get the icon hammered out, and then focus on the AV handle issue (or vice versa, but its really confusing when they are conflated; divide and conquer). 5. use try-finally structures for all files your app opens, and don't just stop the program during debugging if it has a file open. run the app until the file is closed, then abort.
  • < – Frank Thomas – 2015-09-24T15:01:21.687

    Both of your comments lead me to believe that my initial comment was not read completely. The folders are not read only: I never changed the folder permissions, and they're part of a solution build, and if you read in the post, you have seen that I used handle to see what was holding the file's handle. @FrankThomas: I rebooted multiple times within the post, and it has been established that Clean solution does not work. My icon issue is a separate issue, thus focus should not be divided toward it. Finally, I have no idea what you're saying on step 5. – Sage Kelly – 2015-09-24T15:08:12.957

    @Ƭᴇcʜιᴇ007 Even so, I did use Process Explorer, and it showed that SpriteSheetAnimator.exe, the program itself, had three threads open. – Sage Kelly – 2015-09-24T15:16:37.567

    No where in your post do you mention that the file has been checked for read-only, and assuming that just because you didn't (intentionally) change anything about the permissions doesn't mean they didn't get changed. I was asking for verification that they were still set right, since you didn't mention that you had checked them. Have you checked for disk corruption yet? If the program itself was running (3 threads worth you seem to say), then yes, of course you can't delete the file. If you kill the things holding it, and delete it, can you then successfully rebuild it? – Ƭᴇcʜιᴇ007 – 2015-09-24T15:21:55.257

    @Ƭᴇcʜιᴇ007: I'm sorry. I snapped a little. Last time I wrote something this long, I got a comment saying, "tl;dr show me code", so my tolerance is a little shallow...and my anger misguided. Anyway, I found that each time I build the program it will change the \bin and \obj folders to read only, as well as its subfolders. How would I go about checking for disk corruption? I can't kill any handles. I keep getting "T" when I try. – Sage Kelly – 2015-09-24T15:27:58.857

    1@SageKelly - running chkdsk provided you have proper backups. I assume you have configure your security program to except scanning and watching at these specific locations your program appears in right? – Ramhound – 2015-09-24T15:30:49.743

    Folders will always appear read-only (that's a general Windows thing). :) – Ƭᴇcʜιᴇ007 – 2015-09-24T16:00:25.843

    @Ramhound: Yes, I do. However, just recently, which I didn't include in my post, I added my entire project as an exclusion to scanning so it would this, and other projects I make, alone. I don't have backups, so I'm not sure if I should chkdsk. – Sage Kelly – 2015-09-24T16:12:52.653

    So create backups. – Ramhound – 2015-09-24T16:15:02.687

    Well, the program is under GitHub subversion. Does that count? or do you want me to do the entire C drive? – Sage Kelly – 2015-09-24T16:17:52.570

    No answers