[英]Im getting exception Typeload what the exception can be?
我添加了3 dll的參考:Google.Apis,Google.Apis.Translate.v2,System.Runtime.Serialization
在Form1中我有一行:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Translator.translate(new TranslateInput());
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
現在錯誤異常位於類轉換器的第一行:拋出錯誤的行是: var service = new TranslateService { Key = GetApiKey() };
類代碼是:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Web;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using Google.Apis.Util;
using Google.Apis.Translate.v2;
using Google.Apis.Translate.v2.Data;
using TranslationsResource = Google.Apis.Translate.v2.Data.TranslationsResource;
public class Translator
{
public static string translate(TranslateInput input)
{
// Create the service.
var service = new TranslateService { Key = GetApiKey() };
string translationResult = "";
// Execute the first translation request.
Console.WriteLine("Translating to '" + input.TargetLanguage + "' ...");
TranslationsListResponse response = service.Translations.List(input.SourceText, input.TargetLanguage).Fetch();
var translations = new List<string>();
foreach (TranslationsResource translation in response.Translations)
{
translationResult = translation.TranslatedText;
}
return translationResult;
}
private static string GetApiKey()
{
return "AIzaSyCjxMe6RKHZzd7xSfSh2pEsBqUdXYm5tA8"; // Enter Your Key
}
}
/// <summary>
/// User input for this example.
/// </summary>
[Description("input")]
public class TranslateInput
{
[Description("text to translate")]
public string SourceText = "Who ate my candy?";
[Description("target language")]
public string TargetLanguage = "fr";
}
錯誤是:
無法從程序集“Google.Apis,Version = 1.1.4497.35846,Culture = neutral,PublicKeyToken = null”加載類型“Google.Apis.Discovery.FactoryParameterV1_0”。
試圖谷歌尋求幫助,並試圖將項目類型更改為x64平台,但它沒有幫助。 所以我把它放回x86
我有windows 7 64bit visual studio c#2010 pro .net 4.0 profile client。
無法弄清楚錯誤是什么?
上面發布的消息中報告的此錯誤是由於解決方案或項目的bin \\ Debug文件夾中的本地副本造成的。 即使您嘗試清理解決方案,此類副本仍將存在。
為了避免這種情況發生,您必須通過在項目屬性中添加引用路徑來強制Visual Studio引用正確的DLL。 遺憾的是,如果您的解決方案中有多個項目,則必須一個接一個地設置項目的參考路徑,直到完成為止。
如果您想知道如何設置參考路徑,請遵循以下簡單說明:
1.選擇您的項目,單擊鼠標右鍵,然后單擊“屬性”; 2.在項目屬性中,單擊“參考路徑”; 3.文件夾,鍵入或瀏覽到DLL的正確位置,單擊[添加文件夾]。
您需要為每個DLL可能具有的許多不同位置執行這些步驟。 考慮在相同項目屬性的“構建”選項卡下設置輸出路徑,以便您可以在每個目錄的同一目錄中輸出DLL,從而確保在同一位置找到所有最新版本,從而簡化了引用。
請注意,這只是導致此錯誤的一個原因。 但可以肯定的是,必須對所提到的組件的錯誤副本做一些事情。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.