How to Open the Same File Twice in Visual Studio

Hey everyone,

Today I was working on a fairly large class and needed to compare two different areas of code. I’m used to using text editors such as notepad++ and sublime where I would normally just open the file multiple times. It turns out that Visual Studio has a similar feature, although it’s admittedly a lot less intuitive:

- Open the file you want to duplicate and make it the active tab (just click on it somewhere)
- Select window from the menu up the top
- Click New Window

This will duplicate your active tab. To place them side by side simply right click on one of them and then select ‘New Vertical Tab Group’.

Thanks to this Stackoverflow post for the solution: http://stackoverflow.com/a/772159/522859

View Generated SQL in Entity Framework (EF)

Hey everyone,

Just a quick post on how to view the generated sql in entity framework. To start with, just add the following line to your db context constructor:

public class TestDbContext : DbContext
    {
        public TestDbContext() : base("name=TestDbContext")
        {
            this.Database.Log = s => System.Diagnostics.Debug.WriteLine(s); //This line
        }
        ...

With this line added, you should now be able to see all of your generated sql in the output window.

SELECT TOP (1) 
    [Project1].[VidId] AS [VidId], 
    [Project1].[CreatedAt] AS [CreatedAt], 
    [Project1].[CHECK] AS [CHECK], 
    [Project1].[SourceCheck] AS [SourceCheck]
    FROM ( SELECT 
        [Extent1].[VidId] AS [VidId], 
        [Extent1].[CreatedAt] AS [CreatedAt], 
        [Extent1].[CHECK] AS [CHECK], 
        [Extent1].[SourceCheck] AS [SourceCheck]
        FROM [dbo].[Vids] AS [Extent1]
        WHERE [Extent1].[VidId] < @p__linq__0
    )  AS [Project1]
    ORDER BY [Project1].[VidId] DESC
 
-- p__linq__0: '535' (Type = Int32)
-- Executing at 28/06/2014 5:00:16 PM +10:00
-- Completed in 0 ms with result: SqlDataReader

If you’re not using EF6, there were a few other options where I came across this solution: http://stackoverflow.com/a/20751723/522859

Dragging a File from File Explorer Causes Google Chrome to Crash

Hey everyone,

A team member found an interesting bug today that caused chrome to go non-responsive. The cause was simply dragging a file from the file explorer onto a drag and drop upload area. It is reproducible on every site I’ve tested, including Gmail and Dropbox.

Reproduce

  • Go to https://mail.google.com
  • Click compose
  • Click attach files (close any of the annoying popups that appear)
  • DRAG a number of files from the file selector window to the new message screen (they will start to upload) (IMPORTANT: these need to be dragged from the file selector popup, NOT a new explorer window)
  • While they are still uploading hit cancel on the file browser window. Browser will go non-responsive

A bug has been reported here: https://code.google.com/p/chromium/issues/detail?id=388661

How to Open the Same File Twice in Visual Studio

Hey everyone,

I was working on a fairly large class in visual studio and having a bit of trouble comparing two different areas within it. Thankfully, StackOverflow knew of a way to make things a lot easier – open the same file twice:

- With the tab you want to duplicate currently active, select Window from the menu
- Click new window
- On the new window, right click and select ‘New Vertical Tab Group’ from the drop down

How to stop text taking up more than one line – CSS

Hey everyone,

Just a quick post on how to stop text taking up more than one line using only CSS:

.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

You can check it out using this fiddle: http://jsfiddle.net/wb5m7/
There’s also a great StackOverflow post: http://stackoverflow.com/a/572302/522859

Duplicate type name within an assembly. – Entity FrameWork (EF)

Hey everyone,

I ran into this error message while trying to debug a project today:

“Duplicate type name within an assembly.”

 

The workaround to this was actually pretty weird. Remove all of your breakpoints that appear before this exception and place one after it instead. That’s it!

A bit of a weird issue, but according to the StackOverflow post where I found the solution Microsoft are aware of it: http://stackoverflow.com/a/23529882/522859

Twitter Authentication 401 Unauthorized – MVC4/5

Hey everyone,

Just testing out twitter authentication and ran into the following error:

Response Status code does not indicate success: 401 (Unauthorized).

To fix this, all you’ve got to do is go to you Twitter App settings and:
- Add a callback url (doesn’t have to be real)
- Check the ExternalLoginConfirmationViewModel checkbox

Unable to Find GoogleOAuth2AuthenticationOptions – MVC4/5

Hey everyone,

I was following the guide provided via the startup.auth.cs link on how to add Google authentication to your app. The problem I hit was that the example types used weren’t available, specifically GoogleOAuth2AuthenticationOptions.

Thankfully the fix fix for this was pretty easy, simply update OWIN via NuGet:

- Right click on your project
- Go to Manage NuGet Packages
- Click on the updates drop down
- Search for OWIN
- Update all of the relevant options

Thanks to this Stackoverflow post for the solution: http://stackoverflow.com/a/23606431/522859

Decimal Values for Bitcoin C#

Hey everyone,

Just linking to a few Stackoverflow posts that have helped me out with bitcoin precision requirements:

Precision Values
http://stackoverflow.com/a/22077085/522859
http://bitcoin.stackexchange.com/a/4099

Setting up Decimal Precision in MVC4+
http://stackoverflow.com/a/7769162/522859

Refresh a Page with JavaScript

Hey everyone,

Just a quick post on how to force a page refresh with JavaScript (no jQuery required):

location.reload();

Note that the reload function accepts a boolean parameter that can be used for force a server refresh. Alternatively, it just defaults to the cache.

Checkout this Stackoverflow post for more info: http://stackoverflow.com/a/5404869/522859