我试图编写一个应用程序与Visual Studio Team Services进行通信,使用列出的Nuget软件包here。Visual Studio团队服务API示例抛出System.Net.Http错误
示例代码直接来自微软官方文档,在“使用模式”下列出的软件包的同一页面上。我的测试代码位于控制台应用程序中,设置为.net框架的4.7版(由Visual Studio 2017 15.2(26430.16)发布编译,但我认为不重要)。该代码与微软的例子相同,除了更改连接url,项目和repo名称。
直接安装的唯一Nuget包(约30个作为依赖项安装)是Microsoft.TeamFoundationServer.ExtendedClient
。
安装,包装Microsoft.TeamFoundationServer.ExtendedClient
using System;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.Client;
using Microsoft.TeamFoundation.SourceControl.WebApi;
using Microsoft.VisualStudio.Services.WebApi;
namespace vssApiTest
{
class Program
{
const String c_collectionUri = "https://[[redacted]].visualstudio.com/DefaultCollection";
const String c_projectName = "Inspections";
const String c_repoName = "Src";
static void Main(string[] args)
{
// Interactively ask the user for credentials, caching them so the user isn't constantly prompted
VssCredentials creds = new VssClientCredentials();
creds.Storage = new VssClientCredentialStorage();
// Connect to VSTS
VssConnection connection = new VssConnection(new Uri(c_collectionUri), creds);
// Get a GitHttpClient to talk to the Git endpoints
GitHttpClient gitClient = connection.GetClient<GitHttpClient>();
// Get data about a specific repository
var repo = gitClient.GetRepositoryAsync(c_projectName, c_repoName).Result;
}
}
}
上线VssConnection connection = new VssConnection(new Uri(c_collectionUri), creds);
,一个TypeLoadException
被抛出(在运行时)与消息:
继承安全违反类型的规则: 'System.Net.Http.WebRequestHandler'。派生类型必须匹配 基类型的安全可访问性或不易访问。
我试过这个错误消息的Google搜索变体没有返回任何有用的东西。
我做错了什么,是我跟随错误的示例代码,还是有一些其他问题呢?
4.3.2和4.3.3的工作就像一个魅力。谢谢 –