Outbreak Labs

I can do anything I want to. And so can you.

MySQL Connector/Net for CoreCLR / DNXCore50

After several failed attempts, I have managed to strip down and modify the MySQL Connector/Net library enough to get it working on DNXCore50. I would strongly advise against using this in production, but it may work for testing purposes while waiting for an official release from Oracle. Here is the repo.

The following basic scenario works, which was my goal:

string connectionString = "server=127.0.0.1;userid=my_user;password=my_password;database=my_db;default command timeout=10;Connection Timeout=5;";

    using (var conn = new MySqlConnection(connectionString))
    {
        conn.Open();
        var cmd = new MySqlCommand(@"select col1, col2 from data where id = @id", conn);
        cmd.Parameters.AddWithValue("@id", "myId");
        var reader = cmd.ExecuteReader();

        string col1data;
        string col2data;

        if (reader.Read())
        {

            if (!reader.IsDBNull(0))
            {
                col1data = reader.GetString(0);
            }

            if (!reader.IsDBNull(1))
            {
                col2data = reader.GetString(1);
            }
        }
    }

Debugging AvalonDock 1.3 applications in Windows 8 and Windows 10

I recently upgraded from Windows 7 to Windows 10. Among the myriad problems I've run into, was the inability to run my Progression toolkit from within Visual Studio. Progression uses AvalonDock 1.3, which doesn't seem to get along with Windows 10 (or Windows 8, based on my research). Curiously, the program builds and can run outside of Visual Studio, but when run with the debugger, this exception is thrown:

Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll

Additional information: Could not load file or assembly 'AvalonDock.Aero2, Version=1.3.3600.0, Culture=neutral, PublicKeyToken=85a1e0ada7ec13e4' or one of its dependencies. The system cannot find the file specified.
This appears to be the result of Windows 10 loading a new Aero2 theme that AvalonDock was unprepared for. After spending a few minutes trying to cheat by copying the existing DLL to match the new name, I decided to take the approach of forcing my application to use the old Windows 7 Aero theme. The top results on StackOverflow, which involved adding a reference to the PresentationFramework.Aero dll and editing the resource XAML, did not solve my problem. Then I found an article appropriately named How to Actually Change the System Theme in WPF. The article is worth a read, but here's the solution, shamelessly copied:

public partial class App : Application
    {
        public App()
        {
            SetTheme("aero", "normalcolor");
        }

        /// 
        /// Sets the WPF system theme.
        /// 
        /// The name of the theme. (ie "aero")
        /// The name of the color. (ie "normalcolor")
        public static void SetTheme(string themeName, string themeColor)
        {
            const BindingFlags staticNonPublic = BindingFlags.Static | BindingFlags.NonPublic;

            var presentationFrameworkAsm = Assembly.GetAssembly(typeof(Window));

            var themeWrapper = presentationFrameworkAsm.GetType("MS.Win32.UxThemeWrapper");

            var isActiveField = themeWrapper.GetField("_isActive", staticNonPublic);
            var themeColorField = themeWrapper.GetField("_themeColor", staticNonPublic);
            var themeNameField = themeWrapper.GetField("_themeName", staticNonPublic);

            // Set this to true so WPF doesn't default to classic.
            isActiveField.SetValue(null, true);

            themeColorField.SetValue(null, themeColor);
            themeNameField.SetValue(null, themeName);
        }
    }
With that in place, the application no longer crashes when Visual Studio starts it.