none
Upgrading a VS2005 Add-in to VS2008 (Failing to load)

    Question

  • I have an add-in I wrote for VS2005 and have used for about a year now. I tried today to port it to VS2008 but two separate issues are blocking progress and I can't easily diagnose a fix. I've googled around for a while, read what I could, searched here, but thus far no luck.

    The add-in uses two projects, one called VS2008_Addin (was VS2005_Addin) and the other called "Shared Classes". The latter compiles to a dll that is used by the former (and contains classes this addin shares with other software , i.e. wasn't written for this add-in in particular)

    It' all works fine on VS2005. Now poters to 2008 I refactored a lot of 2005 references to 2008 and followed some guidelines I found on-line for making the conversion. And when I try to debug the addin now I get two distinct problems/surprises. The first is this message:

    LoadFromContext was detected
    Message: The assembly     named 'Shared Classes' was loaded from 'file:///C:/Documents and Settings/berndw/My Documents/Visual Studio 2008/Projects/Myriax/TFS Tools/VS2008_AddIn/bin/Shared Classes.DLL' using the LoadFrom context. The use of this context can result in unexpected behavior for serialization, casting and dependency resolution. In almost all cases, it is recommended that the LoadFrom context be avoided. This can be done by installing assemblies in the Global Assembly Cache or in the ApplicationBase directory and using Assembly.Load when explicitly loading assemblies.

    I have researched to my hearts ocntent but cannot divine why htis should suddenly appear now and wasn't happening before. I can see that putting "Shared Classes.DLL" into the GAC is one workarounbd but that's not real suitable for debugging an add-in (I want to be using the lates build of the DLL) and I can see solutions that involve writing an XML .config file that directs probing apparently ... but I'm really not sure where to continue with diagnosis and fixing of this.

    I can click Continue however and the addin continues to load. I can see that it the Connect constructor is called, then I get abothe LoadFromContext error:

    LoadFromContext was detected
    Message: The assembly named 'Microsoft.VisualStudio.TeamFoundation' was loaded from 'file:///C:/Documents and Settings/berndw/My Documents/Visual Studio 2008/Projects/Myriax/TFS Tools/VS2008_AddIn/bin/Microsoft.VisualStudio.TeamFoundation.DLL' using the LoadFrom context. The use of this context can result in unexpected behavior for serialization, casting and dependency resolution. In almost all cases, it is recommended that the LoadFrom context be avoided. This can be done by installing assemblies in the Global Assembly Cache or in the ApplicationBase directory and using Assembly.Load when explicitly loading assemblies.

    this time on the TeamFoundation.DLL. I cna again continue, and then I just get a generic error:

    ---------------------------
    Microsoft Visual Studio
    ---------------------------
    The Add-in 'Myriax_Tools' failed to load or caused an exception.
    Would you like to remove this Add-in?
    If you choose yes, the file it was loaded from, 'C:\Documents and Settings\berndw\My Documents\Visual Studio 2008\Addins\VS2008_AddIn - For Testing.AddIn', will be renamed.

    Error Message: <Unknown Error>
    Error number: 8013141a
    ---------------------------
    Yes   No  
    ---------------------------

    How can I diagnose this? It's not really helpful ... if I single step the code in the Connect constructor I find that it all runs fine but that this intrappable exception is thrown when the Connect constructor has completed before the OnConnection event is invoked (which is the next point of entry into my code ordinarily). So there's an exception happening somewhere outside of my code and it's not sharing much useful information alas.

    Any clues to diagnose and/or fix both of the issues will be rewarded with copious amounts of gratitude.

    Cheers,

    Bernd.

    Project Manager, Manager of Support, Quality Assurance and Documentation
    Tuesday, November 25, 2008 5:06 AM

Answers

All replies

  •  HOWTO: Troubleshooting Visual Studio and Office add-ins

    And if you can provide the necessary source code and detailed steps to reproduce this issue, you can get better help, I believe.

    Thanks.
    Return to the source, learn the way!
    Tuesday, November 25, 2008 5:42 AM
  • Thanks for the pointe. I've explored this page but alas it's pretty broad and general and hasn't help any. The key zone on it states:

    2. The add-in crashes when loaded

    This can have several causes:

    • The add-in is registered but the actual path of the Dll does not match the path stated in the InProcServer32 value of the registry entry (Registry-based registration) or in the XML file (Visual Studio 2005 add-ins using XML-based registration). You can use the regedit.exe tool of Windows to discover if this is the problem for COM-addins.
    • The OnConnection, OnStartupComplete or some other method of the add-in called when it is loaded crashes. Ensure that you use exception handlers in each method of the Connect class.
    • You get <Unknown Error> (Error Number 80131522) in a Visual Studio 2005/2008 add-in that uses XML registration (.AddIn file). Likely the namespace and connect class that you have specified in the .AddIn file, <FullClassName> tag does not match the actual namespace and name of the Connect class in the source code.
    • You get "The system cannot find the file specified" (Error Number 80070002): the file pointed by the COM registration or by the <Assembly> tag of the .AddIn file (XML registration) can not be found.
    • You get "No such interface supported" (Error Number 80004002): a cause for this error is that the Connect class is not visible to COM, even for Visual Studio 2005/2008 add-ins that use XML registration and not COM-registration. This can happen if you removed the <Assembly: ComVisible(True)> attribute of the AssemblyInfo file, or you changed its value to False. While you can remove this attribute at assembly level, at least the Connect class should have it applied.
    whereas I'm getting an <Unknown Error> (Error Number 8013141a) which they don't list and the first point is ruled out (I've checked my XML registration file againand again and it points to the right file all right).

    None of which helps explain why "LoadFromContext was detected" is fired all of a sudden and whether or not that contributes (I can suppress it by turning exceptions breaks off for most things).

    Re: supplying code, hmmm, this isn't exatly the right forum, it's like bulky and there's lots of it and most of it of no consequence to loading the addin. The bit that is teh add-in skeleteon so to sepak is itself just derived form the satandard template and works fine on VS2005 - I cna't help but suspect a simple migration issues somewhere. The problem though is that it is hard to imagine it being in my code at all as I can't catch an exception in my code, it's happening some time after the Connect object is constructed and before the OnConnection event is fired (i.e. between my code segments) and my code is fundamentally that which you get when you create a new VS2008 add-in from the default templates (I have one of those loading, albeit with the toolbar I expect missing so further diagnostics there). It's more likely somewhere in the code metadat, project files or solution files.

    There in lies a possible clue. The solution file seems to map a pile of GUIDs to about the place. That rings an alarm bell because I changed all instances of VS2005_AddIn in my code (namespace I used, and some laebles I used) to VS2008_AddIn, but did nothing with GUIDs and if these GUIDS appear in the registry (as they do) mapped to the VS2005 implementation I may be causing a confusion. SO my latest thread is to look at how to get myself a pile of new GUIDs functionally (i.e. create a totally new solution (I cheated, I took and old V2005_AddIn.sln file renamed it to VS2006_AddIn.sln and replaced all instances inside of it and all project files and source files of VS2005 to VS2008). I suspect these GUIDs are the source of the problem ...

    Cheers,

    Bernd/

    Project Manager, Manager of Support, Quality Assurance and Documentation
    Tuesday, November 25, 2008 7:23 AM
  • O.K. I have made no progress with studying possible GUID conflicts so I embarked on the dreaded step by step bisection method. I have my AddIn which doesn't work, and I have a sample AddIn (the default template when you create a new VS2008 AddIn from the VS2008 File>New>Project menu, which does work. So let'sadd bits of my AddIn to the working project until it fails. Painstaking and slow with tests between each piecewise step until by bisecting the code space lets me hone right on in to the line that is to blame, and I have it.

    In the method OnConnection I follow the guidleines documented here:

    http://blogs.msdn.com/hippietim/archive/2006/03/29/563988.aspx

    and my method starts like this:

            private TeamFoundationServerExt _tfsext;                                        // The team foundation server extension object which provides context form the team explorer 
     
      
            public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)  
            {  
                try  
                {  
                    if (Debug) System.Windows.Forms.MessageBox.Show("Connecting with " + connectMode.ToString());  
                    _applicationObject = (DTE2)application;  
                    _addInInstance = (EnvDTE.AddIn)addInInst;  
                    _status = (EnvDTE.StatusBar)_applicationObject.StatusBar;  
                    _tfsext = _applicationObject.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as TeamFoundationServerExt;  
                    _connect = connectMode;  
                    _status.Text = "Connecting to my add-in ...";  
     
     


    Well, if I comment out this line:

                    _tfsext = _applicationObject.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as TeamFoundationServerExt;
     
    it runs and works. If I include this line then it crashes with:

    ---------------------------
    Microsoft Visual Studio
    ---------------------------
    The Add-in 'Myriax_Tools' failed to load or caused an exception.
    Would you like to remove this Add-in?
    If you choose yes, the file it was loaded from, 'C:\Documents and Settings\berndw\My Documents\Visual Studio 2008\Addins\VS2008_AddIn - For Testing.AddIn', will be renamed.

    Error Message: <Unknown Error>
    Error number: 8013141a
    ---------------------------
    Yes   No  
    ---------------------------

    If I put a breakpoint above this line and try to debug the breakpoint is never reached, the addin apparently fails to load before my code is ever kick started. So adding this line to the OnConnection method causes some bizarre failure prior to execution.

    What might that be and how might I diagnose it further?

    Frustrated,

    Bernd.



    Project Manager, Manager of Support, Quality Assurance and Documentation
    Thursday, November 27, 2008 5:01 AM
  • This was of course a vital clue and at last I have the AddIn building and loading. It's not functional yet, more issues to resolve, but the failure to load was fixed through one simple realisation! That line I needed to comment out referred to an object in the VS2005 SDK. So I installed the VS2008 SDK and updated all the references to use the newly installed DLLs and voila the AddIn now loads and runs ...

    Now at last I can start debugging some of the remaining issues a smy code is finally being executed and I will be able to debug it ...

    Morela of the story htus far, is that the upgrade guides didn't help me from making a fairly obvious mistake and not upgrading to the VS2008 SDK ... red faced.

    Project Manager, Manager of Support, Quality Assurance and Documentation
    Thursday, November 27, 2008 6:05 AM
  • Hi Bernd,

    If your OnConnection method that you posted is the one that you are actually using is wrong because it does the same whatever connectMode is passed.

    See:

    The OnConnection method and ext_ConnectMode.ext_cm_UISetup of Visual Studio add-ins
    http://msmvps.com/blogs/carlosq/archive/2008/10/13/the-onconnection-method-and-ext-connectmode-ext-cm-uisetup-of-visual-studio-add-ins.aspx

    and

    HOWTO: Use correctly the OnConnection method of a Visual Studio add-in
    http://www.mztools.com/resources_vsnet_addins.aspx

    and

    HOWTO: Adding buttons, commandbars and toolbars to Visual Studio .NET from an add-in
    http://www.mztools.com/resources_vsnet_addins.aspx

    That said, even with that problem fixed wouldn't have helped to diagnose your problem. If when Visual Studio loads your add-in it doesn't find its DLL or some of its references DLLs it gives an untrappable error (because the add-in couldn't be loaded) with number 80070002 but it could be some other problem like strong name validation failed which seems to be the error 8013141a. I will fix the troubleshooting article to reflect this.



    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com
    Thursday, November 27, 2008 1:40 PM
  • Carlos,

    Thanks for that. Yes, I know I'm not checking the ConnectMode in the code above, but as you observe in your articles this is a very poorly designed part of the paradigm and hellishly confusing to manage so in the VS2005 implementation I took a sledge hammer approach and combine sensitivity to ConnectMode with explicit checks for the existence of the UI elements I expect to be there on any run recreating them if they're not there ... this includes the commands themselves, the submenu I put them on, and buttons on tha submenu and the toolbar I put them on and the buttons on that toolbar.

    What I'm struggling to diagnose now is why, two strange behaviours exist after the port. These are not visible in my VS2005 implementation and are in the VS2008 (which differes fundamentally only in that I use the VS2008 SDK references).

    1) The buttons on my submenu just aren't there
    2) The buttons on the toolbar are disabled

    I enable them explicitly and step though the code for this but they stay disabled. Bizarre. They are disabled at first (probably) and then enabled later (probably) in both instances the Enabled property on the CommandBarButton is true of TeamFoundationServerExt reports an active project context and false otherwise (as my commands need access to the active team project). But stepping through the code this is true when I display teh team explorer and the Enabled flags are set to true, but in the VS2005 version this works and in the VS2008 version it doesn't they stay disabled (or missing in the case of the submenuy command buttons).

    Any thoughts that help will be appreciated, in the mean time I continue to debug it and research options, again working up form the simplest of tepmplate AddIn's which can succesfully do this and building up ... all bothersomely time consuming for a simple port.

    Cheers,

    Bernd.

    Project Manager, Manager of Support, Quality Assurance and Documentation
    Friday, November 28, 2008 2:06 AM
  • Could you open a new thread for this unrelated question(s)? Read the guidelines at:

    How to ask questions to increase your chances of an answer
    http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/9307ca0b-d152-4c31-85f5-05b6166d7410

    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com
    Friday, November 28, 2008 8:59 AM
  • Thanks I will. I'll try some diagnostics my end first and if (when) I get really frustrated and stuck, I'll fork another thread with that question. I'm working on a bisection method to bring a working example and my code together till I find which bit causes failure when ...

    Cheers,

    Bernd.

    Project Manager, Manager of Support, Quality Assurance and Documentation
    Sunday, November 30, 2008 6:32 AM
  • Finally, by bisection found the issue and got it to work. In porting it I had overlooked the QueryStatus method and that because I'd changed the name of the addin to wasn't enabling my commands. What made this awe-inspiringly difficult to find at my end was that the consequence of not enabling means that its toolbar button is disabled (greyed) and its menu item is not rendered at all! So I was getting an empty submenu. This inconsistent behaviour had me suspecting a change in the way submenus are populated and something mechanistic about getting my commands on that submenu, and I wasn't thinking enabled/disabled. Sheesh. Cost me some time that did. I now use a sledge hammer QueryStatus that just returns

    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;

    all the time regardless. Saves me some hassle and I have no interest in enabling or disabling commands this way currently. When I do, I'll revisit it.

    Cheers,

    Bernd.

    Project Manager, Manager of Support, Quality Assurance and Documentation
    Monday, December 01, 2008 10:50 PM