每次运行应用程序时,我都会得到这个异常。我不知道它是什么
XamlParseException未被处理。 “在与指定绑定约束匹配的类型'chrm.MainWindow‘上调用构造函数会引发异常。”行号'3‘和行位置'9’。
我的代码
GoogleChrome.cs
namespace chrm
{
class GoogleChrome
{
public List<URL> URLs = new List<URL>();
public IEnumerable<URL> GetHistory()
{
// Get Current Users App Data
string documentsFolder = Environment.GetFolderPath
(Environment.SpecialFolder.ApplicationData);
string[] tempstr = documentsFolder.Split('\\');
string tempstr1 = "";
documentsFolder += "\\Google\\Chrome\\User Data\\Default";
if (tempstr[tempstr.Length - 1] != "Local")
{
for (int i = 0; i < tempstr.Length - 1; i++)
{
tempstr1 += tempstr[i] + "\\";
}
documentsFolder = tempstr1 + "Local\\Google\\Chrome\\User Data\\Default";
}
// Check if directory exists
if (Directory.Exists(documentsFolder))
{
return ExtractUserHistory(documentsFolder);
}
return null;
}
IEnumerable<URL> ExtractUserHistory(string folder)
{
// Get User history info
DataTable historyDT = ExtractFromTable("urls", folder);
// Get visit Time/Data info
DataTable visitsDT = ExtractFromTable("visits",
folder);
// Loop each history entry
foreach (DataRow row in historyDT.Rows)
{
// Obtain URL and Title strings
string url = row["url"].ToString();
string title = row["title"].ToString();
// Create new Entry
URL u = new URL(url.Replace('\'', ' '),
title.Replace('\'', ' '),
"Google Chrome");
// Add entry to list
URLs.Add(u);
}
// Clear URL History
DeleteFromTable("urls", folder);
DeleteFromTable("visits", folder);
return URLs;
}
void DeleteFromTable(string table, string folder)
{
SQLiteConnection sql_con;
SQLiteCommand sql_cmd;
// FireFox database file
string dbPath = folder + "\\History";
// If file exists
if (File.Exists(dbPath))
{
// Data connection
sql_con = new SQLiteConnection("Data Source=" + dbPath +
";Version=3;New=False;Compress=True;");
// Open the Conn
sql_con.Open();
// Delete Query
string CommandText = "delete from " + table;
// Create command
sql_cmd = new SQLiteCommand(CommandText, sql_con);
sql_cmd.ExecuteNonQuery();
// Clean up
sql_con.Close();
}
}
DataTable ExtractFromTable(string table, string folder)
{
SQLiteConnection sql_con;
SQLiteCommand sql_cmd;
SQLiteDataAdapter DB;
DataTable DT = new DataTable();
// FireFox database file
string dbPath = folder + "\\History";
// If file exists
if (File.Exists(dbPath))
{
// Data connection
sql_con = new SQLiteConnection("Data Source=" + dbPath +
";Version=3;New=False;Compress=True;");
// Open the Connection
sql_con.Open();
sql_cmd = sql_con.CreateCommand();
// Select Query
string CommandText = "select * from " + table;
// Populate Data Table
DB = new SQLiteDataAdapter(CommandText, sql_con);
DB.Fill(DT);
// Clean up
sql_con.Close();
}
return DT;
}
}
}URL.cs
namespace chrm
{
class URL
{
string url;
string title;
string browser;
public URL(string url, string title, string browser)
{
this.url = url;
this.title = title;
this.browser = browser;
}
public string getData()
{
return browser + " - " + title + " - " + url;
}
}
}最后是Mainwindow.xaml.cs
namespace chrm
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
GoogleChrome ch = new GoogleChrome();
public MainWindow()
{
InitializeComponent();
ch.GetHistory();
}
}
}当我把调试放进cs文件..。在DataTable ExtractFromTable(string表,string文件夹)中看不到它。所以我只在主窗口中得到错误。
现在该怎么办?
好吧..。当我抓住例外的时候它给了我
System.IO.FileLoadException:混合模式程序集是针对运行时的版本“v2.0.50727”构建的,如果没有其他配置信息,则无法在4.0运行时中加载。\r\n在chrm.GoogleChrome.ExtractFromTable(字符串表,(字符串文件夹)\r\n在chrm.GoogleChrome.ExtractUserHistory(字符串文件夹)在D:\html5\chrm\chrm\GoogleChrome.cs:line中,45\r\n在chrm.GoogleChrome.GetHistory()在D:\html5\chrm\chrm\GoogleChrome.cs:line中,35\r\n在chrm.MainWindow..ctor()在D:\html5\chrm\chrm\MainWindow.xaml.cs:line 33中
是因为我使用的dll是v2.0 ..我的应用程序需要4.0?
发布于 2012-10-29 06:31:57
根据您的IOException,我确实会说这是一个错误,因为您正在.NET 4.0中编译,同时试图使用针对.NET 2.0构建的DLL
尝试将其添加到app.config文件的配置部分。如果需要的话,您可以在主应用程序或正在使用上述代码的DLL中尝试:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>https://stackoverflow.com/questions/13116602
复制相似问题