Dec 22

How to get MySQL working with Microsoft .NET’s Entity Framework 6

  1. Download and install the latest MySQL .NET Connector.
  2. Add [MySQL.Data] and [MySql.Data.Entity for EF6] assembly references for your .NET Framework version (hover over the assembly to see its framework version in its .dll path).
  3. Use NuGet Package Manager to install Entity Framework.
  4. Modify Web.config’s section to MySQL values (this will avoid the “No Entity Framework provider found for the ADO.NET provider with invariant name ‘MySql.Data.MySqlClient’.” error):
      <defaultconnectionfactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6">
          <parameter value="v11.0"></parameter>
        <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"></provider>
  5. Add the following to Web.config’s section:
    <system .data>
        <remove invariant="MySql.Data.MySqlClient"></remove>
        <add name="MySQL Data Provider"
             description="Data Provider for MySQL"
             type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></add>
      <add name="Storage"
           connectionString="server=localhost; User Id=user; Password=password; Persist Security Info=True; database=db_name;"
  6. For migrations to work, add this to your migration Configuration class’ constructor:
    SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());
Oct 25

Mortality (beat poem, with MP3)

Lately I’ve grown increasingly fond of beat poems, and when I grow fond of something, I often try to emulate it (badly). so here’s my latest creative fart. Enjoy! :)

Download MP3

Modus Operandi – Mortality Lyrics

I liked this morning – it promised a great day
But as I was strolling briskly along my everyday way
Some random asshole stumbled in front of me trying to say
Something that I can only describe as a bay
I don’t have time for your bullcrap, your shitfaced stare
Showing plainly you can’t tell a brick from a bear
I have to go, gotta run, bye-bye, ciao
What? You want me to stay so you can talk to me now?
Dude, you could sleep on my car and I wouldn’t be half as incensed
As for the fact that you’re maiming my time into past tense

Some idiots insist that mortality’s great
It makes us appreciate life, and what’s on its plate
Without death we’d be permanently in a depressed state
‘Cause eternal life would be nothing but boredom without expiration date
Are you fucking kidding me? Is this some joke?
What kind of a sick fuck would actually want to choke?
Are you retarded? Are you mentally weak?
Do I have to point out what every kid knows, even before they can speak:
You have to be alive to feel anything, and guess what
That includes enjoyment of the very life you’re belittling!

How can you breathlessly talk about entropy
As if it’s a bounty and not the enemy
Knowing everything falls and eventually,
You too will perish soon without hope for recovery?

Your body breaks down over the course of time
You only get 24 hours a day, and that might seem fine
Until you subtract the sleep, food, washing and work
Then it turns out you’ve barely the time to form a coherent thought!
And as your body decays your brain follows suit
Until you can’t even put on your goddamn boots!
Diseases pile up, so the meds pile up too
Does any of this sound like motivation to you?
I say — fuck that, and if it does, then fuck you
If you love death so much, go and marry it, too
I might not have a choice in facing eternal pause
But when I die, it will be murder regardless of cause.

Aug 03

ExternalInterface callback exception handling in ActionScript 3

I had a problem. I needed to make sure exceptions (both manually thrown and unexpected run-time errors) thrown by my Flash/ActionScript 3 application were handled, silent failures were a complete no-no. At the first glance, this seems quite easy.

One way is to enclose your entire code in a try-catch block. It might seem unsightly if you have a lot of code, but becomes quite nice if you use a simple include:

try {
    include "";
catch (e:Error) {
    // Handle it.

Flash player 10.1 also introduced an event handler for this specific purpose. As far as I can tell, it does the exact same thing as the try-catch block, just in a more OOP fashion. You attach an UncaughtErrorEvent handler to the main movie object (through its loaderInfo property) and any unhandled exceptions will end up there:

loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, ErroHandler);

function ErrorHandler(event:UncaughtErrorEvent):void {
    // Handle it.

Which is all good and fine, but here’s the catch: this won’t work on ExternalInterface callbacks. Because the code exectued by an ExternalInterface callback is not run in the context of the main movie clip. This effectively puts it outside the try-catch block (which is defined within the main movie) and the event listener (which is attached to the main movie).

The only workaround I could find was to encase every external callback function in it’s own try-catch block, which then manually triggers the UncaughtErrorEvent of the main movie clip (through a static reference). Since my app has a lot of external calls (it interacts heavily with JavaScript of the page it’s on), I also added a wrapper function to reduce code and improve maintenance & readability. Here’s how it looks:

loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, ErroHandler);

function ErrorHandler(event:UncaughtErrorEvent):void {
    // Handle it.

ExternalInterface.addCallback("ChangeAngle", function(...$args) { ExternalCall(SwitchAngle, $args); } );
ExternalInterface.addCallback("AddText", function(...$args) { ExternalCall(NewTextAddon, $args); } );
ExternalInterface.addCallback("AddImage", function(...$args) { ExternalCall(NewImageAddon, $args); } );

function ExternalCall($function:Function, $args:Array=null):* {
    try {
        return $function.apply(null, $args);
    catch (e:Error) {
        GlobalInstances.MainMovie.dispatchEvent(new UncaughtErrorEvent("uncaughtError", true, true, e));

Hope this helps someone as stuck as I originally was. Or maybe someone can point out a better way of accomplishing this.