Mostafa Armandi
Mostafa Armandi

Reputation: 939

VSXI referenced assemblies not loaded properly

In my given VSIX I have referenced .netstandard's version of nuget package Microsoft.TeamFoundationServer.Client to get a list of Projects utilizing GetProjects() method of ProjectHttpClient class from Microsoft.TeamFoundation.Core.WebApi.dll assemly.
I get Method not found exception in runtime at the moment of method call.
It took me a long time to learn that, this is because a VSIX is loaded into devenv.exe App Domain which has already loaded the same referenced assembly with a different version (and different signature of GetProjects() method) from the following path:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer.

Some of things that I have done to make it work:

  1. Manually appending nuegt assembly using Assembly.LoadFrom to the list of loaded assemblies during VSIX's InitializeAsync method which didn't help.
  2. Trying to point runtime to use that nuget version, using assemblyIdentity, which turned out to be pointless since it is apparently gets ignored in VSIX packages.(link).
  3. Replace PackageReference with Assembly Reference pointing to that version of assembly, located in the aforementioned Team Explorer folder which solve the problem, but it makes my VSIX tightly bound to the target environment binary versions. which doesn't sounds a logical decision.

Upvotes: 0

Views: 139

Answers (1)

DevPreSupport_MSFT
DevPreSupport_MSFT

Reputation: 282

I can reproduce this issue on my local environment. Here is the detailed information: enter image description here

we can find there are 6 parameters in the function “GetProjects”. The type of last parameter is Boolean. I can also find the related method on the class "ProjectHttpClient"

    public virtual Task<IPagedList<TeamProjectReference>> GetProjects(ProjectState? stateFilter, int? top, int? skip, object userState, string continuationToken)
    {
        return GetProjects(stateFilter, top, skip, userState, continuationToken, null);
    }

   
    public virtual Task<IPagedList<TeamProjectReference>> GetProjects(ProjectState? stateFilter = null, int? top = null, int? skip = null, object userState = null, string continuationToken = null, **bool? getDefaultTeamImageUrl = null**)
    {
        List<KeyValuePair<string, string>> queryParams = new List<KeyValuePair<string, string>>();
        QueryParamHelper.AddNonNullParam(queryParams, "stateFilter", stateFilter);
        QueryParamHelper.AddNonNullParam(queryParams, "$top", top);
        QueryParamHelper.AddNonNullParam(queryParams, "$skip", skip);
        QueryParamHelper.AddNonNullParam(queryParams, "continuationToken", continuationToken);
        QueryParamHelper.AddNonNullParam(queryParams, "getDefaultTeamImageUrl", getDefaultTeamImageUrl);
        return GetProjectsAsync(queryParams, userState);
    }

However we cannot found the GetProjects method with 6 parameters in the official site: enter image description here

So I would suggest you change GetProjects method with 5 parameters:

 var test = projectClient.GetProjects(null,3,1,null,null).Result;

This is the test result:

enter image description here

Upvotes: 1

Related Questions