2011-03-11 119 views
2

嗨,我想提出一個應用程序,可以提交一個YouTube視頻的評論。我正在使用.net框架4.0。c#youtube api error

當我點擊一個按鈕它吐出這個錯誤

無法加載文件或程序集「Google.GData.Client,版本= 1.7.0.1,文化=中性公鑰= 04a59ca9b0273830」或之一它的依賴關係。定位的程序集清單定義與程序集引用不匹配。 (異常來自HRESULT:0x80131040)

我使用的代碼如下

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Text.RegularExpressions; 
using System.Windows.Forms; 
using System.IO; 
using System.Web; 
using System.Net; 
using HtmlAgilityPack; 
using System.Xml; 
using Google.GData.Client; 
using Google.GData.Extensions; 
using Google.GData.YouTube; 
using Google.GData.Extensions.MediaRss; 
using Google.YouTube; 

的代碼的其餘部分是

string developerKey; 
string username; 
string password; 

developerKey = "mykey"; 
username = "my username"; 
password = "my pass"; 

    YouTubeRequestSettings settings = new YouTubeRequestSettings("youtube app", developerKey, username, password); 
      YouTubeRequest request = new YouTubeRequest(settings); 

      Uri videoEntryUrl = new Uri("my vid"); 
      Video video = request.Retrieve<Video>(videoEntryUrl); 

      Comment c = new Comment(); 
      c.Content = "This is my comment from my app"; 
      request.AddComment(video, c); 

回答

2

你缺少程序集。編譯應用程序時,您必須已將其作爲參考,但它不在您正在測試的位置。

因此,它與您的代碼無關,但您的構建和部署過程—即shell腳本,NAnt,VS.

一個典型的YouTube客戶端將在EXE(或DLL)的同一目錄中具有以下DLL。

Google.GData.Client.dll 
Google.GData.Extensions.dll 
Google.GData.YouTube.dll 

如果不是,那麼他們需要安裝在GAC中,或者使用.NET的程序集綁定配置進行定位。可能你想要第一個選擇,但是。

+0

該dll文件與.exe文件位於同一文件夾內,並且它仍然出現錯誤。什麼是GAC? – mintuz 2011-03-11 19:12:11

+0

你必須有兩個不同的版本。嘗試用EXING文件夾中的那些文件替換編譯中的文件夾。 – harpo 2011-03-11 19:16:28

+0

仍然沒有運氣:( – mintuz 2011-03-11 19:18:55