Tag: Visual Studio 2017

Bitbucket Extension for Visual Studio

I started working in a new company recently, one that uses the Atlassian Bitbucket repository for source control. I\m not a big fan, but it’s Git. Anyway, I needed to integrate it with Visual Studio 2017, so I fired up the Extensions and Updates dialog from the Tools menu. I typed in ‘bitbucket’ in the search field, and found one extension, Visual Studio Bitbucket Extension by NextIteration v. 1.37.1 at the of writing this, which I then downloaded and installed. Unfortunately I couldn’t find in the Source Control section of the Options dialog box, found on the Tools menu; it just wasn’t shown in the Current source control plug-in dropdown list. I closed the Options dialog, and switched to the Team Explorer window which didn’t show the extension either. So, I went to the Visual Studio market place and found another extension by MistyK, https://marketplace.visualstudio.com/items?itemName=MistyK.VisualStudioBitbucketExtension. Installing that, did the trick, even if this extension was also version 1.37.1, go figure…

Advertisements

Visual Studio 2017 Editor new line wrapping

We all have our favourite settings when it comes to setting up Visual Studio, and the editor is quite often set up differently for a group of developers working together. I like having the opening brace ({) on the same line as the class, struct or whatever the brace signals the beginning of.

I like this:

class {

as compared to this:

class {

I frequently use the key combination Ctrl+K, Ctrl+D to format my document after having typed some code. I dislike it, if the formatting is not to my liking. It should therefore not come as a surprise, if I tell you that while working on a new UWP app, in which I had copied across some code from a Template10 project template, the key combo seemingly didn’t work anymore. After some investigation, including opening an existing Console app, in which the key combo did work, I took a look at this code:

namespace Template10.Views
{
    public sealed partial class SettingsPage : Page
    {
        readonly Template10.Services.SerializationService.ISerializationService _serializationService;
 
        public SettingsPage()
        {
            InitializeComponent();
            NavigationCacheMode = NavigationCacheMode.Required;
            _serializationService = Template10.Services.SerializationService.SerializationService.Json;
        }
 
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var index = int.Parse(_serializationService.Deserialize(e.Parameter?.ToString()).ToString());
            MyPivot.SelectedIndex = index;
        }
    }
}

Because of the Page class, from which the class shown, SettingsPage, is derived has a notification stating “Base type ‘Page’ is already specified in other parts”, the class/type name Page is greyed out. This effectively blocks for the document formatting placing the opening brace { on the same line as the class declaration. If I remove : Page, and press the key combination Ctrl+K, Ctrl+D, this is what I get.

namespace Template10.Views {
    public sealed partial class SettingsPage {
        readonly Template10.Services.SerializationService.ISerializationService _serializationService;
 
        public SettingsPage() {
            InitializeComponent();
            NavigationCacheMode = NavigationCacheMode.Required;
            _serializationService = Template10.Services.SerializationService.SerializationService.Json;
        }
 
        protected override void OnNavigatedTo(NavigationEventArgs e) {
            var index = int.Parse(_serializationService.Deserialize(e.Parameter?.ToString()).ToString());
            MyPivot.SelectedIndex = index;
        }
    }
}

 

Visual Studio 2017 Create Strong Name Key File

When trying to create a strong name key file for your project, in this case a UWP project, in Visual Studio 2017, and probably previous versions too, you may get an error message, once you click OK in the Create Strong Name Key dialogue box.

CreateStrongNameKeyWindows-VS2017

The operation could not be completed message box.

TheOperationCouldNotBeCompletedDialog

It turns out that all I needed to do, was to run Visual Studio as an administrator, and it worked. It’s the actual signing with the password that requires this, as you can create a key file without a password, and the signing will work without running VS as an administrator.

OutOfMemoryException in online test

I did an online test the other day, and while the code I had put together did work and passed 3 of the 4 testcases, the failing testcase throw an OutOfMemoryException. I was writing the code in Visual Studio 2017 and copying it to the web-based IDE on TestDome. Now, since I don’t know what the testcase did, I can only assume that it added a very large number of int’s to an array, for which I was to find the kth most common integer in the array. This is my code:

public static int KthMostCommon(int[] a, int k) {
    return a.GroupBy(v => v)
        .OrderByDescending(g => g.Count()).ElementAt(k - 1).Key;
}

I only got a 66% score for that task, but it dawned on me, that I should have tried using a byte array instead. Trying it with the following call to the method and obviously changing the method signature to accept a byte array instead of a an int array, worked a charm.

var t = Enumerable.Repeat<byte>(0, 1000000000)
    .Select(i => (byte) randNum.Next(minValue, maxValue)).ToArray();
var x = KthMostCommon(t, 2);

What would you have done, not knowing the number of integers that was in the array?

UPDATE:

I obviously couldn’t have changed the method signature as suggested in the actual test, as that would have caused all unit tests to fail. Another option is to pass the int array and convert to a byte array, and then disposing of the int array before processing the byte array.

var bytes = new byte[a.Length * 4]; 
for (var i = 0; i < a.Length; i++)
     Array.Copy(BitConverter.GetBytes(a[i]), 0, bytes, i * 4, 4);
a = null; 
GC.Collect();

Mind you, it would probably be better changing the processing alltogether… 🙂

Start Page in Visual Studio 2017

What the heck happened with the Start Page in VS 2017? Well, not the Start Page as such, but how do you open it, after closing it manually or opening/creating a project or solution? In prior versions you could access the Start Page menu item on the View menu, and going further back over the years, I do believe it ws accessible from the Help menu at some point. In any case, it is now residing on the File menu…

VisualStudio2017StartPage

Visual Studio 2017 Extension Load Error

After installing quite a few extensions by using the Extensions and Updates command on the Tools menu, I started to get a load error every time I opened Visual Studio, telling me to check the ActivityLog.xml in the C:\Users\…\AppData\Roaming\Microsoft\VisualStudio\15.0_709865ab folder. I opened the file and found numerous entries like this one:

System.ComponentModel.Composition.ImportCardinalityMismatchException: Duplicate EditorFormatDefinition exports with identical name attributes exist. Duplicate name is PowerShell Interactive – Black

I suggested to me I had to check for duplicate extensions, and I had indeed installed two editions of the same extension, PowerShell Tools for Visual Studio 2017 as well as the old one, PowerShell Tools for Visual Studio 2015. Uninstalling the latter solved the issue. 🙂