views:

238

answers:

3

Using Visual Studio 2005 with the latest Service Pack.

I have a managed C++ solution with 38 projects (that I've just inherited.) When I build this solution, I'm receiving the following error from the Assembly Linker:

"error AL1019: Metadata failure while creating assembly -- The process cannot access the file because it is being used by another process."

I'm kind of at a loss as to how to resolve or troubleshoot this. The surrounding steps in the build output are:

  1. Writing Resource File... Done.
  2. Compiling resources...
  3. Linking...
  4. Creating library [PATH]\[FileName].lib and object [PATH]\[FileName].exp
  5. Creating resource satellites...
  6. Error Occurs Here.

There is no difference in the results between Build vs Rebuild vs Project Only with or without Cleaning the Solution first. And, in all cases, the DLL, EXP, ILK, LIB and PDB files for this project are created.

I've compared this particular project to other projects in the solution that are structured similarly and see no appreciable differences. I've looked at the batch files and temporary rsp files that get generated during the build process and see nothing that jumps out there either.

My current speculation is that the Linker is trying to embed the Intermediate Manifest file into the assembly while something else is still trying to write to the same Intermediate Manifest file (or to the assembly itself.) Though, I'm kind of guessing at this point.

If anyone knows how to resolve this or has any insight as to what else to look into to try and troubleshoot I'd greatly appreciate it. Thanks.

A sanitized version of the end of my build log, if it helps:


    /ASSEMBLYRESOURCE:".\Debug\[Namespace].[ErringProject].dll.licenses" 
    ] 
    Creating command line "link.exe @[Path]\[ErringProject]\Debug\RSP00030A20042852.rsp /NOLOGO /ERRORREPORT:PROMPT" 
    Creating temporary file "[Path]\[ErringProject]\Debug\RSP00030B20042852.rsp" with contents 
    [ 
    /out:"[OutputPath]\[Namespace].[ErringProject].dll" 
    /c:Run 
    /template:"..\..\..\..\..\Run\[Namespace].[ErringProject].dll" 
    /embed:".\Debug\[Namespace].StringsNT.resources" 
    /embed:".\Debug\[Namespace].Strings.resources" 
    ] 
    Creating command line "al.exe @[Path]\[ErringProject]\Debug\RSP00030B20042852.rsp /nologo" 

+2  A: 

Try navigating directly to the problem file and see if you can delete it yourself. If you can't, rename it (yes, sometimes you can rename files even though they're in use) and try the build again. Sometimes something holds the file open and even a clean can't delete it.

If the above doesn't work try adding an exception to your build directory in your anti-virus software. I've had this issue with Symantec Endpoint Protection. As soon as the file was written and closed, it would open it to scan it right when the next step was to edit that file. Needless to say, the file was "in use" and caused the build to fail.

Joshua
If the file is blocked ("in use") and you cannot rename or delete it, you can still find out which process is accessing the file by using the ProcessExplorer [http://technet.microsoft.com/en-us/sysinternals/default.aspx] (Find Handle Or DLL).
MP24
Unfortunately, nothing tells me *which* file is in use. I have ensured that all outputs are cleaned prior to building and, upon erring, I've used process explorer to see if any of the temporary or final output files have a lock -- they do not.
Jacob G
Antivirus changes also make no impact.
Jacob G
Post part of your build log. If you open the .htm file it should also show you the command line that visual studio executed. This should point you in the direction of the locked file.
Joshua
Try cleaning out all of the files manually in your `[Path]\[ErringProject]\Debug` folder. Also, try closing the `{exe}.vshost.exe` file that is probably running in the background (using task manager). Visual Studio will relaunch it right away but that may let you rebuild.
Joshua
I clear out all of the files everytime (in case Clean doesn't work). I get the same results unfortunately if vshost.exe isn't running.
Jacob G
A: 

This is a problem that seems relativelty common with VS2005, but MS closes the issue as a non-repro (I suspect the problem is connected to some interaction with other applications/drivers installed on the system that MS doesn't have on their test beds).

I've heard that people have worked around the problem by changing the output directory in the project settings, but I'm not sure how permanent or reliable the workaround is. Another thing to try (if it's possible for you and hasn't already been done) is to update to to SP1 or VS2008.

Michael Burr
I'm on the latest Service Packs and can't upgrade, unfortunately. Changing the output directory didn't work.
Jacob G
If you have any support incidents with MS (and you probably do if you have an MSDN subscription) I'd say it's worth calling one of those in.
Michael Burr
A: 

Finally tracked this down to the order of the XML Filter Collections in the Project file when using the external resource compiler (i.e. resgen.)

The failing project had, in its Proj file:

<files>
    <Filter Name="Header Files" ...>
        ...
    </Filter>
    <Filter Name="Resource Files" ...>
        ...
    </Filter>
    <Filter Name="Source Files" ...>
        ...
    </Filter>
</files>

Switching that to:

<files>
    <Filter Name="Header Files" ...>
        ...
    </Filter>
    <Filter Name="Source Files" ...>
        ...
    </Filter>
    <Filter Name="Resource Files" ...>
        ...
    </Filter>
</files>

Did the trick.

Jacob G