locked
"Find All References" programatically RRS feed

  • Question

  • I am trying to implement "Find All References" programatically. I have gone through multiple forums and was successfully able to get it working (partially) as provided at http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2438477&SiteID=1. The single problem still remains is that I am not able to fetch the results back in some data structure. My IVsObjectSearch.Find always return me "out IVsObjectList" parameter as null. However I still see the search results displayed in Search Results dialog.

    Can someone able to provide assistance on what I am doing wrong. Here is the code snippet (in Package implementation):

     

    IVsObjectSearch search = GetService(typeof(SVsObjectSearch)) as IVsObjectSearch;

    IVsObjectList ob;

    VSOBSEARCHCRITERIA c = new VSOBSEARCHCRITERIA();

    c.szName = "ObjectNameToSearch";

    c.eSrchType = VSOBSEARCHTYPE.SO_ENTIREWORD;

    c.grfOptions = (uint)_VSOBSEARCHOPTIONS.VSOBSO_CASESENSITIVE;

    VSOBSEARCHCRITERIA[] carr = new VSOBSEARCHCRITERIA[] { c };

    int retval = search.Find((uint)__VSOBSEARCHFLAGS.VSOSF_EXPANDREFS, carr, out ob);

     

    I always get ob as null and no exception is thrown.

     

    -Neeraj

    Sunday, April 20, 2008 10:30 AM

Answers

  • What's the version of Visual Studio you're talking about?

    Could you please send a sample project and repro steps in details to my email address which can be found in my personal profile page?


    Tuesday, April 22, 2008 6:37 AM
  • I received your project and cannot open and run it in Visual Studio since it was written using a out-of-date version of visual studio. So I modified the csproj file to run it under latest version of VSSDK and I reproduced this issue.

    Like amadeus1eu in that thread mentioned, you will always get an InvalidCastException in that method. Sounds like an issue with the implementation of the interface.

    You may also submit this issue to the following site in the formal way:

    http://connect.microsoft.com/VisualStudio/


    After you submit it, I'd appreciate if you post the feedback address so that it can be found by community members having the similar issue.

    Thanks for your valuable feedback!
    Wednesday, April 23, 2008 4:09 AM
  • I have posted the bug at http://connect.microsoft.com/VisualStudio/.
    The feedback link is https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=339611

    BTW Is there any workaround for this? Can I get the search results by any others means?
    Wednesday, April 23, 2008 5:05 PM

All replies

  • Any comment on this? Can someone help me to understand what is done wrong here because of which I am getting null for IVsObjectList? Is there any other way to achieve the same?

    Monday, April 21, 2008 4:47 PM
  • What's the version of Visual Studio you're talking about?

    Could you please send a sample project and repro steps in details to my email address which can be found in my personal profile page?


    Tuesday, April 22, 2008 6:37 AM
  • Hi Feng,

     

    I am using Visual Studio 2005 and the SDK I have installed is VS SDK October 2005. The code is exactly what is there in the post. I debug the given project (using Visual Studio SDK in experimental hive). This will open a new instance of Visual Studio wherein I open some existing project and click on Tools->1 FindAll (which is created byu the package implementation).

    For your reference I am sending the entire project also by mail.

     

    Thanks

     

    Tuesday, April 22, 2008 3:35 PM
  • I received your project and cannot open and run it in Visual Studio since it was written using a out-of-date version of visual studio. So I modified the csproj file to run it under latest version of VSSDK and I reproduced this issue.

    Like amadeus1eu in that thread mentioned, you will always get an InvalidCastException in that method. Sounds like an issue with the implementation of the interface.

    You may also submit this issue to the following site in the formal way:

    http://connect.microsoft.com/VisualStudio/


    After you submit it, I'd appreciate if you post the feedback address so that it can be found by community members having the similar issue.

    Thanks for your valuable feedback!
    Wednesday, April 23, 2008 4:09 AM
  • I have posted the bug at http://connect.microsoft.com/VisualStudio/.
    The feedback link is https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=339611

    BTW Is there any workaround for this? Can I get the search results by any others means?
    Wednesday, April 23, 2008 5:05 PM
  • Since you have post the feedback in our connect site, our developers will directly contact you. And  I believe they can give you a good solution.

    Thanks again for your understanding!
    Thursday, April 24, 2008 12:00 AM
  • Hi everyone.

    I'm quite interested in this thread since I too need to find all references to items during runtime.

    NeerajAg,
    could you please tell me what is the state of your issue?

    And question to everyone - I've tried to work out current thread and this one http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2438477&SiteID=1 and I've some problems in calling services -

    IVsOutputWindow output = Package.GetGlobalService(typeof(IVsOutputWindow)) as IVsOutputWindow;
    and
    IVsObjectSearch search = Package.GetGlobalService( typeof( SVsObjectSearch ) ) as IVsObjectSearch;

    both return null references. That's quite bad. Both these calls are executed in Connect.TestFunc() method. Can anyone tell what to do to get normal result from Package.
    GetGlobalService() ?


    added:

    Well, for now I got the instance of IVsObjectSearch.

    But it still returns null for IVsObjectList. (I got VS SDK version 4.0 (downloaded yeaterday).)
    Monday, May 5, 2008 3:27 PM