Blog posts about troubleshooting

  • Entity Framework migration problem after merge

    December 10, 2014 | Tags: Troubleshooting, Entity Framework, C#

    A problem with code first migrations in Entity Framework arises when migrations in two branches are merged. Although you still have all the migrations in your merged project it still says "Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration."

    And if you create a new migration with the add-migration command you will end up with a migration that wants to add tables and/or fields that you already have in your database.

    Even if you do an update-database -targetmigration and try to re-run the migrations the error will remain.

    The cause of this problem is that each migration is created with a resource file (resx) that includes a snapshot of the database. This is what causes Entity Framework to be confused after the merge of two or more migrations.

    Solving the problem

    The fix is somewhat dirty but does the trick. You need to create a new migration that has the right snapshot but don't include the erroneous migrations.

    1. Add a new migration using add-migration
    2. Open the new migration and remove all the code from Up() and Down()
    3. Compile and run the project, it should be working again

    This empty migration will reset the snapshot and next time you change your data model the migrations will be created correctly.

    Be sure that you don't do any changes to your data model before you do this fix or otherwise make sure that you don't remove the valid migration steps.


  • HttpContext.Current not working in ASP.NET MVC

    December 09, 2014 | Tags: Troubleshooting, ASP.NET, MVC, C#

    This is most likely because it's no resolving to the correct class. Instead of using System.Web.HttpContext it tries to resolve towards System.Web.Mvc.Controller.HttpContext. The way to fix this is to prefix HttpContext.Current with System.Web so that your usage looks like: System.Web.HttpContext.Current


  • $(window).height() vs $(document).height()

    April 23, 2013 | Tags: Javascript, Troubleshooting, jQuery
    I was trying to use the $(window).height() method in jQuery to get the height of the browser window but was instead getting the document height in return (same as $(document).height()).

    So, what to do if window height returns document height instead?

    Solution

    The problem is most likely that your HTML document lacks a <!DOCTYPE>-definition. So the solution to the problem is to add a valid <!DOCTYPE> like <!DOCTYPE HTML> in the top of the HTML file. When done $(window).height() should start to report the proper window height and not the document's.



  • Preserve textformat when changing text in Flash / AS3

    April 09, 2013 | Tags: Actionscript, AS3, Troubleshooting, Flash, Snippet
    Notice that the textformat that was defined for your TextField mysteriously disappears when you just change the text? A bit annoying, but the reason is that the format is not applied to the TextField itself but the text in it. Replace the text and you replace the textformat as well.

    This can however be solved by storing away the textformat before you change the text and then re-apply it like this:

    // Save the old textformat before changing the text
    var textFormat:TextFormat = buttonText.getTextFormat();

    // Change the text
    buttonText.text = "New text goes here";

    // Re-apply the textformat
    buttonText.setTextFormat(textFormat);


  • Correct font names in TextFormat.font (AS3)

    April 03, 2013 | Tags: Actionscript, AS3, Troubleshooting, Flash
    If you want to use TextFormat in order to set which font family and style you wish to use on a component in your Flash project you just might be a bit puzzled on how to express both family and style in just one field - TextFormat.font.

    The problem

    If you plan to use the regular version of the font family ("Veto Com" in the sample, but could be "Arial", "Verdana" or the font of your choice), you'll just go with:
    import flash.text.TextFormat;

    var textFormat:TextFormat = new TextFormat();
    textFormat.font = "Veto Com";
    But if you want to use the Light style instead of Regular it's a bit trickier, because you need to know the font name including both family and style. Unfortunately there are no standards so it might differ between font sets.

    The solution

    There are two ways to get the correct font name:

    1. In Windows, locate the font file and open it to display the font information window. It will look something like this and the correct font name to use will be displayed in upper left corner:


    2. Add a textfield to your project and give it an instance name. Set both the Family and Style properties to the font you want. Then in code access the font property of the textfield and trace it using trace(myTextField.getTextFormat().font);
    Source for this solution: http://blog.erikphansen.com/actionscript-textformatfont-values/

    Enter the font name that you get from either of the methods above in your code:
    import flash.text.TextFormat;

    var textFormat:TextFormat = new TextFormat();
    textFormat.font = "Veto Com Light";