Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# “XamlParseException未处理”_C#_.net_Wpf - Fatal编程技术网

C# “XamlParseException未处理”

C# “XamlParseException未处理”,c#,.net,wpf,C#,.net,Wpf,每次运行应用程序时都会出现此异常。我不知道这是什么 未处理XamlParseException '对类型'chrm.MainWindow'的构造函数的调用,该类型与指定的 绑定约束引发异常。“行号“3”和行位置“9” 我的代码 GoogleChrome.cs namespace chrm { class GoogleChrome { public List<URL> URLs = new List<URL>(); public IEnumerable<

每次运行应用程序时都会出现此异常。我不知道这是什么

未处理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;
    }
}
}
最后是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文件中时。。我在DataTableExtractFromTableString表、string文件夹中看到它没有运行。所以我只在主窗口中得到错误

现在该怎么办

好的。。当我捕捉到异常时,它会给我

System.IO.FileLoadException:混合模式程序集是根据运行时版本“v2.0.50727”生成的,如果没有其他配置信息,无法在4.0运行时中加载。\r\n在chrm.GoogleChrome.ExtractFromTableString表中,字符串文件夹\r\n位于chrm.GoogleChrome.ExtractUserHistoryString文件夹中的D:\html5\chrm\chrm\GoogleChrome.cs:chrm.GoogleChrome.GetHistory中的第45行\r\n位于D:\html5\chrm\chrm\GoogleChrome.cs:chrm.MainWindow中的第35行\r\n..位于D:\html5\chrm\chrm\chrm\MainWindow.xaml.cs:33行

是因为我使用的dll是v2.0吗。。我的应用程序需要4.0?

根据您的IOException,我确实认为这是一个错误,因为您在尝试使用基于.NET 2.0构建的DLL时,正在.NET 4.0中编译

尝试在app.config文件的“配置”部分添加此选项。如果需要,您可以在主应用程序或使用上述代码段的DLL中进行尝试:

<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
</startup>

似乎您的主窗口Xaml不正确。调试代码以查看代码流是否进入ch.GetHistory?如果确实是Xaml问题,那么在InitializeComponent处会出现异常。
<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
</startup>