Sunday, June 18, 2017

A Nice 5 Column Bootstrap Layout If You Need It

I am adding this here because someone else might find this useful.
I needed a 5 column layout for Bootstrap.
Here it is what I am using. Feel free to use it if you need it.


The CSS -

    <style>
        @@media (min-width: 992px) {
            .col-md-1-5 {
                width: 20%;
            }
            .col-md-2-5 {
                width: 40%;
            }
            .col-md-3-5 {
                width: 60%;
            }
            .col-md-4-5 {
                width: 80%;
            }
            .col-md-5-5 {
                width: 100%;
            }
        }
        @@media (min-width: 1200px) {
            .col-lg-1-5 {
                width: 20%;
            }
            .col-lg-2-5 {
                width: 40%;
            }
            .col-lg-3-5 {
                width: 60%;
            }
            .col-lg-4-5 {
                width: 80%;
            }
            .col-lg-5-5 {
                width: 100%;
            }
        }
        /* This part is only needed so you can see how the various grid possibilities - this is not needed  */
        .show-grid [class^=col-] span,
        .container-fluid .show-grid [class^=col-] {
            display: block;
            padding-top: 10px;
            padding-bottom: 10px;
            background-color: #eee;
            background-color: rgba(86,61,124,.15);
            text-align: center;
            border: 1px solid #ddd;
            border: 1px solid rgba(86,61,124,.2);
        }
        [class^=col-] {
            margin-bottom: 30px;
        }
    </style>

The HTML -


<div class="container">
    <div class="page-header">
        <h1>Bootstrap Grid (5 columns)</h1>
    </div>
    <h2>Boxed grid</h2>
    <div class="row show-grid">
        <div class="col-sm-6 col-md-1-5 col-lg-2-5">
            <span>sm-6 md-1-5 lg-2-5</span>
        </div>
        <div class="col-sm-6 col-md-1-5 col-lg-2-5">
            <span>sm-6 md-1-5 lg-2-5</span>
        </div>
        <div class="col-sm-6 col-md-1-5 col-lg-1-5">
            <span>sm-6 md-1-5 lg-1-5</span>
        </div>
        <div class="col-sm-6 col-md-1-5 col-lg-3-5">
            <span>sm-6 md-1-5 lg-3-5</span>
        </div>
        <div class="col-sm-6 col-md-1-5 col-lg-1-5">
            <span>sm-6 md-1-5 lg-1-5</span>
        </div>
        <div class="col-sm-6 col-md-2-5 col-lg-1-5">
            <span>sm-6 md-2-5 lg-1-5</span>
        </div>
        <div class="col-sm-6 col-md-3-5 col-lg-2-5">
            <span>sm-6 md-3-5 lg-2-5</span>
        </div>
        <div class="col-sm-6 col-md-1-5 col-lg-3-5">
            <span>sm-6 md-1-5 lg-3-5</span>
        </div>
        <div class="col-sm-6 col-md-4-5 col-lg-1-5">
            <span>sm-6 md-4-5 lg-1-5</span>
        </div>
        <div class="col-sm-6 col-md-5-5 col-lg-1-5">
            <span>sm-6 md-5-5 lg-1-5</span>
        </div>
        <div class="col-sm-6 col-md-3-5 col-lg-1-5">
            <span>sm-6 md-3-5 lg-1-5</span>
        </div>
        <div class="col-sm-6 col-md-2-5 col-lg-1-5">
            <span>sm-6 md-2-5 lg-1-5</span>
        </div>
        <div class="col-sm-6 col-md-4-5 col-lg-1-5">
            <span>sm-6 md-4-5 lg-1-5</span>
        </div>
    </div>
    <h2>Full-width grid</h2>
</div>
<div class="container-fluid">
    <div class="row show-grid">
        <div class="col-sm-6 col-md-1-5 col-lg-2-5">
            <span>sm-6 md-1-5 lg-2-5</span>
        </div>
        <div class="col-sm-6 col-md-1-5 col-lg-2-5">
            <span>sm-6 md-1-5 lg-2-5</span>
        </div>
        <div class="col-sm-6 col-md-1-5 col-lg-1-5">
            <span>sm-6 md-1-5 lg-1-5</span>
        </div>
        <div class="col-sm-6 col-md-1-5 col-lg-3-5">
            <span>sm-6 md-1-5 lg-3-5</span>
        </div>
        <div class="col-sm-6 col-md-1-5 col-lg-1-5">
            <span>sm-6 md-1-5 lg-1-5</span>
        </div>
        <div class="col-sm-6 col-md-2-5 col-lg-1-5">
            <span>sm-6 md-2-5 lg-1-5</span>
        </div>
        <div class="col-sm-6 col-md-3-5 col-lg-2-5">
            <span>sm-6 md-3-5 lg-2-5</span>
        </div>
        <div class="col-sm-6 col-md-1-5 col-lg-3-5">
            <span>sm-6 md-1-5 lg-3-5</span>
        </div>
        <div class="col-sm-6 col-md-4-5 col-lg-1-5">
            <span>sm-6 md-4-5 lg-1-5</span>
        </div>
        <div class="col-sm-6 col-md-5-5 col-lg-1-5">
            <span>sm-6 md-5-5 lg-1-5</span>
        </div>
        <div class="col-sm-6 col-md-3-5 col-lg-1-5">
            <span>sm-6 md-3-5 lg-1-5</span>
        </div>
        <div class="col-sm-6 col-md-2-5 col-lg-1-5">
            <span>sm-6 md-2-5 lg-1-5</span>
        </div>
        <div class="col-sm-6 col-md-4-5 col-lg-1-5">
            <span>sm-6 md-4-5 lg-1-5</span>
        </div>
    </div>
</div>

Please make note of the @@ I am using in the style section. I am only doing that because I am adding the code here in the <style> tag. You don't need this if you are using the CSS in an external stylesheet.

To use this, create your page in whatever language/framework you use.
Copy and paste the CSS listed above between the <head> and </head> section in your code or in an external stylesheet.
Copy and paste the html section between the <body> and </body> section in your code.
Run your code and you should now see a page with examples of the 5 column layout.

Enjoy!

PLEASE NOTE - This Bootstrap layout requires Bootstrap :-)! This layout is Bootstrap 3.0 friendly.

Smooches,
Kila Morton

Wednesday, June 7, 2017

How To Solve "Missing Name After . Operator" When Using YUI Compressor.Net And EcmaScript.Net


I have been working with a few projects I created that utilize YUI Compressor.Net. I am using this library instead of the native Asp.Net bundling and minification elements because I have found that the .Net libraries mangle css and js in certain cases. I decided to use YUI Compressor.Net after doing some testing with it and discovering that it took care of several of the issues I was having.

The only issue with this .Net port of the very popular YUI Compressor project is that the project itself is old. It worked right out of the box, but it is old. When you look at the project information on Nuget, the project was last updated by the original developer in September of 2014 (the "current" version is 2.7.0). The great thing is, as is the case with a lot of projects created out of need, this project has recent contributions from people who use it currently and update it for their needs and, altruistically, share their changes with the rest of us.

You can take a look at the project on Nuget here -
You can take a look at the project code on Github here -
  • https://github.com/YUICompressor-NET/YUICompressor.NET
You can take a look at the EcmaScript project, which is also a port over to .Net, here -

HOW DID I GET THE ERROR

I was using this project when I decided to change the version of JQuery from 1.x to JQuery 2.2.4. After doing this and rebuilding, I started to get an error when the system tried to create my bundles. The error can be seen below.

WHAT WAS THE ERROR


missing name after . operator

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: EcmaScript.NET.EcmaScriptRuntimeException: missing name after . operator

The image above has been altered to just show the error and part of the stack trace.

HOW TO SOLVE THE ISSUE


Since there is almost nothing new under the sun and this project is old, I figured that someone else might have had this issue. A quick search uncovered the EcmaScript.Net GitHub project and an issue filed by a developer who had the exact same problem. It turns out that this error is happening because of how the EcmaScript project is handling reserved keywords in scripts. This issue became a problem when I switched to a newer version of JQuery that used some keywords EcmaScript didn't like. You can read about the error by clicking here.

The truth is that the developer who found this issue already created a fix for it and did a commit in GitHub of the fix. However, after pulling down the code, you will find that the original developer has not merged the changes into the codebase. Here is what you need to do to solve this error and get on with your bundling/minifying life.

  1. Download the EcmaScript.Net project from Github here - https://github.com/PureKrome/EcmaScript.NET
  2. Open the project in Visual Studio and find the following two files - EcmaScript.NET/Parser.cs and EcmaScript.NET/TokenStream.cs. 
  3. Copy the code from the GitHub commit for TokenStream.cs into the TokenStream.cs file located in your local EcmaScript.Net project. Please note that I have made the letters TokenStream.cs into an actual link to the exact file. Just click on that and it will open in another window and then you can copy the code out of that file and paste it into your local project.
  4. Copy the code from the GitHub commit for Parser.cs into the Parser.cs file located in your local EcmaScript.Net project. Please note that I have made the letters Parser.cs into an actual link to the exact file. Just click on that and it will open in another window and then you can copy the code out of that file and paste it into your local project.
  5. After you have changed those two files, you are going to save and build your EcmaScript.Net project locally using a release build (or a debug build if that is your preference). 
  6. Look at the Output window after the build to see where the dll for the EcmaScript.Net project is located. 
  7. Copy the location of the dll from the Output window to your clipboard. It will be the location listed at the bottom of the Output window ending in EcmaScript.dll.
  8. Go to the Visual Studio project you are using with YuiCompressor.Net. Open the References folder and find & delete the EcmaScript.Net.dll.
  9. Right click on the Reference folder and select Add Reference. Click Browse and the paste the location you copied in step 7 into the textbox and then click Add and then OK. This will add the dll to your current project. You can go back to the references list and look to see that the dll is now listed there again.
  10. Now clean and rebuild your project.
  11. Run your project in Release mode so the bundler will work and VOILA - see the bundled magic in all of its glory! 
You should now be able to get your bundles correctly without any other issues.

Just in case you don't feel like doing all of that, I have included the EcmaScript.Net dll I created for my project in this blog post. Feel free to take it and replace the broken one you have in your project.

Get the EcmaScript.Net dll I created by clicking on this sentence! That link will allow you to download the dll from my Google Drive account. Have fun!

Smooches!
Kila Morton



Sunday, November 6, 2016

How To Change The Names Of The Aspnetuser Tables And How To Stop The Asp.Net Identity Service From Continuing To Create The AspNetUsers Table After Changing The TableNames

I came across something while using the latest version of Asp.Net Identity that will likely save someone out there some time. It was a simple thing, but might not be readily apparent.


By default, when you use the AspNet Identity service, it creates the following set of tables:
  • dbo.AspNetRoles
  • dbo.AspNetUserClaims
  • dbo.AspNetUserLogins
  • dbo.AspNetUserRoles
  • dbo.AspNetUsers
The default schema is dbo and the table names are the default names created by the AspNet Identity service.

To change the default schema, you can do one of a couple of things.
You can add the schema to the OnModelCreating method like so:

  protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
   {
      base.OnModelCreating(modelBuilder);
           
      //your default schema would be a string of your choosing
      modelBuilder.HasDefaultSchema("YourDefaultSchemaHere");
   }

or you can change the schema as you rename the table in the OnModelCreating method

   modelBuilder.Entity<IdentityUser>().ToTable("Users", "YourDefaultSchemaHere");
 

Either of these methods change your tables to:


  • YourDefaultSchemaHere.AspNetRoles
  • YourDefaultSchemaHere.AspNetUserClaims
  • YourDefaultSchemaHere.AspNetUserLogins
  • YourDefaultSchemaHere.AspNetUserRoles
  • YourDefaultSchemaHere.AspNetUsers

  • If you want to change the default AspNet Identity table names, you can do it in the following way:


    protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
    {   base.OnModelCreating(modelBuilder);

       //this is the default schema that will be used in the system.
       //I have the schema value stored in the app settings area of my web.config 

       modelBuilder.HasDefaultSchema(ConfigurationManager.AppSettings 
       ["DefaultDatabaseSchema"]);

       //the renamed tables

       modelBuilder.Entity<ApplicationUser>().ToTable("Users");

       modelBuilder.Entity<IdentityRole>().ToTable("Roles");

       modelBuilder.Entity<IdentityUserRole>().ToTable("UserRoles");

       modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaims");

       modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogins");
    }



    Using either your new schema name or dbo, you add a field to ApplicationUser like this:


    public class ApplicationUser : IdentityUser
    {
       [Required]
       public string WebsiteUrl { get; set; }


          //...other stuff here
    }


    That field, in this case WebsiteUrl, will be added to the AspNetUsers table.
    That is what you would expect to happen.
    Now, here is where things might get strange for you.
    There is a situation where you can rename the default table and add that field, but the field will NOT be added to the new table name! It will STILL be added to the database, but in the AspNetUsers table! That is NOT what you would expect right? Well here is a little bit of news for you, there is a simple fix for this if this behavior is not what you want.


    If this is happening to you, it is likely happening because you are identifying the IdentityUser table INSTEAD of the ApplicationUser table when you rename your tables.


    protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
    {
       base.OnModelCreating(modelBuilder);


       //this is the default schema that will be used in the system to separate the

       modelBuilder.HasDefaultSchema(ConfigurationManager.AppSettings 
       ["DefaultSchemaToBeUsedToPrefaceCreatedDatabaseTables"]);


       //the renamed tables

       modelBuilder.Entity<ApplicationUser>().ToTable("Users");

       modelBuilder.Entity<IdentityRole>().ToTable("Roles");

       modelBuilder.Entity<IdentityUserRole>().ToTable("UserRoles");

       modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaims");

       modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogins");
    }


    Notice the highlighted field. If you have IdentityUser in that field instead of ApplicationUser, the IdentityUser table and its associated fields will be renamed to Users, however, IdentityUser doesn't know anything about the extra field or fields you might have added in ApplicationUser. ApplicationUser incorporates the IdentityUser fields AND your added field. In my example above, that field is the WebsiteUrl. So, if your system is creating the database tables and STILL creating the AspNetUsers table AFTER you have renamed the table names, check the entity name you are using for the Users table. Remember that it should be ApplicationUser - NOT IdentityUser.


    Smooches!
    Kila



















    Monday, April 4, 2016

    How To Solve Website Errors: 503 Service Temporarily Unavailable While Using WordPress With A Windows Shared Hosting Accounts

    OK. This is an error that will likely have you pulling your hair out (if you have hair :-)). Here is the scenario.

    I have several website hosting accounts. One of those accounts is a Windows account that allows me to host multiple website (Deluxe Shared Hosting). I have MANY domains hosted on this account and the websites are a mixture of Asp.Net MVC, Asp.Net Webforms (yes...webforms still work :-)) and WordPress sites. I noticed an odd thing happening with the WordPress sites. From time to time, as I was working in the WordPress admin area, the sites would produce a 503 Service Unavailable error. Sometimes I would be editing a menu and click the Update button and would get the error. Sometimes I would make a change and try to visit the site and get the error. Sometimes I would make a theme edit and save and get the error. It happened at very random moments when some action was initiated on the server.

    Initially, I thought it was the version of PHP being used for the shared hosting account, so I upgraded to version 5.4 (I was using 5.2). Nope! That did NOT solve the problem at all. OK. What next? I upgraded WordPress for one of the accounts and started hammering it. No resolution! I kept getting the intermittent 503 errors. OK. So now what? Next I started hammering my Asp.Net MVC websites to try to produce the error. Nope! Couldn't reproduce the 503 error on ANY of those sites. I did the same for the Webforms sites and could not reproduce the 503 error there either. So I realized the first fact about this error -

    FACT #1 - The 503 Service Temporarily Unavailable error was ONLY happening on my Windows hosted accounts that had WordPress installed in their folders.

    Interesting....

    After realizing fact #1, I started to pay very close attention to what was happening when the error happened. I realized something. The error seemed to happen when some function had to be performed - ie. when something had to be saved. It didn't seem to happen on navigation only actions like going from page to page. However, I did notice that if the error happened when I was trying to perform an action in the admin panel, then I would also get the error on the website if I tried to bring that up at that moment. It was like the server was hanging on any server function other than serving pages and would get "stuck" for a few moments. It felt like the request for processing was happening too fast for the server to handle it so it would produce an error. Basically, the request for a function was coming in and being routed, but the underlying process could not move quickly enough to process it.

    Since Google is my friend, I started researching the issue. I saw that many people had the 503 error on shared hosting accounts, but no one had a real solution - including the hosting companies! Now I'm no server expert, but this isn't rocket science either. How hard can it be for some of these hosting companies to examine their logs and come up with a solution? Based on what I read, it must be VERY hard for them to do that! Anywho.....I decided to keep researching.

    I came across this from Microsoft -
    https://support.microsoft.com/en-us/kb/2619402

    That article gave me some great information. Since the Windows Deluxe shared hosting account allowed me to interact with IIS in a very limited way, I decided to see if I could tweak some settings in their to prevent, help, solve or stop the 503 errors from continuing to happen. By the way, my hosting account is using IIS 7.0. The IIS area provided by the website was very limited. However, it did allow me to switch from Integrated to Classic Pipeline mode. In integrated mode, all requests are handled in a unified pipeline. However, in classic mode, there are two pipelines. One is for native code applications and one is for managed code applications. You can look up the differences between native code and managed code, but essentially managed code needs a runtime to handle its execution. Native code executes on a particular processor and it takes it's instructions on how to run from the OS it is running on.

    So, here is what I did. The IIS 7.0 pipeline was set to Integrated mode. I changed this to Classic. Then I recycled the App Pool. The combination of these two things stopped the 503 errors from happening. This should help you get your websites running if you are on a Windows shared hosting account with limited access to IIS. Do not forget to recycle the app pool.

    I will keep you updated on how this "fix" holds. I have tested it quite a bit and haven't received a 503 error again....YET :-)!

    If you are experiencing this issue on your shared Windows hosting account with WordPress, try this and let me know how it works for you.

    Smooches,

    Kila Morton

    Monday, January 5, 2015

    How To Solve A Failure [INSTALL_FAILED_OLDER_SDK] When Using Android Studio

    There are some times when even though you KNOW what to do, you forget some small detail that causes you to waste time. When building Android projects, you know to add the minimum supported version to your manifest file. Well when using Android Studio to create Android projects, Gradle ignores your manifest file. This can make for a little bit of head-scratching as you are trying to figure out why your newly created project isn't running as you expected.

    If you get the following error:

    Failure [INSTALL_FAILED_OLDER_SDK]

    Look build.gradle file for your app and change the following :

    defaultConfig {
            applicationId "com.example.test.myapplication1"
            minSdkVersion 15
            targetSdkVersion 21
            versionCode 1
            versionName "1.0"
        }

    Notice the highlight. You are going to change minSdkVersion to a version that matches your target test device. Issue solved!

    Smooches!
    Kila

    Wednesday, December 31, 2014

    How To Solve The Gradle DSL method not found: 'runProguard()' Error In Android Studio

    After upgrading Android Studio, I ran into the following error -

    Gradle DSL method not found: 'runProguard()'

    This issue prevented the project from building. The solution was simple.
    Do a search and replace.

    Press Ctrl-F or Edit/Find and enter the letters runProguard into the search area.
    Once you have found runProguard, you will see that it is listed in this procedure:

        buildTypes {
            release {
                runProguard false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }

    Change the area I have highlighted to the following:

        buildTypes {
            release {
          minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }

    That is it! That will solve the issue for you.
    Wasn't that simple?
    Here is a link to more information about why this is necessary.

    http://tools.android.com/tech-docs/new-build-system/migrating-to-1-0-0
    Enjoy!

    Smooches!
    Kila


    Tuesday, December 2, 2014

    Telerik's Just Decompile Offline Installer - Install JustDecompile Using Offline Installers

    When .Net Reflector stopped being free, I think little birdies fell out of their nests all across the world. It was a great, free resource that was extremely useful at breaking apart a dll and allowing you to examine the guts. Although it was great, I was unwilling to shell out money for a paid version. I came across Telerik's JustDecompile, which, in my humble opinion, was better and free. That was many moons ago.

    Fast forward to now and I have been using JustDecompile for years. However, I recently needed to install it on a "secure" system and found that the system's antivirus software was blocking the download. After dutiful searching to find an offline installer without the bootstrap stuff in Telerik's official JustDecompile download, I came across these links-

    http://www.telerik.com/downloads/productfiles/bgctm/JustDecompile_2014.1.117.0.msi
    http://www.telerik.com/account/your-products/product-versions.aspx?pmvid=3656&pid=845 

    These links will allow you to download JustDecompile if you are behind a firewall, unable to download exe files (the top link) or are in a situation where your antivirus software is screaming bloody murder. If it doesn't work for you, let me know. As a matter of fact, if it DOES work for you, let me know. I just like to know things.....Smooches!

    Please note - you WILL need to create a free Telerik account, but why shouldn't you? It is free after all! JustEnjoy (play on words intended)!

    Kila Morton

    Tuesday, April 15, 2014

    SOLVING - Could not load file or assembly or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.

    This is quite possibly one of the most frustrating errors you can get after upgrading a Nuget package in an Asp.Net MVC project. If this is the first time you are getting it, you are likely wondering what is and where is the assembly's manifest. Well fear not mighty soldier developers because I have the information that will help you get running in no time. First an explanation.

    When you update an existing Nuget package, that update often has side effects. What does that mean? Well the packages you need often depend on other packages and when you run the Nuget update, the package you need might pull in updates to the packages IT needs even though you didn't specify that you wanted those other packages updated. That was a  mouthful! The dependencies being updated are side effects that you may or may not have planned for. On the surface, this seems like it might be OK. As long as the update happens to the files you need and things still build, you are fine. However, this isn't always the case. I'm going to run through what happens when an update happens.

    For this example, I'm going to say we are updating Package A.
    1. Package A depends on Packages K, L and M.
    2. You already have a version of Packages K, L and M installed on your machine.
    3. Package A needs to upgrade Packages K, L and M BEFORE it can install itself.
    4. Package M is needed by Package R so it can't be uninstalled unless Package R is uninstalled.
    5. The update  uninstalls Package R, Package M, Package L and Package K and then installs the newer versions of each package it relies on and the version of Package R that works with Package M. 
    6. After the new versions of the dependencies have all been installed, Package A installs the latest version of itself.
    7. The package.config file is updated to include the version information for the newly installed files.
    8. The dependentAssembly area in the web.config file is updated to include dependency information and establish the backward capability of the newly updated files.

    That is a lot! It is no wonder then that subtle side effects (aka hidden problems) can arise during that process. It is involved! If everything runs smoothly, all of the references are updated accordingly and all is right with the world. However, nothing ever runs smoothly does it?

    Sometimes, due to all of the installing and uninstalling that takes place, the web.config file does NOT get updated by the Nuget Package you are running! This is where we run into errors like -

    Could not load file or assembly 'Whatever.File' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

    Basically what this error SHOULD say is, "The web.config and package.config files do not match what is in the References folder"! There you have it - I have just rewritten a Microsoft error into something that a developer can actually understand? Did hell freeze over? Anyway, THAT is the problem. Sometimes when these packages uninstall and reinstall dependent packages, they do NOT update the packages.cofig and web.config accordingly. If the web.config references a version of the package that no longer exists, you  are going to get the "Could not load file or assembly...blah...blah....blah" error! So how do we solve this issue? The solution is easy.

    1. First, identify the file that the system is complaining about. It should be easy to do since the error message will list the file. For example, in the error below, Microsoft.Owin.Security.OAuth is the culprit. Could not load file or assembly 'Microsoft.Owin.Security.OAuth' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
    2. Second, go the References folder in your project and look for the file specified. When you find it, right click on it and select Properties (Alt-Enter) and look at the Version. Make a note of it. This is the actual version that is installed on your system.
    3. Third, go to the packages.config file and find the file. Check to see that the version number for the file listed in the packages.config matches the version you have specified in your References folder. 
    4. Fourth, check the web.config dependentassembly area for the file. The bindingDirect  areas has an oldVersion and newVersion area. The oldVersion area should end with a version number that is EQUAL to the version number you have installed and the newVersion number should MATCH what you have installed. For example, if you have version 5.0 of System.Web.Mvc, then your dependentAssembly and associated bindingRedirect should look like the following - 
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

          <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
          </dependentAssembly>
     

        </assemblyBinding>

     After you are done, clean and rebuild your project!
     Smile :-). Either your project built successfully and you can see your stuff or you have to repeat the steps above for another file until they have all been corrected.

    Notice the highlighted areas. The newVersion is what is installed on your system. The oldVersion represents all of the versions the newVersion should be able to handle. If this web.config information is out of sync with the version information in your packages file and in your project, then you will get an error.

    Please note - sometimes you have to manually change MORE than just one file to get things running. I have one project in which I had to update 5 references from different packages. Each situation will be different. If you get another file error, correct that one and keep going until you get a clean build and can run your project.

    If you want, you can run the Nuget Package Manager and update the one package that is giving you an issue. However, sometimes that is not the best approach if that package  has dependent relationships. You can end up in what I call "Package DLL Hell" - where one package updates another package and each update keeps causing other side effects! Hey - wasn't this what we were supposed to be SAVED from using Nuget? LOL.....anywho....following the steps above will get you going!

    Smooches,

    Kila Morton







    Friday, March 21, 2014

    Solving System.InvalidCastException was unhandled by user code Message=[A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast ......

    Recently, while upgrading an Asp.Net MVC 4 project someone created to an Asp.Net MVC 5 project, I ran across a great error. The error was this:

    It was also bright and red!


    Server Error in '/' Application.

    [A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.HostSection. Type A originates from 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'. Type B originates from 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\bc28c2e0\1b833c84\assembly\dl3\efd960b2\2bccde4f_7f44cf01\System.Web.WebPages.Razor.dll'.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidCastException: [A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.HostSection. Type A originates from 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'. Type B originates from 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\bc28c2e0\1b833c84\assembly\dl3\efd960b2\2bccde4f_7f44cf01\System.Web.WebPages.Razor.dll'.

    This error made me VERY unhappy.
    However, the solution was VERY simple.
    I just needed to tell the application which version to use.
    Here are the steps I took.


    1. Open the web.config file.
    2. Scroll until you find the <assemblybinding> tag under <runtime>.
    3. Add in the following dependent assembly information for the dll that is causing you problems. In my case, it was as follows:

    <dependentAssembly>

    <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="2.0.0.0" newVersion="3.0.0.0"/>

    </dependentAssembly>

    4. Rebuild your project!

    That is it! You should now see the fantastic work you have created after you build and Ctrl-F5. For all of you people out there still making projects with MVC 4 - JUST STOP! Back away slowly! MVC 5 is your friend!

    Smooches,
    Kila Morton

    Wednesday, February 26, 2014

    Solving "The term 'mongod' is not recognized as the name of a cmdlet, function, script file, or operable program.

    Recently, while attempting to install an instance of MongoDB on a Windows Azure VM, I got a nice error.

    mongod : The term 'mongod' is not recognized as the name of a cmdlet, function, script file, or operable program.
    Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

    I was in the bin directory of MongoDB at the command prompt and trying to run the database with the following statement -
    mongod  --dbpath c:\MongoData\ --logpath C:\MongoLogs\mongolog.db

    Ha! I forgot the .\!
    mongod  --dbpath c:\MongoData\ --logpath C:\MongoLogs\mongolog.db

    should have been
    .\mongod  --dbpath c:\MongoData\ --logpath C:\MongoLogs\mongolog.db

    I'm adding this here just in case anyone else is spacing out on a Wednesday wondering what in the world is going on when they are trying to run their Mongo databases.

    Smooches,

    Kila

    Thursday, February 20, 2014

    Solving System.Web.Http.GlobalConfiguration' does not contain a definition for 'Configure

    When upgrading your fantastic Asp.Net Web Api projects to version 2.0, you might come across this wonderful error -

    System.Web.Http.GlobalConfiguration' does not contain a definition for 'Configure 
    on this line of code -
    GlobalConfiguration.Configure(WebApiConfig.Register);

    The solution is quick and simple.

    1. Open the Package Manager Console for the project with the error.
    2. Type in Install-Package Microsoft.AspNet.WebApi.WebHost and hit Enter
    3. Rebuild your project and all should be right with the world (or at least right with your project)


    Smooches,
    Kila



    Wednesday, January 8, 2014

    How To Remove The "Switch between apps" window In Windows 8.1

    Hi! I've just been using a Windows 8.1 machine and losing my mind. I vowed never to use it until it was better designed (usually around Microsoft's 3rd or 4th attempt) after the very first frustrating experience I had with Windows 8, but I had to backtrack on that to test a piece of software I'm working on. I have noticed that although Windows 8.1 is slightly different, Microsoft has decided to maintain the interface from hell. I don't know why Microsoft thinks that people want to invest time in learning a new operating system when they have things to do.

    The new rub for me now with Windows 8.1 was the right side Switch between apps menu that didn't want to disappear. I moved my mouse all over that little thing to get it to leave. It wouldn't. I switched to a different app and it popped up on the left side. I was starting to get annoyed. I moved my mouse over it, pressed Esc and laughed as it sat there on the screen mocking me. Finally, I decided to probe it with my mouse. It won't go anywhere if you just put your mouse over it. You actually have to put your mouse into the far left corner (if it popped up on the left) or the far right corner (if it popped up on the right) for it to go away. That is the dumbest thing I have ever seen in my life! 

    Microsoft is a company with many brilliant people. They come up with great things from time to time. Windows 8 and Windows 8.1 should NOT be included as one of those great things. A few months back, I was on the Microsoft campus to do some testing for a Visual Studio add-in. Basically, they put you in a room and have you test out a product while you provide feedback. How on EARTH, did Windows 8 make it through that process? I don't understand. The product is COMPLETELY counter-intuitive for an operating system. I don't want a phone experience on my laptop! When I sit down to work, I don't want to perform unnatural movements to get things done. Do you know how much effort it takes to move my arm to touch my screen versus moving my wrist SLIGHTLY with my mouse to move something on the screen? I don't want to swipe and figure it out. In fact, I don't even like fingers ON my screen! I'm not alone! I also hate trying to figure out what something does. I like words - Open, Close, etc. I am against the idea of prearranged desktop icons. When I add a program to my computer and it adds an icon, I feel connected to that program and it's placement on the desktop because I ADDED IT. When I open Windows 8 and all of this crap is already staring at me, it just FEELS wrong because I didn't add that crap. I REALLY don't like the colors and styling of the interface either. I think it looks immature and cluttered. It may sound silly, but the way you set your computer up is an extension of you. Microsoft made the bet that people wanted a phone like experience across all devices. They were wrong. I have Windows 7 on every machine I do real business with. I have Windows 8 for those times when I need to make sure something I've created works on it. However, I have NO intention of upgrading unless I am absolutely forced to do so. NO INTENTION! I couldn't even imagine a system like Windows 8, with that horrible Metro interface, being used in an enterprise environment where people have to get things done quickly. You just don't have time to figure out why the pages keep swapping over each other when you are trying to get real work done. Windows 8 has been out for some time now and it has a very small adoption rate. I actually know people who purchased a Windows 8 laptop and then installed Windows 7 on it! What does that tell you?

    I would love it if Microsoft gave users a CHOICE - stick with the dumb as rocks Metro interface OR use the Classic Windows 7 interface! They would really get to see how many people thought Windows 7 was just fine. Windows 8 wasn't an improvement over a design that was broken. It just wasn't. If they had focused more on the cloud and integration with your other devices and LESS on radically altering the entire interface, Windows 8 would have been a smashing success. Instead, just like with the ribbon in Office that sent me and others right into the arms of Google Docs and Open Office, they focused on styling TOO MUCH! Who made that choice? I bet it wasn't a real developer. It seems like something a marketing person would have thought of. Either way, I think it is just plain crazy. History may show me to be totally wrong, but given the fact that Windows 7 usage is still mighty high, I don't think so.

    Anywho, to remove that annoying Switch between apps menu, just put your mouse in the nearest corner! Why didn't Microsoft make a little close icon on the pop-up? Counter-intuitive Microsoft - simply counter-intuitive.
    This ends my rant for the day.

    Smooches,
    Kila

    ***********************************************************

    Problem:
    The "Switch between apps" pop up in Windows 8.1 will not go away.

    Solution:
    Put your mouse into the corner of the pop up and it will disappear. If the pop up is in the far right corner, put your mouse into the top right corner of the pop up and it should disappear. If the pop up is in the far left, put your mouse into the top left corner and it should disappear. After you finish getting rid of that, go get a breath of fresh air.


    Thursday, December 19, 2013

    How To Find Stereo Mix On Windows 7- How To Enable Stereo Mix With Conexant


    I like to use Audacity to record things off of the Internet sometimes. However, to get a clean recording, you need to be able to use the Stereo Mix feature on your audio device. If you have certain Conexant audio devices, you  may not be able to use the Stereo Mix feature. According to some reports, computer makers, like Sony Corporation, asked Conexant to disable the Stereo Mix feature to stop people from recording things off of the Internet that might violate a copyright. Well, no matter the reason, I'm here to show you how to enable Stereo Mix on your Conexant device. Make sure you do the right things with this power.

    First we are going to make sure you don't have Stereo Mix on your machine already. If you are technically savvy and are completely sure you don't have it, then you can skip this step.


    1. In the lower left hand of your task bar, right click on the speaker icon.
    2. Select Recording devices. 
    3. Right click in the blank white space and select Show Disabled Devices and Show Disconnected Devices.
    4. If you don't see Stereo Mix, like the photo below shows, then you need to follow the second set of directions.




    ******************************************************************************
    OK. Now we are going to add Stereo Mix. It once was lost, but now it will be found! Ready?

    1. Go to your start menu and type Regedit. We are going to edit your Registry. Once the software comes up, click on Regedit. 
    2. Once you have Regedit open, you are going to go to HKEY_LOCAL_MACHINESYSTEM\CurrentControlSet\Control\Class\{4D36E96C-E325-11CE-BFC1-08002BE10318}\0000\Settings\EPattributes.
    3. Once you get to the EPattributes node, you are going to check and see if you have the EpSettings node. If you HAVE this node, move on to the next step. If you DO NOT have the EpSettings node, you will need to add it by right clicking on the EPattributes node and selecting New and then Key. Enter EpSettings.
    4. After you have either added EpSettings or verified that you have it, you are now going to add a key to EpSettings by right clicking on EpSettings, selecting New and then Key and creating a key named StereoMixEnable.
    5. After it has been created, right click on StereoMixEnable, click New and then Binary Value to create a Binary Value called Enable. 
    6. Change the value for Enable to 1 or 01 if you can't just put the 1 in.
    7. Right Click on StereoMixEnable again, click New and then Binary Value to create a Binary Value named MixAssocSeq.
    8. Change the value of MixAssocSeq to e0 e0
    9. Right Click on StereoMixEnable again, click New and then Binary Value to create a Binary Value named MuteGainSettings.
    10. Change the value of MuteGainSettings to 00 00.
    11. Now close Regedit and restart your computer.
    12. After your computer restarts, go to Control Panel, Sound and then click Recording tab and you will see Stereo Mix. It will be disabled.
    13. Right click Stereo Mix and enable it.
    14. Set it as the default device.
    Now you can use Stereo Mix to record sounds from the Internet directly into your computer using something like Audacity.

    If you have problems or questions, just ask!

    Smooches!
    Kila Morton

    Problem:
    You do not see Stereo Mix on your laptop or PC and you have a Conexant device.

    Solution:
    You must alter the registry settings, restart your machine and enable Stereo Mix.

    Saturday, August 3, 2013

    How To Solve The anti-forgery token could not be decrypted. If this application is hosted by a Web Farm or cluster, ensure that all machines are running the same version of ASP.NET Web Pages and that the configuration specifies explicit encryption and validation keys. AutoGenerate cannot be used in a cluster. Error In Asp.Net MVC!


    The anti-forgery token could not be decrypted. If this application is hosted by a Web Farm or cluster, ensure that all machines are running the same version of ASP.NET Web Pages and that the <machineKey> configuration specifies explicit encryption and validation keys. AutoGenerate cannot be used in a cluster.

    Isn't that a beautiful error? Recently, while working on a website I created in Asp.Net MVC 4, I got this error. How you ask? I'm so glad you asked! The website is hosted right now and I am developing it on my local development machine and pushing the changes to the actual website. From time to time, I leave my computer and leave the website up. There have been times when I was logged into the website, walked away, came back after the session timed out and clicked on a link on the site only to have the site route me to the sign in page. That is the expected behavior. What isn't expected, is that when I try to sign in I get this beautiful error -

    The anti-forgery token could not be decrypted. If this application is hosted by a Web Farm or cluster, ensure that all machines are running the same version of ASP.NET Web Pages and that the <machineKey> configuration specifies explicit encryption and validation keys. AutoGenerate cannot be used in a cluster.

    Now WHY do I think this is a beautiful error? Well unlike some errors you get while developing, this error actually means EXACTLY what it says! I am using the Antiforgery token system in Mvc. You call that using this syntax @Html.Antiforgery(). When you use this system straight out of the box, the encryption and validation keys are auto-generated at runtime for you. That is great - until the session terminates. At that point, the system loses a reference to those auto-generated keys. Then, when you are kicked out of the system and have to come back, it still has a reference to the old keys, but those are not usable anymore - since the system generated new ones for your new session. All of a sudden, the new one the system generated and the old one your page is referencing are not in sync and you get the error.

    So what can you do? The answer is simple - follow directions and generate the keys in your web.config file! Add the following to your site's web.config file.

    <configuration>
      <system.web>
        <machineKey decryptionKey="Decryption key goes here, IsolateApps"
                    validationKey="Validation key goes here, IsolateApps" />
      </system.web>
    </configuration>
    You can generate keys by going into IIS and clicking on Machine Key - if you have the right version and IIS features installed. You will not see Machine Key if you don't. If you don't, you can go to the Control Panel and install additional IIS features. Then, paste those keys into the code above. That will allow the Antiforgery system to work off of those instead of autogenerating.

    Problem solved!
    I just love it when a plan comes together! Don't you?

    Smooches,

    Kila Morton
     

    Sunday, June 9, 2013

    Solve Cannot retrieve property 'Name' because localization failed. Type 'YourResourceFile' is not public or does not contain a public static string property with the name 'YourItemName'.

    Data Annotations are a great thing. They allow you to add information to your model quickly and easily. However, if you have an application that is designed for multiple cultures, you cannot add a Name to your annotation and have it display appropriately for other cultures. It is easy to use App_GlobalResources to hold your global strings, however, you may encounter the following message when using an App_GlobalResources folder in Asp.Net MVC -

            [Required(
                ErrorMessageResourceName = "Required_PleaseSelectA",
                ErrorMessageResourceType = typeof(StringResources))]
            [StringLength(100,
                ErrorMessageResourceName = "Length_YourMustBeACombination",
                ErrorMessageResourceType = typeof(StringResources),
                MinimumLength = 6)]
            [Display(
                ResourceType = typeof(LocalizedResources),
                Name = "CategoryName",
                Description = "CategoryName")]
            public string CategoryName { get; set; }
    Cannot retrieve property 'Name' because localization failed.  Type 'Resources.StringResources' is not public or does not contain a public static string property with the name 'CategoryName'.

    In this particular example, I set up resources for a property called CategoryName.
    This error is VERY simple to solve. The resource file needs to be made public.
    To do this, you will need to change the TYPE of tool used to generate the resource file.

    In Asp.Net MVC 4, when you add a App_GlobalResources folder and create a resource file in it, by default the resource file is set up as internal and given the GlobalResourceProxyGenerator as a tool. That internal designation creates a problem for the DisplayAttribute annotation because it checks to see if the ResourceType is visible. In fact, it actually uses Type.IsVisible. This creates a problem because the internal class is NOT visible to it.

    Now here is an interesting thing to note. The RequiredAttribute and StringAttribute both inherit from ValidationAttribute. The DisplayAttribute does NOT. The Required and String Attributes utilize a different mechanism to connect with the resource files. You can see subtle differences when you look at how the items are set up again -

            [Required(
                ErrorMessageResourceName = "Required_PleaseSelectA",
                ErrorMessageResourceType = typeof(StringResources))]
            [StringLength(100,
                ErrorMessageResourceName = "Length_YourMustBeACombination",
                ErrorMessageResourceType = typeof(StringResources),
                MinimumLength = 6)]

            [Display(
                ResourceType = typeof(StringResources),
                Name = "CategoryName",
                Description = "CategoryName")]

            public string CategoryName { get; set; }
    Notice that each resource file in the photo of App_GlobalResources above has a .cs file attached to it.When you click on that resource file,  you see that all of the classes are internal. If you change the CustomTool to PublicResXFileCodeGenerator and rebuild your application, you will see the .cs file go from internal to public and your DisplayAttribute will be able to connect with the resource file now. In fact, if you click on the .cs file to open it AND change then go over to properties and change the CustomTool, all of the items in the file will automagically change from internal to public.

    Smooches,

    Kila Morton