Visual Studio 2010 Add-in Settings Swapper

Challenged by a coworker recently, I created a simple add-in for Visual Studio 2010 to modify the settings for code formatting based on the file extension. The usage scenario is simple: allow for different language formatting rules based on the file file type (or extension). In this case, he wanted to have a different standard for curly brace usage in MVC ASPX pages overriding the default.

The addin, called Settings Swapper may be downloaded from CodePlex and is licensed using the new BSD license.

The documentation is here.

The settings he used for MVC pages are included in the documentation. If you have any questions or issues, either leave a comment here or add something to codeplex.

Enjoy.

Visual Studio 2010 Crashes Repeatedly

If you have my kind of luck and Visual Studio 2010 crashes every time you open a specific project or solution, try deleting the .suo file associated with the solution (the Visual Studio Solution User Options). It’s located in the same folder as the solution (.sln) file, and often is hidden.

It usually works for me.

The stack dump from the mini-dump taken by Visual Studio isn’t real enlightening. Things went wrong. Smile

     ntdll.dll!@RtlpLowFragHeapFree@8()  + 0x89 bytes   
     ntdll.dll!_RtlFreeHeap@12()  + 0x7e bytes   
     apphelp.dll!_SdbFree@4()  + 0x22 bytes   
     apphelp.dll!_HashFree@4()  + 0x3c bytes   
     apphelp.dll!_SdbpReleaseSearchDBContext@4()  + 0x6d bytes   
     apphelp.dll!_SdbGetMatchingExeEx@32()  + 0x2b9 bytes   
     apphelp.dll!_InternalCheckRunApp@76()  + 0x21c bytes   
     apphelp.dll!_ApphelpCheckRunAppEx@56()  + 0xa7 bytes   
     kernel32.dll!_BaseRestoreImpersonation@4()  – 0x75d55 bytes   
     kernel32.dll!_BaseCheckRunApp@52()  + 0x46 bytes   
     kernel32.dll!_BasepCheckBadapp@60()  + 0x1a1 bytes   
     kernel32.dll!_BasepQueryAppCompat@68()  + 0x63 bytes   
     kernel32.dll!_CreateProcessInternalW@48()  + 0x961 bytes   
>    kernel32.dll!_CreateProcessInternalA@48()  + 0x123 bytes   
     kernel32.dll!_CreateProcessA@40()  + 0x2c bytes   
     devenv.exe!DwCreateProcess()  + 0xc0 bytes   
     devenv.exe!LaunchWatson()  + 0x2b2 bytes   
     devenv.exe!DwExceptionFilterEx()  + 0xed bytes   
     devenv.exe!DwExceptionFilter()  + 0x1f bytes   
     mscoreei.dll!InternalUnhandledExceptionFilter()  + 0x1c bytes   
     kernel32.dll!_UnhandledExceptionFilter@4()  + 0x5e2 bytes   
     ntdll.dll!___RtlUserThreadStart@8()  + 0x369cc bytes   
     ntdll.dll!@_EH4_CallFilterFunc@8()  + 0x12 bytes   
     ntdll.dll!ExecuteHandler2@20()  + 0x26 bytes   
     ntdll.dll!ExecuteHandler@20()  + 0x24 bytes   
     ntdll.dll!_KiUserExceptionDispatcher@8()  + 0xf bytes   
     ntdll.dll!@RtlpLowFragHeapFree@8()  + 0x89 bytes   
     ntdll.dll!_RtlFreeHeap@12()  + 0x7e bytes   
     ole32.dll!CRetailMalloc_Free()  + 0x1c bytes   
     ole32.dll!_CoTaskMemFree@4()  + 0x13 bytes   
     Microsoft.VisualStudio.Editor.Implementation.ni.dll!0daff77b()    
     [Frames below may be incorrect and/or missing, no symbols loaded for Microsoft.VisualStudio.Editor.Implementation.ni.dll]   
     Microsoft.VisualStudio.Editor.Implementation.ni.dll!0daff77b()    
     Microsoft.VisualStudio.Editor.Implementation.ni.dll!0dafdfcd()    
     Microsoft.VisualStudio.Editor.Implementation.ni.dll!0daff642()    
     Microsoft.VisualStudio.Editor.Implementation.ni.dll!0dafdfcd()    
     cslangsvc.dll!CEditFilter::QueryStatus()  + 0x13c bytes   
     cslangsvc.dll!CVsEditFilter::QueryStatus()  + 0x95 bytes   
     mscorlib.ni.dll!5af61753()    
     Microsoft.VisualStudio.Editor.Implementation.ni.dll!0dae99eb()    
     Microsoft.VisualStudio.Editor.Implementation.ni.dll!0dae9a1c()    
     Microsoft.VisualStudio.Platform.WindowManagement.ni.dll!6dce2ae4()    
     Microsoft.VisualStudio.Platform.WindowManagement.ni.dll!6dcdf98c()    
     msenv.dll!CVSCommandTarget::QueryStatusCmd()  + 0x423c bytes   
     msenv.dll!`anonymous namespace’::QueryStatusForController()  + 0x63 bytes   
     msenv.dll!`anonymous namespace’::GetQueryStatusFlags()  + 0x3a bytes   
     msenv.dll!CSurfaceCommandingSupport::IsCommandEnabled()  + 0x1bbb bytes   
     msenv.dll!`anonymous namespace’::DoCommonStateUpdating<CommandUI::Models::IButtonController,`anonymous namespace’::<lambda1> >()  + 0xa2 bytes   
     msenv.dll!CUpdateVisitor::VisitButtonController()  + 0x1b bytes   
     msenv.dll!CControllerVisitorBase::DispatchVisit()  + 0x3bf bytes   
     msenv.dll!CControllerVisitorBase::VisitController()  + 0x22 bytes   
     msenv.dll!CSurfaceCommandingSupport::Update()  + 0x2e bytes   
     msenv.dll!CommandUI::Models::Impl::CControllerBase::Update()  + 0x21 bytes   
     msenv.dll!UpdateChildCollectionWithSeparators()  + 0x17f bytes   
     msenv.dll!CUpdateVisitor::VisitToolBarController()  + 0x2a6 bytes   
     msenv.dll!CControllerVisitorBase::DispatchVisit()  + 0x226 bytes   
     msenv.dll!CControllerVisitorBase::VisitController()  + 0x22 bytes   
     msenv.dll!CSurfaceCommandingSupport::Update()  + 0x2e bytes   
     msenv.dll!UpdateCommandModels()  + 0x147 bytes   
     msenv.dll!CmdUpdateForceInternal()  + 0x28 bytes   
     msenv.dll!CMsoComponent::FDoNonPeriodicIdle()  + 0x991 bytes   
     msenv.dll!CMsoComponent::FDoIdle()  + 0x17 bytes   
     msenv.dll!SCM::FDoIdleLoop()  + 0xf3 bytes   
     msenv.dll!SCM::FDoIdle()  + 0xc7 bytes   
     msenv.dll!SCM_MsoStdCompMgr::FDoIdle()  + 0x13 bytes   
     msenv.dll!CMsoCMHandler::EnvironmentMsgLoop()  + 0x74a bytes   
     msenv.dll!CMsoCMHandler::FPushMessageLoop()  + 0x79 bytes   
     msenv.dll!SCM::FPushMessageLoop()  + 0x8c bytes   
     msenv.dll!SCM_MsoCompMgr::FPushMessageLoop()  + 0x2a bytes   
     msenv.dll!CMsoComponent::PushMsgLoop()  + 0x28 bytes   
     msenv.dll!VStudioMainLogged()  + 0x22a bytes   
     msenv.dll!_VStudioMain()  + 0x78 bytes   
     devenv.exe!util_CallVsMain()  + 0xdb bytes   
     devenv.exe!CDevEnvAppId::Run()  + 0x693 bytes   
     devenv.exe!_WinMain@16()  + 0x88 bytes   
     devenv.exe!operator new[]()  + 0xa59d bytes   
     kernel32.dll!@BaseThreadInitThunk@12()  + 0x12 bytes   
     ntdll.dll!___RtlUserThreadStart@8()  + 0x27 bytes   
     ntdll.dll!__RtlUserThreadStart@8()  + 0x1b bytes   

Prudential User Experience Fail

I was updating my life insurance beneficiaries (for insurance provided by my employer) and I had just added my wife as a primary beneficiary and then indicated that I wanted to add another. I must be a total screw up:

You have recently updated your beneficiary details. Please wait one day to perform one more transaction.

Uh – I’m allowed one “transaction” per day? I guess that’s one way to make a scalable web system and not overload the database system too much.

Silverlight Analog/Retro Flip Numbers

I’m not sure what to call these exactly. I’ve created a relatively simple Silverlight 4 control that emulates the old mechanical flip style numbers (or letters) displays found at airports and in old clock-radios.

image

I call it the RetroFlipper.

It’s easy to use (at least for my needs). Declare an instance of the control in XAML:

xmlns:wpcontrols="clr-namespace:WiredPrairie.Controls;assembly=WiredPrairie.RetroFlipperControl"             

 

        <wpcontrols:RetroFlipper Margin="5,20" 
                                 x:Name="numberFlip100" Grid.RowSpan="1" Grid.Column="1"/>

And then respond to the “Flipped” event and set the “Text” property as needed.

            numberFlip0.Flipped += new EventHandler(numberFlip1_Flipped);
            numberFlip0.Text = "0"; //(0, 0);

The default animation speed can be adjusted:

numberFlip0.AnimationSpeed = 1;

It’s a percentage – 1.0 is the default. If you want the animation of the flip to be half speed for example, just set it to .5.

The class that drives the demo is really simple:

public partial class MainPage : UserControl
{
    private DispatcherTimer _timer;
    private int _inc = 0;

    public MainPage()
    {
        InitializeComponent();
        numberFlip0.Text = "0"; //(0, 0);
        numberFlip0.AnimationSpeed = 1;
        numberFlip10.Text = "0"; //(0, 0);
        numberFlip10.AnimationSpeed = .7;
        numberFlip100.Text = "0"; //(0, 0);
        numberFlip100.AnimationSpeed = .4;
        _timer = new DispatcherTimer();
        _timer.Interval = TimeSpan.FromSeconds(.5);
        _timer.Tick += new EventHandler(_timer_Tick); 
        
    }

    void _timer_Tick(object sender, EventArgs e)
    {
        int current = _inc;
        int next = ++_inc;
        if (next % 10 == 0)
        {
            numberFlip10.Text = Math.Floor(next / 10 % 10).ToString(); 
        }
        if (next % 100 == 0)
        {
            numberFlip100.Text = Math.Floor(next / 100 % 100).ToString(); 
        }

        numberFlip0.Text = (next % 10).ToString();            
    }

    private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
    {
        _timer.Start();
    }
}

(And no, it doesn’t handle numbers > 1000).

Building the control required a few tricks.

The most interesting was that I decided to use 4 layers to actually represent and animate the flip cards:

image

Using a few OpacityMasks

<Border.OpacityMask>
    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="Transparent" Offset="0.5"/>
        <GradientStop Color="Black" Offset="1"/>
        <GradientStop Color="Black" Offset="0.5"/>
        <GradientStop Color="Transparent"/>
    </LinearGradientBrush>
</Border.OpacityMask>

and some creative PlaneProjection and animations,

<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationX)" Storyboard.TargetName="backBottom">
    <EasingDoubleKeyFrame KeyTime="0:0:0.17" Value="270"/>
    <EasingDoubleKeyFrame KeyTime="0:0:0.27" Value="180"/>
    <EasingDoubleKeyFrame KeyTime="0:0:0.30" Value="220"/>
    <EasingDoubleKeyFrame KeyTime="0:0:0.32" Value="180"/>
</DoubleAnimationUsingKeyFrames>

it’s possible to create the illusion of the mechanical parts moving.

Any text may be set into the Text property – it’s automatically sized to fill. So, it could be words, double digits, anything you’d like, as long as it’s text.

In any case, the demo is here.

The source code, licensed under BSD, is here.

Enjoy.

Visual Studio 2010 Crashes

Visual Studio 2010 crashes a lot while doing WPF and Silverlight development for me. Anyone else having that same problem? It happens frequently after resuming my PC from ‘sleep’ or ‘hibernation’ …, but that could be a coincidence.

Microsoft Visual Studio 2010 has stopped working

Interestingly, one of the functions in the stack trace is a PNG encoder. PNG’s are my image file of choice in Silverlight and web applications. I know the project that was currently loaded contains several PNG files. Maybe there’s no connection.

     ntdll.dll!_RtlReportCriticalFailure@8()  + 0x57 bytes   
     ntdll.dll!_RtlpReportHeapFailure@4()  + 0x21 bytes   
     ntdll.dll!_RtlpLogHeapFailure@24()  + 0xa1 bytes   
     ntdll.dll!_RtlFreeHeap@12()  + 0x4ffeb bytes   
     kernel32.dll!_HeapFree@12()  + 0x14 bytes   
     WindowsCodecs.dll!WPF::ProcessHeapImpl::Free()  + 0x1c bytes   
>    WindowsCodecs.dll!DynArrayImpl<0>::~DynArrayImpl<0>()  + 0x104f bytes   
     WindowsCodecs.dll!CPngFrameEncode::~CPngFrameEncode()  + 0x66 bytes   
     WindowsCodecs.dll!CPngFrameEncode::`vector deleting destructor'()  + 0xd bytes   
     WindowsCodecs.dll!CMILCOMBase::InternalRelease()  + 0x24 bytes   
     WindowsCodecs.dll!CResetStream::Release()  + 0xe bytes   
     wpfgfx_v0400.dll!MILRelease()  + 0xe bytes   
     PresentationCore.ni.dll!5e74f2b1()    
     [Frames below may be incorrect and/or missing, no symbols loaded for PresentationCore.ni.dll]   
     PresentationCore.ni.dll!5e74f2b1()    
     PresentationCore.ni.dll!5e74f2fe()    
     clr.dll!_CallDescrWorker@20()  + 0x33 bytes   
     clr.dll!_CallDescrWorkerWithHandler@24()  + 0x8a bytes   
     clr.dll!MethodDesc::CallDescr()  + 0x148 bytes   
     clr.dll!MethodDesc::CallTargetWorker()  + 0x21 bytes   
     clr.dll!SafeHandle::RunReleaseMethod()  + 0xc7 bytes   
     clr.dll!SafeHandle::Release()  + 0x7b257 bytes   
     clr.dll!SafeHandle::Dispose()  + 0x2d bytes   
     clr.dll!SafeHandle::Finalize()  + 0xb0 bytes   
     mscorlib.ni.dll!617b913b()    
     mscorlib.ni.dll!617b90b2()    
     clr.dll!MethodTable::SetObjCreateDelegate()  – 0x1fc874 bytes   
     clr.dll!MethodTable::CallFinalizer()  + 0x75 bytes   
     clr.dll!WKS::CallFinalizer()  + 0x80 bytes   
     clr.dll!WKS::GCHeap::TraceGCSegments()  – 0x1f9fc6 bytes   
     clr.dll!WKS::GCHeap::TraceGCSegments()  – 0x1fa08a bytes   
     clr.dll!WKS::GCHeap::FinalizerThreadWorker()  + 0xb1 bytes   
     clr.dll!Thread::DoExtraWorkForFinalizer()  – 0xc291e bytes   
     clr.dll!Thread::ShouldChangeAbortToUnload()  + 0x1251e bytes   
     clr.dll!Thread::ShouldChangeAbortToUnload()  + 0x125d9 bytes   
     clr.dll!ManagedThreadBase_NoADTransition()  + 0x35 bytes   
     clr.dll!ManagedThreadBase::FinalizerBase()  + 0xf bytes   
     clr.dll!WKS::GCHeap::FinalizerThreadStart()  + 0xfb bytes   
     clr.dll!Thread::intermediateThreadProc()  + 0x48 bytes   
     kernel32.dll!@BaseThreadInitThunk@12()  + 0x12 bytes   
     ntdll.dll!___RtlUserThreadStart@8()  + 0x27 bytes   
     ntdll.dll!__RtlUserThreadStart@8()  + 0x1b bytes