Philip Hendry's Blog

July 20, 2011

Highlighting Selected Text automatically in Visual Studio

Filed under: Dev Tools, Tip, Visual Studio — philiphendry @ 1:40 pm

I’ve used Eclipse and always loved the way that any selected text is automatically discovered elsewhere in the current file and highlighted – this is also available in Notepad++.

Plugins to the rescue! There’s WordLight for Visual Studio 2008 and another called Highlight all occurrences of selected word.

November 19, 2010

Javascript Intellisense in Visual studio 2008

Filed under: Tip, Visual Studio — philiphendry @ 12:14 pm

I don’t know about you but I’m a big fan of intellisense and for a while I’ve been using a simple hack to get javascript intellisense working. For example, I’ve just added the following lines to the master page :

<%-- A simple hack to fool Visual Studio into giving us intellisence for javascript --%>
<%if(false) {%><script type="text/javascript" language="javascript" src="ClientResources/Javascript/uitools.js"></script><%}%>
<%if(false) {%><script type="text/javascript" language="javascript" src="ClientResources/Javascript/jquery-1.3.2-vsdoc.js"></script><%}%>
<%if(false) {%><script type="text/javascript" language="javascript" src="/../lib/jqueryplugins/jquery.rms.ajaxprogress.js"></script><%}%>
<%if(false) {%><script type="text/javascript" language="javascript" src="/../lib/jqueryplugins/jquery.rms.ajaxhistory.js"></script><%}%>

There are a few things to note :

  • The if (false) is the neat little hack that means this will never get rendered but Visual Studio will still parse and provide intellisense for the references.
  • I’m including the jQuery using the vsdoc version which means the intellisense as slightly more information in it. For example :

    image
  • To extend our own javascript files with vsdoc info see Scott Guthries blog – it’s just a case of formatting the javascript comments.
  • You can also use parents paths out of the web site and into the lib folder!
  • This will also work with style sheets which means the underlining of styles telling you they don’t exist goes away! Admittedly you have to pick either a default one or a customer stylesheet but that’s better than nothing!
<%if(false){%><link href="../styles/Styles.css" rel="Stylesheet" type="text/css" /><%} /* Weird trick to resolve css references in the page without affecting compiled output */%>

September 17, 2010

Creating a shortcut key in Visual Studio 2008 to launch TortoiseSvn Diff

Filed under: Visual Studio — philiphendry @ 9:18 am

I wanted a quick and easy way to launch the TortoiseSvn configured diff tool showing me the differences between my saved working copy and the head version in source control. This article shows how.

First configure the external tools by selecting Tools –> Externals Tools… from the VS menu. Then add entries for the Title, Command, Arguments and Initial directory as shown below. The Command is the path to TortoiseProc.exe and those $(<param>) commands are built in parameters replaced by Visual Studio (press the black arrow to see a list.)

image

To aid debugging it’s useful to select ‘Prompt for arguments’ to see what VS is creating for the list of arguments.

Once done follow the instructions provided by Microsoft to assign a shortcut key to the external tool. Here’s how my Tools menu looks with diff assigned the CTRL+SHIFT+ATL+D keypress :

image

Update:

Here are another couple of ideas. Add TortoiseProc.exe /command:update /path:”$(solutionpath)” and the same again for the commit command. Now I can press Ctrl+Alt+Shift+C to commit any solution changes or Ctrl+Alt+Shift+U to update the solution to the head revision.

For a list of available TortoiseProc commands see http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-automation.html

August 19, 2010

Profiling Unit Tests in Visual Studio 2008

Filed under: Code, Dev Tools, Visual Studio — philiphendry @ 8:53 pm

I had a particular set of tests that when run with a large test data set seemed to be taking a long time to run and so I wanted to check that it was simply the setup and teardown of the tests was taking the time and not the tests itself.

I could have manually put some instrumentation into my tests but I’d rather use a tool for the job and therefore I wanted to run the profiler for my test. It turns out you can do this for MSTest fairly easily. First load the test view (Test –> Windows –> Test View) and seeing as I was using Resharper test runner, this is a fairly important step! Now from the context menu of the test you want to run select ‘Create Performance Session’ :

image

Up pops the Performance Wizard which basically asks whether to Sample or Instrument the process – I chose the later for accuracy. You now have the ‘Performance Explorer’ window with the configured performance profile :

image  

Now all I have to do is click the third button on the toolbar ‘Launch with Profiling’ which runs the process and once completed presents me with a summary of the worst performers :

image

At this point all you have to do is analyse the results and figure out where the slowest sections are. I actually found it easiest to change the view from ‘Summary’ to ‘Modules’ then drill down to the method I new was the method under test and confirm that it was running within an acceptable timescale.

Of course, if you can’t afford Visual Studio Team System then there are other offerings out there… and jetBrains’ dotTrace is one of them which is probably going to cost at lot less!

August 9, 2010

Manually converting a Visual studio project to include asp.net mvc Context menus

Filed under: ASP.NET MVC, Visual Studio — philiphendry @ 2:26 pm

I’ve got a Visual Studio project that includes ASP.NET MVC controllers, models and view utilities but because it was not a Web Application I wasn’t getting any of the context menus for adding MVC elements. For example, ‘Controller’ was missing from the Add menu :

image

To fix this I unloaded the project, edited the csproj and added the following line :

  <PropertyGroup>
    ...
    <ProjectTypeGuids>{603c0e0b-db56-11dc-be95-000d561079b0};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
    ...
  </PropertyGroup>

Using a list of known project type guids I could identify the second guid which is Windows (C#) whilst the first I found by googling and checking a test ASP.NET MVC application I created with Visual Studio.

June 8, 2008

Failed to map the path ‘/’.

Filed under: .Net, Dev Problem, Visual Studio — philiphendry @ 5:32 pm

I was trying to run a simple MVC# example to see how it all hung together and whilst I found the WinForms example up and running within a couple of minutes the WebForms was a little harder and was failing with ‘Failed to map the path ‘/’.’

A few minutes consultation with support (aka Google) didn’t seem to suggested anything. But a moment later (and a slap of the forehead) I’d realised the problem – I was running Visual Studio as myself instead of Administrator and the default web server was struggling.

If someone out there knows which folder needs the appropriate permissions then let me know but for the moment I’ll just run as Administrator :(

April 21, 2008

Debugging .Net on Production Servers

Filed under: .Net, Dev Tools, Microsoft, Visual Studio — philiphendry @ 12:58 pm

I’ve been meaning to look at debugging .Net apps on production servers for a while now since each time I’ve tried with DevEnv.exe I’ve found I can attach to the process, load up C# source, set breakpoints and step through the code but I can’t see the contents of any of the variables.

I’m sure I’ll move forward on this problem at a later date but for now I thought I’d jot down a url that discusses a SOSEX extension for use with WinDBG. I’ve not used it at all yet so may well be back with an update to this blog entry later on!

March 27, 2008

Using WinMerge with TFS

Filed under: Dev Tools, Visual Studio — philiphendry @ 5:15 pm

Rory Primrose has done the hard work for this :)

Redirecting Assembly Versions in .Net

Filed under: .Net, Dev Problem, Microsoft, Visual Studio — philiphendry @ 11:29 am

We were having a problem with deserialization on one of our projects and although the cause seemed obvious the solution wasn’t!

The error we were getting is at the bottom of this post. It says that one type cannot be converted to another type but both types are the same! However, what it isn’t highlighting is that the version number of the assembly that these two types come from is different. When an object is serialized the assembly versions of the objects being serialized are being stored too and when the deserializing these versions are compared to what can be created and if they don’t match the error is thrown.

One solution (I thought) would be to changed the AssemblyFormat property on the binary formatter as shown below. However, this simply does not work. There’s been a bug raised with Microsoft for this issue a year ago but it doesn’t look like it’s been fixed!

BinaryFormatter formatter = new BinaryFormatter();
formatter.AssemblyFormat = FormatterAssemblyStyle.Simple;

So the next option that was suggest by several other blogs was to implement a SerializationBinder that can intercept the requests for the assemblies to create and strip off the assembly version. This, however, is just plain awful since we’re now writing even more code to a simple problem. Here’s some template code:

class Program
    {
        static void Main(string[] args)
        {
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Binder = new SimpleBinder();
        }
    }

    class SimpleBinder : SerializationBinder
    {
        public override Type BindToType(string assemblyName, string typeName)
        {
            /* Implement code to modify the typeName */
            return Type.GetType(typeName);
        }
    }

The third option, and certainly the simplest, is to modify the assembly bindings to redirect one version of an assembly to another. In the example below the bindingRedirect allows requests for version 1.0.0.0 of this particular assembly to be serviced by version 2.0.0.0. So long as we’re sure the deserializing functionality is compatible, this solves the problem without having to change any code.

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
        <assemblyIdentity name="Configuration" publicKeyToken="........." culture=""/>
        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
        <codeBase href="C:\bin\Configuration.dll" version="2.0.0.0" />
    </dependentAssembly>
</assemblyBinding>

Here’s the error :

Object of type ‘com.iMeta.metaCore.Utilities.Base.Pair`2[System.Type,System.Collections.Generic.List`1[M.Box.Core.Command]][]‘ cannot be converted to type ‘com.iMeta.metaCore.Utilities.Base.Pair`2[System.Type,System.Collections.Generic.List`1[M.Box.Core.Command]][]‘. (Exception Type: ArgumentException, Stack:    at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
   at System.Reflection.RtFieldInfo.InternalSetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture, Boolean doVisibilityCheck, Boolean doCheckConsistency)
   at System.Runtime.Serialization.SerializationFieldInfo.InternalSetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture, Boolean requiresAccessCheck, Boolean isBinderDefault)
   at System.Runtime.Serialization.FormatterServices.SerializationSetValue(MemberInfo fi, Object target, Object value)
   at System.Runtime.Serialization.ObjectManager.CompleteObject(ObjectHolder holder, Boolean bObjectFullyComplete)
   at System.Runtime.Serialization.ObjectManager.DoNewlyRegisteredObjectFixups(ObjectHolder holder)
   at System.Runtime.Serialization.ObjectManager.RegisterObject(Object obj, Int64 objectID, SerializationInfo info, Int64 idOfContainingObj, MemberInfo member, Int32[] arrayIndex)
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.RegisterObject(Object obj, ParseRecord pr, ParseRecord objectPr, Boolean bIsString)
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ParseObjectEnd(ParseRecord pr)
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Parse(ParseRecord pr)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)

March 5, 2008

Microsoft Certification

Filed under: Microsoft, Visual Studio — philiphendry @ 8:32 am

I noticed a blog entry that neatly summarised the exam tracks available at Microsoft but more importantly linked the Visual Studio 2008 exam tracks that should be released imminently – register now and you get a 40% discount!

Theme: Shocking Blue Green. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.