我試圖編寫一個應用程序與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的工作就像一個魅力。謝謝 –