locked
Zombie attack from VCLinkerTool? RRS feed

  • Question

  • Hello,

    I have simple piece of code that checks VC Project settings. It works fine up to this line of code:

    enumlinkFixedBaseAddress enFixed = linker->FixedBaseAddress;

    And then I get _com_error exception with this hresult code:

    VCPROJ_E_ZOMBIE (0x80050506L)

    This error will be returned if the item is in a zombie state.

    I tried to look up any documentation on this error code and found... Nothing!

    What zombies? Are they coming for my brain? ;)

    Any information about this error code will be greatly appreciated.

    Regards,

    Victor

    Wednesday, June 5, 2013 4:29 AM

Answers

All replies

  • Generally 'zombie' means the item you are interacting with has been invalidated, either via project unload or some previous action you took. Hard to say without the complete repro, but I suspect some property you set before had the effect of making linker invalid, but without knowing the types and sequence of calls involved that is just a guess.
    Wednesday, June 5, 2013 11:12 PM
  • OK. The original code is in C++. It is part of a larger VS integration project and is kind of hard to read. But, here is a simplified C# code with a similar behavior. When I run it, I get this output:

    Project:Hello2008:Debug|Win32
    Cannot access data for the desired tool since it is in a zombie state.

    You should import the appropriate version of VCProjectEngine before you build it. The imported version should match the DTE ProgId specified in the strProgId in the  Program.Main(). The code in question is implemented in the PrintOptions method.

    using System;
    using System.Collections.Generic;
    using System.Runtime.InteropServices;
    using System.Text;
    using EnvDTE;
    using Microsoft.VisualStudio.VCProjectEngine;
    
    namespace VSAutomation
    {
    
        public class VSAutoException : Exception
        {
    
            public VSAutoException(string i_strMsg)
                : base(i_strMsg)
            {}
        }
    
        public class VSAutoClient
        {
            private _DTE dte;
    
            public VSAutoClient(String strProgId)
            {
                try
                {
                    Type typeDTE = Type.GetTypeFromProgID(strProgId);
                    dte = (_DTE)Activator.CreateInstance(typeDTE);
                }
                catch (COMException ex)
                {
                    throw new VSAutoException("DTE creation failure:" + ex.ErrorCode);
                }
    
            }
    
            public _DTE DTE
            {
                get{return dte;}
            }
    
            public void MakeVisible(bool i_bVisible) 
            {
                dte.MainWindow.Visible = i_bVisible;
            }
    
            public void OpenSolution(string i_strSolution)
            {
                //DTE.Solution.Open(i_strSolution);
                Command("File.OpenProject", i_strSolution);
            }
    
            public void Command(string i_strCommand, string i_strArgs = "")
            {
                DTE.ExecuteCommand(i_strCommand, i_strArgs);
            }
    
            public void PrintOptions()
            {
                try
                {
                    Object[] prjActive = dte.ActiveSolutionProjects;
                    foreach (Project prj in prjActive)
                    {
                        try
                        {
                            VCProject vcp = prj.Object;
                            Configuration cfg = prj.ConfigurationManager.ActiveConfiguration;
                            VCConfiguration vccfg = null;
                            StringBuilder strInfo = new StringBuilder();
                            foreach (VCConfiguration c in vcp.Configurations)
                            {
                                string strCfg = cfg.ConfigurationName + "|" + cfg.PlatformName;
                                if (c.Name == strCfg)
                                {
                                    vccfg = c;
                                    break;
                                }
                            }
                            strInfo.Append("Project:");
                            strInfo.Append(vcp.Name + ":");
                            strInfo.Append(cfg.ConfigurationName + "|");
                            strInfo.Append(cfg.PlatformName);
                            Console.WriteLine(strInfo);
                            if (vccfg != null)
                            {
                                IVCCollection tools;
                                tools = vccfg.Platform.Tools;
                                VCCLCompilerTool comp = tools.Item("VCCLCompilerTool");
                                string strDbgInfo = comp.DebugInformationFormat.ToString();
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
    
            public void ShutDown()
            {
                dte.Quit();
            }
    
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                VSAutoClient vsa = null;
                string strProgId = "VisualStudio.DTE.9.0";
                string strSolution = "hello2010.sln";
                try
                {
                    if (args.Length >= 1)
                    {
                        strSolution = args[1];
                    }
                    vsa = new VSAutoClient(strProgId);
                    vsa.MakeVisible(true);
                    vsa.OpenSolution(strSolution);
                    vsa.PrintOptions();
                    
                }
                catch (VSAutoException ex)
                {
                    Console.Out.WriteLine(ex.Message);
                }
                catch (COMException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                if(vsa  != null)
                    vsa.ShutDown();
            }
        }
    }
    

    Thursday, June 6, 2013 9:05 PM
  • What version of VS is this? It looks (from the sln name) to be 2010, but you have above something about 2008

    Thursday, June 6, 2013 10:31 PM
  • It is built with VS2010, but I was running it on 2005, 2008 and 2010 with the same result. The original project has 3 versions (one for each supported VS). Each version imports from the appropriate VCProjectEngine. This sample has to be manually linked to the appropriate assembly before you run it. As I mentioned above, the ProgId string in the Main should be set appropriately. For example, when I run it on VS2008,  I import the 2008 VCProjectEngine and I set the strProgId = "VisualStudio.DTE.9.0". Of course, this is better done by reflection, but this is just a simple demo.

    Victor

    Thursday, June 6, 2013 11:06 PM
  • This is intriguing:

    Tried to put together a simple powershell script like this:

    try
    {
    	$dte=new-object -com VisualStudio.DTE.10.0
    	$dte.ExecuteCommand("File.OpenProject", "C:\vlh\test\cpp\hello\hello2010\hello2010.sln")
    	sleep 5
    	$sol=$dte.Solution
    	$proj=$sol.Projects
    	$p=$proj.Item(1).Object
    	$cfgs=$p.Configurations
    	$cfg=$cfgs.Item(1)
    	$tools=$cfg.Tools
    	$linker=$tools.Item("VCLinkerTool")
    	$compiler=$tools.Item("VCCLCompilerTool")
    	write-host Linker Options:
    	$linker
    	write-host Compiler Options
    	$compiler
    }
    catch
    {
    	write-host $error[0]
    }
    

    Essentially it is doing the same stuff as the C# code. But unlike C# or C++ code, it works. I wonder why...

    Friday, June 7, 2013 12:08 AM
  • Got it: Had to change one line of code.

    Instead of

    tools = vccfg.Platform.Tools;

    I wrote:

    tools = vccfg.Tools;

    Now everything works.

    I was fooled by this MSDN code sample

    http://msdn.microsoft.com/en-US/library/microsoft.visualstudio.vcprojectengine.vcplatform.tools(v=vs.80).aspx


    • Marked as answer by Victor Havin Friday, June 7, 2013 12:39 AM
    Friday, June 7, 2013 12:39 AM