Cool DevLife Hack on VS2015–Paste Special!

So I saw this post on MSDN Philippines and Philippine .NET Users Group Facebook feed about “cool #DevLifeHacks” that nobody else knows about. So may as well contribute to this fun.


And my entry! Visual Studio 2015 Paste Special! Oh Yea!


Simply copy any XML or JSON and turn it into instant C# Classes!


I am not kidding. From Json result, instant C# classes, complete with getters and setters from primitive types to objects.


How’s that for a “cool #DevLifeHack”?

Error CS1061 ‘ApplicationDbContext’ does not contain a definition for ‘ApplicationUsers’ (Fixed)

Visual Studio ASP.NET MVC controller with views and EF template creates db.ApplicationUsers instead of just db.Users. 

Workaround summary:

1. Rename ApplicationUsers to Users

2. Delete the Controller and View

3. Close and Re-open VS and Project. Rebuild.

4. Recreate the Controller!


So its in the morning, you said lets scaffold! And you got this error:


This happens when you reference a foreign key your “ApplicationUsers” that is used in the IdentityDbContext that inherits IdentityUser.


And then when you add a new controller with views using EF the scaffold will generate the ApplicationUsers but its DbSet or property of the object will not be available. 

One workaround is to rename your ApplicationUsers to only “Users”.



Now this is important, delete the controller and its views folder after renaming. Then you need to close visual studio. 

Open the project once more and rebuild your solution.

You should now be able to scaffold the controller.


Happy Scaffoldings!

Chain Commands in Package Manager Console and PowerShell

So its late, I am in a hurry and am very hungry. I needed this to be quick.


You can actually “Chain” or have sequential commands in one line using PowerShell. To do this use a semicolon “;” in each statement or command.

What it does is execute each statement or command then brings back the cursor to you after the last command was executed.

Since Package Manager Console uses PowerShell. In fact, a simple get-command will display a long list of commands and modules (As I demonstrate… a long list, not a good idea without any filters on get-command on a development computer).


So using PowerShell’s Sub expressions, you can also chain your commands like enabling the migration and then adding an initial migration then finally update the database on one command inside package manager console.

It’s the little things.

Unit Testing and CI of WCF Services

This is one of the reasons why I use WCF for all of my API projects.

There are a lot of ways to test a WCF Service Application, that we are using. I would to do a disclaimer that this may be appropriate for our use but may not for your scenarios. Moreover, what we are testing are the “functionality” of the methods exposed by the service and on tests we bypass most of WCF’s infrastructure.

The first thing you have to make sure is that the service is testable. This a default WCF implementation if you create it directly from the Visual Studio project template.


You wanted to create the service as an abstract class and implement it as a partial class, we do this so that we split most of our logic into multiple files and for this context, which is a unit test discussion, to not to be confused about the references. As you can see, there are 353 references to the partial class and these are all from unit tests.  From this point forward, the red class is our partial class.


Then you add the Service Implementation project as reference to the unit test projects. Make sure to add your Message and Data Contracts as well.


When you create the unit tests, you call the partial classes (in red) and then use it as it was just another class. Test it, use data source if you wish.


Note that this bypasses all WCF infrastructure and is only used for tests like its functionality and removing the networking component. You will also notice that you are not spawning any  IIS or host the WCF service to run test against it.


This now can be checked-in in TFS and do automated tests in your CI.


Happy CI-ing WCF Services! Smile

Visual Studio 2013 hangs on debug (Fixed)

Quick solution: Uncheck show all files.

I was coding for my personal project and after a few hours of debugging, VS seems to hang. I am pretty sure its not the hardware, so lets get that out of the way.

The solution contains a number of projects and folders. So to test, I created an empty solution, added the project and nada. I might be doing something wrong. Maybe VS settings? Symbols? But I already make sure that my build of VS follows my guide so its not it.

After tinkering around, setting settings gave up. So I will debug for one solution for now, its just a view change and do a build after check-in. I noticed that the icon ‘do not show all files’ is ticked, saying “who is adding files again thru solutions explorer?!”


Un-tick it, debug and hey! It works! Gotta try this now on the main solution.