37

I ran into this problem today while migrating a VS2008 solution to VS2010. The problem occurred in either of the following scenarios:

  1. Rebuild Solution
  2. Clean followed by Build Solution

If I did a second Build after either of these, the problem did not show up. Using Google, all I really came up with was year-old blogs from Microsoft saying they are unable to reproduce the problem, or that it is fixed in a future release.

The best thing I found was here: Mikazo Tech Blog: Solve MT.exe Errors in Visual Studio 2010

In the above article it said that the problem is related to Manifest generation, and that the solution is to turn off Manifests in settings under Linker-->Manifest. I don't need Manifests for this project, but I still wasn't satisfied.

I have solved this, and am simply going to answer my own question, because I haven't found this specific error (code 31) on StackOverflow.

paddy
  • 60,864
  • 6
  • 61
  • 103

12 Answers12

38

WARNING: This exact error can also happen as a result of having a Windows Explorer window open in the folder containing the *.exe which you are currently attempting to build.

For example: Explorer open in /.../MyProj/Debug/ while trying to build the Debug version of your code in Visual Studio.

I was angry with myself for ~10min before realizing this.

bunkerdive
  • 2,031
  • 1
  • 25
  • 28
  • Did you have the target file highlighted in Windows Explorer, or was it simply the act of having that folder open? – paddy Feb 01 '15 at 23:53
  • 6
    It was just open and sitting there. Odd, I know. Soon as I closed it there were no issues. – bunkerdive Feb 02 '15 at 00:36
36

Using process monitor and dbgview I discovered msmpeng (Microsoft Security Essentials) was accessing the file, just when mt.exe wanted to have it exclusively. Excluding the development directory solved the problem. It is still a workaround of course.

Pankrates
  • 3,074
  • 1
  • 22
  • 28
user1839019
  • 486
  • 3
  • 2
  • I haven't verified this, but it seems like the most plausible solution so far =) – paddy Oct 29 '13 at 07:08
  • 1
    I had this issue and this was the cause. However, my solution was to change the Output dir and Intermediate dir to be a directory that's not scanned by the anti virus (I'm on a corporate network and can't configure my anti virus). – ytoledano Feb 01 '15 at 15:51
  • Just for verification; this solution works! Thank you! :) – Rami A. Nov 06 '15 at 09:38
  • The same happened to us overnight and completely unexpectedly. There is no Microsoft Security Essentials anymore, it's called Windows Defender now. It's under Settings -> Update & Security -> Windows Defender -> Add exclusion. – Tamas Demjen Nov 10 '15 at 20:51
  • I also just saw this same issue for the first time this morning. Opening Security Essentials and excluding my Visual Studio project folder fixed it for me as well. Thanks for the solution. – Gixxernaut Jun 15 '16 at 14:44
5

In my projects, the Intermediate and Output directories were set to:

  • Intermediate Dir : $(Configuration)\
  • Output Dir : $(SolutionDir)bin\$(Configuration)\

Under C/C++-->Output Files, I had the following:

  • ASM List Location : $(IntDir)\
  • Object File Name : $(IntDir)\
  • Program Database File Name : $(OutDir)\$(TargetName).pdb

Under Linker-->Manifest File, I had:

  • Manifest File : $(IntDir)$(TargetName)$(TargetExt).intermediate.manifest

The cure was to remove the trailing \ from my C/C++-->Output Files section (because it's already part of those variables):

  • ASM List Location : $(IntDir)
  • Object File Name : $(IntDir)
  • Program Database File Name : $(OutDir)$(TargetName).pdb

Normally, the double-up of using $(IntDir) or $(OutDir) with a trailing \ doesn't seem to cause trouble, even though it's bad practice. I can't remember now whether I did it by accident or if the conversion process did it, but for whatever reason, it seems to have been messing up MT.exe.

I hope this is useful to anyone else who encounters this problem. Your settings may well be different, but consider that it may be related to improperly formed filenames.

paddy
  • 60,864
  • 6
  • 61
  • 103
3

Try turning off Windows Defender (or possibly other anti-virus related software). Windows Defender is known to lock files because MT.EXE runs after the linker is finished. WD jumps in the middle to check up on the newly built EXE and locks it up for the MT.EXE.

wpfwannabe
  • 14,587
  • 16
  • 78
  • 129
  • ^This: Excluding just either the processes of devenv.exe or one's own generated build was not enough. It had to be the folder where the build resided. – Laurie Stearn Nov 30 '16 at 13:01
2

Giving credit to https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/c5a3e2c3-fbf4-4268-a551-8cee195be586/test-case-13-for-vista-certification?forum=windowscompatibility, I found this was resolved by fixing the '-' character in the post build commandline. I believe some bad copy/paste efforts have replaced a hyphen with a dash.

KJAWolf
  • 2,722
  • 1
  • 15
  • 6
  • This was my problem too but the weird thing is the post-build command worked in Visual Studio 2013 but not in Visual Studio 2017 and it started to error. Very weird bad character. – ScottN Jul 11 '18 at 23:28
1

deleting the "program debug database" in "debug" folder worked for me.

This problem happened when I was running the .exe in the debug folder on high priority.

sam
  • 57
  • 1
  • 10
1

Run VS as administrator. It solved the problem for me.

Deamonpog
  • 805
  • 1
  • 10
  • 24
0

I have a project (*.sln) written in visual studio c 8.0. It was migrated to VC10 recently. When I choose the "Release mode", it was compiled sucessfully. But if I choose "Debug mode", the error " MSB6006 mt.exe code 31" happened.

I found that, in the debug mode, it used a wrong sub-project to startup. After fixing the startup sub-project, it goes fine so far.

---- new status --- This won't fix the problem. It just makes the problem disapear temporalily by rebuilding-all. Also, there are other faults caused by the migration. The "resources.h" is missed from the new project and the "winres.rc" is shorten.

jemin
  • 41
  • 4
0

In my case it was a problem with TortoiseGit. Removing Debug and Release folders from the GIT repository solved the problem.

0

Check if you have any anti-virus software like AVG. Exclude the manifest files in the anti-virus software exclusion list.

xiao
  • 151
  • 1
  • 8
0

Look for an MSB8012 warnings. Likely you have a different output specification for the C++ output value and the Linker Output value.

Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
Paul
  • 1
0

Try Sysinternals/Procmon and filter on process = "mt.exe". It might tell you that a build input cannot be found.

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31969750) – Waldi Jun 14 '22 at 08:08