Colin’s ALM Checkin Policies VS 2019

I won’t go at length explaining the title, as post is useful only to people who already use this Visual Studio extension. At the time of writing this post, extension is not available for Visual Studio 2019. Last post from the author on this subject suggests he won’t be looking into this any time soon (post is 3 months old now). Multiple PRs have been submitted already so I am taking liberty of making available publicly my personal build of the extension.

I have not thoroughly tested the extension or ran unit test. It covers my teams basic use case, so I take no responsibility to maintain it.

Visual Studio Extensions dialog

Source code

Multiple EntityFramework contexts with code-first migrations

I’ve encountered an issue with code-first migrations in a brown field project which uses Oracle DBMS for data persistence. First to describe my goal in short:

  • Store all application data in single database
  • Application may have multiple data contexts
  • Old parts of database will not have any migrations, as they are created and updated externally
  • Application will have modules which don’t have tight dependency to some central data layer
  • Each module may have it’s own EF DB context. And each module may perform code-first migrations independently of other modules

Sounds quite straight forward, and it is, until we’ve hit a bug in EF. So, we created additional DbContexts, with their own migrations. Upon running the migration, what we’ve encountered is error back from Oracle.

ORA-00955: name is already used by an existing object

What has happened is that EF is attempting to create __MigrationHistory table which already exists. So, although there was another context which created the MigrationHistory table, next context attempts to create it again. We’ve found this bug reported in EF GitHub repo, all the way back in 2016. Workaround that bug author has used is to have separate __MigrationHistory table per context, which I did not like for a couple of reasons.

  • I may have many (more than 5) contexts, and I don’t want variants of __MigrationHistory table to clutter the databases
  • Configuration which allows this change is AppDomain wide, so we would have to either have separate apps to do migrations, or do juggling of AppDomains per DB context

Over investigation of the problem, what we’ve found is that it happens only if user does not use SQL Server dbo schema. Since we use Oracle, this was clearly the case. So we found two potential workarounds. One is clearly, create dbo user and __MigrationHistory table inside it. A cleaner one is to set default schema for HistoryContext of EF. This is EF internal context which is used to read migrations history. So, what you need to do is:Annotate DbContext with your own configuration (MyConfiguration)

1. Annotate DbContext with your own configuration (MyConfiguration)

    public class MyDbContext : DbContext

2. Implement the configuration. It’s purpose is to return subclasses history context. In this case MyHistoryContext

    public class MyConfiguration : DbConfiguration
        public MyConfiguration ()
            SetProviderServices("Oracle.DataAccess.Client", EFOracleProviderServices.Instance);
            SetHistoryContext("Oracle.DataAccess.Client", (connection, defaultSchema) => new MyHistoryContext(connection, defaultSchema));

3. Implement the subclasses context to use your desired schema

    public class MyHistoryContext : HistoryContext
        public MyHistoryContext(DbConnection dbConnection, string defaultSchema)
            : base(dbConnection, defaultSchema)

        protected override void OnModelCreating(DbModelBuilder modelBuilder)

Running ASP.NET application under elevated privileges

Hopefully there are better ways to run an application in IIS under elevated privileges. For my purposes, what I’ll describe in this post will have to do. Have in mind that having any kind of endpoint exposed to public web under elevated privileges is extremely bad idea. I’m doing this in lab circumstances, on a system whos purpose is to run tests on.

To elevate privileges of a web application, IIS process must be elevated of course. I did not see a way to elevate only single application in my short search.

You would think that impersonating an administrator for a single application would work, or that creating App Pool which runs under an administrator account would work. However, this is not the case.

You’ll have to run to machine.config file in one of following folders (I’ve edited configs of .NET 4, 32 bit and 64 bit):

machineConfigPathsSet userName attribute of <processModel /> element to System.

iisProcessModelAfter you run iisreset your application should be able to do serious damage to the system.

Manipulating table child elements in AJAX callback considered harmful?

This is one of those small bugs that eats away entire day. You find a workaround rather quickly, but can’t let go until you know what to heck is going on.

This happened in rather large AngularJS application, which meant I had to chip away everything that is not necessary to reproduce the issue for hours.

Application screen consists of a table with several rows, with number input boxes. When user changes a value and leaves the input field, application sends a web request to perform some kind of calculation to 3rd party service. It then replaces the row that contains the changed field (performing web callbacks onblur is due to hard requirements that customer has placed. Not mine to judge). If blur event occurred due to clicking (not tabbing) into another input in same row, buttons don’t receive click events anymore. I have to stress, that there is no flicker to indicate elements moving around the page. If you click anywhere within the table again, click events start getting fired again.

You can see the issue in action here

Wait for table to load, click one input, then click second input in same row. Now go to bottom of the table and click “Can’t click this!”. It should show an alert. More often than not, it will not fire if you are using IE.

After removing almost all of the code of the application, conclusion is following:

  • happens only in IE (even version 11)
  • happens only when modifying inputs within TABLE element
  • happens only when modifying DOM within an AJAX callback
  • happens only when inputs within a table are defocused+focused
  • disappears when something is focused again after the manipulation

Why this happens?

Can’t really give you inner workings of the browser, but a hint is that AngularJS doesn’t seem to update values in inputs when you swap the object under it. It removes the inputs, and places new ones (we’re talking about ngRepeat directive to generate table rows). If you actually modify values within bound objects, this problem doesn’t happen.

Workaround? Why, there’s an ugly workaround always, of course!

Actually, there are two.

Focus something after modifying the DOM:


Or, modify the objects to which Angular model is bound. You can use angular.copy() function for that. It’s primary use is for creating copies of objects, but it takes an optional second parameter using which you can provide destination object.

angular.copy(newItem, $scope.ItemArray[idxToReplace]);
// instead of 
$scope.ItemArray[idxToReplace] = newItem;

Although second workaround seems nicer, I prefer the first one. I don’t want workarounds to seem nice. Broken line of code shown in workaround is actually more optimal, so I assume someone may want to ‘fix’ the workaround. I prefer that fixes for ugly bugs be obvious.

Update 2015-06-18:
This also happens with current version of Spartan browser.

Early access to HttpRequest in ASP.NET application

This is I see question often asked by people working on legacy applications. When IIS Integrated application mode was introduced, there were couple of breaking changes that caused (badly designed) access to web request to crash.

Applications which used to access HttpRequest early, in Application_Start greet visitors with an exception:

Request is not available in this context

In simple words, request is not yet available in this stage of execution. It will be available later. Documentation for HttpContext.Request property states:

ASP.NET will throw an exception if you try to use this property when the HttpRequest object is not available. For example, this would be true in the Application_Start method of the Global.asax file, or in a method that is called from the Application_Start method. At that time no HTTP request has been created yet.

There are many suggestions that involve catching the exception, checking message or other properties and make a decision based on that. While this will work, it’s not good approach for number of reasons.

Most important of which, it will negatively impact performance of your application, which is explained in this MSDN article.

Checking message is not safe, since different language version of .NET framework may be used, with localized messages. Or the message can be changed in updated version of .NET framework.

In the end, determining that Request is not always enough. One may decide to allow this, if information in the request is not critical, but some (awful) code may require the request to properly perform the initialization.

Workaround is simple enough, that I’m amazed there are so many proposals for what I’ve described above.

  1. Move initialization from Application_Start to Application_BeginRequest.
  2. Since request handling method executes on each request, make sure it’s executed only once
public void Application_BeginRequest()

private static bool _startupPerformed = false;
private static object _startupLock = new object();
private void DoStartup()
    if (!_startupPerformed)
        lock (_startupLock)
            if (!_startupPerformed)
                _startupPerformed = true;
                // Initialize here

Creating network share with anonymous access

I needed to create a network share on Windows server machine which would require no authentication whatsoever from users. This post is intended to serve me as a reminder, since googling the solution every time eats easily away hours.

Settings which need to be changed of course depend on version of Windows of network share host. This post describes how to do it on a Windows 2012 R2.

Rougly what needs to be done is:

  • network share should be created
  • share permissions need to be set
  • security settings need to be changed

In more words:

  1. Share a folder by opening folder properties, navigating to Sharing tab and clicking
    Advanced Sharing…
  2. Enable sharing and click Permissions
  3. Add Everyone (should already be there), Guest and ANONYMOUS LOGON and give them Read access
  4. Open Group Policy Editor (hit Ctrl+R, type gpedit.msc and hit enter)
  5. Navigate to Computer Configuration → Windows Settings → Security Options
  6. Change following:
    • Accounts: Guest account status – change to Enabled
    • Network access: Let Everyone permissions apply to anonymous users – change to Enabled
    • Network access: Restrict anonymous access to Named Pipes and Shares – change to Disabled
    • Network access: Shares that can be accessed anonymously – enter name of share you created in the text field

This let me access the share \\<MachineName>\Share without providing any login information.

Running Windows 8.1? With how similar these two OSs seem, you’d expect this would be enough. However, it is not. For Windows 8.1, Microsoft recommends using Home groups. It is still possible to get conventional file share working, but I have not had time to try this out and it doesn’t seem a good security practice. I’ll just refer you to a find I stumbled upon on MS Technet Forums. Essentially what it suggests is using LanMan level 1 compatibility mode which would allow OS to accept LM authentication (in addition to NTLMv2). I’m not going to pretend to understand what kind of repercussions this has on machine security so I won’t recommend you to do it outside of your home LAN, and maybe not even there if it’s exposed over WiFi.


Web server returning proper response with 500 status


I’ve had a funny problem today. It wasn’t so funny during hour time I was trying to solve it. Directing my browser to a web page which looked OK yesterday resulted in a horrific view of content without downloaded styles and smelled like missing script files.

Debugger has shown that indeed, some of the static files could not be downloaded. Status 500, server said. Internal server error, server said. Ok then, let’s see what this is about. So I open Response body and what do I see? I see proper response, from start to end.


This happened to random static files.

Root cause

My bad…

I’ve placed some debugging code which occasionally failed in Global.asax.cs, Application_Start method. Code was such that it failed for random web request, and IIS was configured through web.config to let ASP.NET handle all requests, including static files. So, from standpoint of ASP.NET, web request has failed since an exception was thrown and it returned status 500 to IIS. However, it did not return any response body along with status, so IIS grabbed the file and sent it back.


Web fonts and IE on Windows 2012

I’ve had not a good day with web. It’s been throwing me curve balls whole day. One of things which wasted my time was Internet Explorer which is ran on a server OS.

I did not expect everything to go completely smooth, as it’s usual to have to go around IE enhanced security on server operating system if you wish to browse at all.

I’ve fired up IE’s debugger to see what’s going on, expecting that problem lies in MIME types configured in IE (or web.config file). However it turned out that IE did not request web fonts at all. There was no warning or notice in console either.

Iconless buttons
IE on server OS does not request web font unless site is trusted

Problem was that IE does not even request web fonts unless host is added to list of trusted sites. Run to IE options, Security tab, select Trusted sites and add target host to the list. Problem should be solved



Upgrading Windows 8.1 edition to Pro

The problem
I’ve recently got a new laptop with licensed version of Windows 8.1, however I needed a Pro version since I need Hyper-V. So… I downloaded “multiple edition” setup ISO from MSDN and repaved the machine. It did not ask for a product key and just got activated automatically as a standard edition. After searching around I found out you can change your product key (in a couple of ways) so I gave it a shot with my Pro key. But I was greeted with an error message.

That key can’t be used to activate this edition of Windows.

Googling and Binging around didn’t help as everyone pointed to using an “Upgrade key” which is a different thing. This doesn’t work for me since I’m MSDN subscriber. Why in hell would I then buy another key? I won’t budge… Go for another longer session of search…

The solution

Disable User Account Control

After disabling UAC changing product key worked like a charm. I’m amazed as anyone else…

EntityFramework 7 – Where to next?

With a track record of doing major strategy shifts, Microsoft wasn’t the company one would expect to play by rules that someone else wrote. After era of dictating trends, they’ve learned to listen and follow paths set by someone else. They’ve open sourced a lot of things they are working on. And not just research projects. Major frameworks or components used by millions of websites.

EntityFramework is another proof that they listen. They’ve heard how people want to do data access, and they’ve followed the way set by Hibernate project. They weren’t very successful in the begging. I’ve had a lot of rows with EF 3.5, it’s object tracking, database first design et cetera. After years of playing catch-up, finally with EF 5 we got a tool which we would dare use in a production project.

After tremendous effort they’ve made, and a lot of energy invested they are neck and neck with best O/RM solutions, and they have a chance to offer something more. Strategy for EF7 has been outlined for public in their Entity Framework Everywhere initiative.

What I’ve taken away from their post is:

  • It will be lightweight. Many seldom used features will not be there. Think, one-to-one mapping will remain, inheritance mappings wont. And surely few other things.
  • It will be available everywhere. Meaning, we will finally have a worthy heir to SQLite for local storage (think Windows Store, Windows Phone)
  • It won’t be just for relational data anymore. Azure Table Storage will be one of the target stores
  • EntityFramework 7 will be a different beast, and will potentially introduce noticeable amount of breaking changes to existing projects. Those of you used to DbContext need not worry as much
  • EntityFramework 6 will be developed and maintained in parallel

FeatherThose are tactical steps they are taking. What is the strategy behind them? I’m not so sure these steps stemmed from a strategy. It is the other way around. Microsoft has invested a lot of effort into making a good O/RM tool with premium experience for developers. Now that they are there, they still have developers who’ve invested years in EF and rather than shifting to maintenance mode and disbanding part of the team, they’ve decided they can afford to innovate. We don’t see clear strategy also because now ASP.NET team which is in charge of EF, is making  a tool for Windows Store and Windows Phone.

What Microsoft is doing is providing a lot of choice to developers. Rather than risking by making a strategy and missing, they are providing many choices and hoping us developers will take them the rest of the way. I’m enthusiastic about having lightweight local storage O/RM, and hope for better performance, but I hope that developers won’t get lost in forest of choices.