每次运行应用程序时都会遇到此异常。我不知道是什么
XamlParseException 未处理。
'调用与指定绑定约束匹配的'chrm.MainWindow'类型的构造函数引发异常。行号“3”和行位置“9”。
我的代码
谷歌浏览器.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;
}
}
}
网址.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(字符串表,字符串文件夹)中。所以我只在主窗口中得到错误。
现在做什么?
好的..当我捕捉到它给我的异常时
System.IO.FileLoadException:混合模式程序集是针对运行时版本“v2.0.50727”构建的,如果没有其他配置信息,则无法在 4.0 运行时中加载。\r\n at chrm.GoogleChrome.ExtractFromTable(String table, String folder )\r\n 在 D:\html5\chrm\chrm\GoogleChrome.cs:line 45\r\n 在 chrm.GoogleChrome.ExtractUserHistory(String folder) 在 D:\html5\chrm \chrm\GoogleChrome.cs:line 35\r\n at chrm.MainWindow..ctor() in D:\html5\chrm\chrm\MainWindow.xaml.cs:line 33
是因为我使用的 dll 是 v2.0 .. 我的应用程序需要 4.0 吗?