Debugging a Visual Studio Crash

After a recent reboot, Visual Studio just stopped working.  Whenever I clicked on the icon on my desktop, I’d see this:

image

When the obvious solution (restarting my computer) I had to dig a little deeper.

Step 1:  Logs

The first step is to get some more information.  You can tell Visual Studio to log at startup by passing it the /log parameter on the command line.  Now, I’m fairly comfortable with the command line, but I rarely ever use it to start up Visual Studio.

An easier way is to just use the Diagnostic Mode option in the jump list.  Right click on the Visual Studio icon in your taskbar and select Diagnostic Mode.

image

Now all I had to do was wait for Visual Studio to crash again.  To get to the logs right click on the Visual Studio icon again select Open Activity Log Location.  With my setup, this opened C:\Users\Josh\AppData\Roaming\Microsoft\VisualStudio\12.0.  The log file is ActivityLog.xml.

In the log just search for a line like

<type>Error</type>

Hopefully, there aren’t too many of them.  In my case it pointed to a missing DLL

  <entry>
    <record>371</record>
    <time>2015/01/26 21:26:02.821</time>
    <type>Error</type>
    <source>Microsoft.VisualStudio.CommonIDE.ExtensibilityHosting.VsShellComponentModelHost</source>
    <description>Could not load file or assembly &apos;GettingStartedSetup.dll&apos; or one of its dependencies. The system cannot find the file specified.</description>
    <path>C:\USERS\JOSH\APPDATA\LOCAL\MICROSOFT\VISUALSTUDIO\12.0\EXTENSIONS\UVLFSVOS.E40\GettingStartedSetup.dll</path>
  </entry>

I went to the folder specified and verified that the DLL was missing.  Next thing to do is open up the extension.vsixmanifest to determine which extension it was.  Looking at the DisplayName node, it was fairly clear that it was Release Management tools for Visual Studio 2013.

<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011">
  <Metadata>
    <Identity Id="9b4bef8e-2ac3-4fa8-b8c7-d93d73d3618b" Version="2.2" Language="en-US" Publisher="Microsoft" />
    <DisplayName xml:space="preserve">Release Management tools for Visual Studio 2013</DisplayName>
    <Description xml:space="preserve">Release Management tools for Visual Studio helps to quickly get started with creating a Release Definition to automate the deployment of your application to multiple stages. You start with a working Build definition and then using this tool, set up a release pipeline that enables triggering of a Release for each build that is available for the build definition.</Description>
    <MoreInfo>http://www.visualstudio.com/products/release-management-for-microsoft-visual-studio-vs</MoreInfo>
    ...
  </Metadata>
    ...
</PackageManifest>

Step 2:  Safe Mode

Now that I know which extension was misbehaving, all I needed to do was uninstall it.

Open up Visual Studio in safe mode.  This can be done with a command line switch or through the jump menu again.

image

Visual Studio should open w/out a problem.  From here, it’s easy sailing.  Open up the Extensions and Updates tool, find the problematic extension in the Installed list, and press the uninstall button.

image

Now I was able to restart Visual Studio and it worked just fine.  I could have re-installed the extension, but I didn’t really need it so I just left it uninstalled.

Genymotion Android Emulator

I like to use an emulator to debug my android apps.  My emulator of choice is the Genymotion emulator.  It’s much easier to install and use than the one in the android-sdk.

One drawback I have seen with it it, is that sometimes it just refuses to start.  Getting it to start back up isn’t hard, but it isn’t all that unintuitive.

Try Try Again

The first thing to try is to just restart the emulator a few more times.  It might just work the third or fourth time.  You don’t have to restart the entire Genymotion console, just hit the start button and wait for the emulator to succeed or fail.  Try this a few times and you might just get lucky.

Delete Network Settings

If you’ve tried a few times and still don’t have any success you can force Genymotion to reconfigure its network settings.

Summary

  1. Open up Oracle VM Virtual Box manager
  2. Go to Preferences
  3. Go to the Network tab
  4. Delete the VirtualBox Host-Only Ethernet Adapter
  5. Start up the emulator as normal

Details

Open up the Oracle VM Virtual Box manager.  I do this by typing any part of the name that I happen to remember at the time into my start menu.

image

VirtualBox is what powers the emulator, so you will see all of your android images listed.  Go to File –> Preferences

image

Then click on Network on the right.

image

You should see “VirtualBox Host-Only Ethernet Adapter” in the “Host-only Networks”.  Select it and click the delete button on the right (it’s the button in the middle)

image

Now, go back to Genymotion and try to start the emulator again. It will notice that the virtual network adapter is missing and recreate it. You may see a UAC prompt asking if VirtualBox should be allowed to make changes to your computer.  Click yes.

Your emulator should now startup.

Creating Drawables for Android

One of the pains for Android development for me is creating drawables in different sizes for various devices. In the past I’d only have a few images at a time to resize so I’d normally just upload them to Android Asset Studio and have the site generate the correct sizes for me.

There are two problems with this approach.  First, I have to upload the files one at a time.  If I have more than 4 files then it becomes a bit of a chore.  Second, I can’t specify what size I want the output.  It always  generates files that are

mdpi 32×32 pixels
hdpi 48×48 pixels
xhdpi 64×64 pixels
xxhdpi 96×96 pixels

Instead of manually editing the images I had (I had a lot) I decided to finally just write an app to handle this for me.  You can find it on GitHub at AndroidIconsResizer.  Right now it is a little barebones but it quickly and easily handles batches of images.

All options are optional so the simples use is to just run it.  If nothing is specified it assumes the current directory for all input or output.  By default the output images are all squares and are 100×100 at the mdpi size.

> AndroidIconResizer

It looks for all the .png files in current directory, resizes them and copies them to the appropriate output directories.  If you ran the above command in the following directory

.
..
file.png
anotherFile.png

then the directory would look like this after

.
..
file.png
res/
    drawable-mdpi/
        file.png (100 x 100 pixels)
        anotherFile.png (100 x 100 pixels)
    drawable-hdpi/
        file.png (150 x 150 pixels)
        anotherFile.png (150 x 150 pixels)
    drawable-xhdpi/
        file.png (200 x 200 pixels)
        anotherFile.png (200 x 200 pixels)
    drawable-xxhdpi/
        file.png (300 x 300 pixels)
        anotherFile.png (300 x 300 pixels)

It is possible to specify different sizes (heights and widths) for the output images.  All you need to specify is the size you want the mdpi image.  The other sizes are extrapolated based on Google’s iconography recommendations.

> AndroidIconResizer –w 20 –h 50

You can specify the input and output directories just as easily

> AndroidIconResizer –i inputDir –o outputDir

By default the xxxhdpi image isn’t generated since it’s only needed for launcher icons.  You can choose to include it with an option

> AndroidIconResizer –-include-xxxhdpi

Or you can just ask the tool itself for some help:

> AndroidIconResizer –help

Those were all the features I needed today, but I’ll probably be expanding on this app in the future.  Let me know if you’d want any other features.

Happy Coding.