Monday Sep 07, 2009

Unit tests failing with 'Exception has been thrown by the target of an invocation'?

I encountered an interesting problem in Visual Studio this week:

  • Symptom:
    • VS2008 SP1 w/ Team Foundation Client
    • Unit tests in VS fail with 'Exception has been thrown by the target of an invocation'
    • Unit tests work at w/ mstest cmdline.
    • Team explorer shows Red X on Work Items folder.
    • using witexport cmdline fails with 'Value does not fall within the expected range.' message
    • Affects all solutions in problem TFS project for user on a computer.
    • Does not affect same user on other systems.
  • Resolution
    • Deleted registry key HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0 and allowed Visual Studio to rebuild settings on next load.  Something more surgical might have worked, but I was casting a wide net over different options.
    • Re-installing software or patches doesn't help...  The problem appeared to be in registry?

 At first, all I had was an austere error dialog preventing me from running any tests in Visual Studio: 'Exception has been thrown by the target of an invocation.' - no stack.  no details.  I managed to get a stack out of Visual Studio by attaching a debugger to it.  There must have been a better way. :S

System.Reflection.TargetInvocationException occurred
  Message="Exception has been thrown by the target of an invocation."
  Source="mscorlib"
  StackTrace:
       at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
       at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
  InnerException: System.ArgumentException
       Message="The Extender Provider failed to return an Extender for this object."
       Source=""
       StackTrace:
            at Microsoft.TeamFoundation.WorkItemTracking.Client.DataStore.HandleComException(Int32 hr)
            at Microsoft.TeamFoundation.WorkItemTracking.Client.DataStore.DatastoreClass.get_RootNode()
            at Microsoft.TeamFoundation.WorkItemTracking.Client.ProjectCollection..ctor(WorkItemStore store)
            at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore.get_Projects()
            at Microsoft.VisualStudio.TeamSystem.Integration.TeamFoundationHostHelper.GetWorkItemTypes(WorkItemStore store, String projectName)
            at Microsoft.VisualStudio.TeamSystem.Integration.TeamFoundationHostHelper.RefreshData(Boolean serverChanged, Boolean projectChanged, Boolean fireEvent)
            at Microsoft.VisualStudio.TeamSystem.Integration.TeamFoundationHostHelper.Initialize(Boolean getBuildInfo, Boolean getWorkItemTypes)
            at Microsoft.VisualStudio.TeamSystem.Integration.TeamFoundationHostHelper..ctor(IServiceProvider serviceProvider, Boolean getBuildInfo, Boolean getWorkItemTypes)
            at Microsoft.VisualStudio.TeamSystem.Integration.VsetServerHelper..ctor(IServiceProvider serviceProvider)
            at Microsoft.VisualStudio.TeamSystem.Integration.Client.VsetHelper.InitializeThrow(IServiceProvider serviceProvider)
            at Microsoft.VisualStudio.TeamSystem.Integration.Client.VsetHelper.InitializeHelper(IServiceProvider serviceProvider)
            at Microsoft.VisualStudio.TeamSystem.Integration.Client.VsetHelper.CreateVsetHelper(IServiceProvider serviceProvider)
            at Microsoft.VisualStudio.TestTools.TestCaseManagement.QualityToolsPackage.get_VsetHelper()
            at Microsoft.VisualStudio.TestTools.TestCaseManagement.ResultsToolWindow..ctor()
            at Microsoft.VisualStudio.TestTools.TestCaseManagement.ResultToolWindowHost..ctor()
       InnerException:

Comments:

Hello, I have run into this as wall and found that the solution for me was to open the Team Explorer windoe in VS and allow it to connect to the TFS server. Then when I run the unit tests I do not get the error.

Posted by Jeffrey Hastings on June 06, 2010 at 08:37 AM PDT #

Wow! Sad but true. Jeffrey Hastings' comment is right on. Just connect with Team Explorer and the error stops. My Solution didn't even have SC bindings and VS was still confused. Simple fix, though. Thanks Jeffrey!

Posted by Todd Girvin on June 07, 2010 at 12:51 PM PDT #

Hi,

Thanks Jeffrey and Ray! Solved my problem too!!

Posted by Håvard Eek on July 30, 2010 at 02:04 AM PDT #

Post a Comment:
  • HTML Syntax: Allowed