Friday, June 29, 2012

Visual Studio 2010 Web Deploy improvements

Microsoft announced some important improvements in the Visual Studio 2012 Web Deploy.

I noticed that when you install the new Windows Azure SDK for Visual Studio 2010, you will also get the same updates for the Visual Studio 2010 Web Publishing Experience.

These updates include some of the following  features:

  • Updated Web Publish dialog
  • Support to import publish profiles (.publishSettings files)
  • Support to configure EF Code First migrations during publish
  • Support to create web packages in the publish dialog
  • Publish profiles now a part of the project and stored in version control by default
  • Publish profiles are now MSBuild files
  • Profile specific web.config transforms

After installing the SDK, you get a new Publish dialog:

PublishDialogProfile

You can now import a .publishsettings file(provided by many web host sites and by Windows Azure) and you can also manage your publish profiles.

One of the things I like the most is that these publish profiles are now stored as a part of your project under the folder Properties\PublishProfiles as .pubxml files:

image

These .pubxml files are  just normal MSBuild files so you can modify these files in order to customize the publish process. You can also leverage these publish profiles to simply publishing from the command line:

msbuild.exe SOFAServicesHost.csproj /p:DeployOnBuild=true;PublishProfile="SOFA – Release";Password={INSERT-PASSWORD}

Thursday, June 28, 2012

TFS: Automatically exclude from Source Control

When you try to add items to TFSsource control, it automatically excludes certain folders and files:

image

But what if you want to change the default list of excluded folders and files? In Visual Studio 2010 you can do this by changing the following two registry keys:

  1. HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\TeamFoundation\SourceControl\AddOptions\ExcludeMasks
  2. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\TeamFoundation\SourceControl\AddOptions\ExcludeMasks

Add or remove some items from the list separated by a semicolon. Next time you’ll open Visual Studio, the list will be changed.

image

Wednesday, June 27, 2012

Coolest OneNote feature EVER: search text in images

Last week at Community Day 2012, in his session Little productivity tools every professional developer should know about, Dennis Doomen shared a great tip about one of the cool features inside OneNote. 

OneNote automatically does an OCR scan on anything you inserted into OneNote. Right-clicking on any picture or screenshot you inserted. Select “Make Text in Image Searchable” and then make sure the correct language is selected.

image

Now, you can copy text from the Picture. Simply right-click on the picture, and select “Copy Text from Picture”.

image

To make this even cooler, OneNote will index all OCR results and make them available through the search function.  Simply enter your search query in the search box on top right, and OneNote will automatically find all instances of that term in all of your notebooks. It even highlights the search term in the image!

image

image

Thanks Dennis for the great tips!

Tuesday, June 26, 2012

Testing for Continuous Delivery

The Microsoft Patterns & Practices team released a new document about ‘Testing for Continuous Delivery with Visual Studio 2012 RC’.

“This guide describes how testing has been changing over the years and how the testing infrastructure you can build with Visual Studio 2012 RC will help you achieve continuous delivery of your software projects. This guide provides an end-to-end walkthrough of the testing scenarios supported by the Visual Studio 2012 RC infrastructure. It will help testers and developers use Team Foundation Server effectively as an application lifecycle management solution for testing and supporting products.

This guide helps you

  • Understand how testing is changing with the new tools available to testers.
  • Set up the testing infrastructure.
  • Use the tools for unit testing.
  • Understand how the lab environment works and how it supports a project.
  • Understand the power of the manual testing tools.
  • Learn to use the tools for automated testing.
  • Use the tools in the testing toolbox.

In addition, this guidance describes testing with the Visual Studio 2012 RC testing infrastructure composed of Team Foundation Server, Build System, Test Controller, and SharePoint, and discusses the supported reporting functionality that can help track various test velocities and code coverage. This guide also helps you understand the critical ways in which your testing processes will change with the use of these new tools.

After reading this book, you will be familiar with how to set up Team Foundation Server in Visual Studio 2012 RC and its corresponding infrastructure components in a number of configurations. You'll also have a good understanding of how to use the Visual Studio 2012 RC testing tools such as Lab Manager and code coverage tests to achieve a far more effective testing experience and full application lifecycle management for your system.”

The related code samples can be downloaded from Codeplex.

ALM Maturity

Monday, June 25, 2012

NHibernate error: Possible non-threadsafe access to the session

The moment you think you’ve seen all possible NHibernate errors, a new one pops up Smile.

A colleague asked me to have a look at a query he created using the QueryOver syntax. But instead of getting the correct results, the query failed with the following error message:

“Possible non-threadsafe access to the session.”

I was 100% sure that we were working on a single thread, so I had no idea what caused this error. Even stranger is that when I switched from an  IStatelessSession to a normal ISession, the error disappeared…

The NHibernate JIRA brought the solution:

In a stateless session, queries load objects in a two-phase process: in the first phase, a temporary persistence context is populated with empty objects; in the second phase, the objects' member data is read from the database. If an object contains an association or a collection, the query performs a recursive call to the session's get() method. This clears the temporary persistence context.
If the parent object contained any other associations to be read as part of the second phase, Hibernate threw an assertion because the associations cannot be found in the persistence context.


This has been fixed by introducing a new method: <literal>org.hibernate.engine.PersistenceContext.isLoadFinished()</literal>. This method tells StatelessSession when to clean the temporary persistence context.

And indeed when I switched to the most recent NHibernate version, the problem was gone!

Friday, June 22, 2012

Waterfall neither works for User Interface design

For a recent project we hired a design agency to help us create and design an attractive user interface for our users. So after some meetings with our end users, a few weeks of designer magic, the big moment was there, they going to present us ‘THE DESIGN’.

So I entered the meeting full of anticipation, eager to learn about the cool things the designers have created. So after a few PowerPoint slides, we got to see nicely designed and polished screens of our user interface, followed by the obvious question; “And guys, what do you think?”. There wasn’t much we could say, it certainly looked nice and the whole design was finished. But it doesn’t seem there was much room left for discussion or change.

After leaving the meeting, I didn’t feel satisfied. Although the result looked good, something was missing…

Dilbert_UX

Last week at NDC I had to think again about this meeting when I was following the Creating User Experiences: Unlocking the Invisible Cage session by Billy Hollis. In this session he explains that the design agency we hired took a completely wrong approach. By doing all the user meetings first and then creating a finished design(doesn’t this sound like waterfall to you?), users feel it hard to discuss about the core concepts of the application. Instead they discuss about some colors and maybe the position of a button here and there. But they’ll never discuss the concept itself: ‘Is this the correct design for this application?’.

Instead applying Agile techniques to the design process will lead to a far better design and user experience. By first creating multiple very simple, sketchy screen mockups, trying out completely different approaches, you’re giving the users room for discussion. They can talk about what designs they like, what designs they don’t like, why they like/dislike it, and so on. This is far more useful feedback than saying ‘this button should be green instead of red’.  The designer can then take all this input and create a new set of designs applying the concepts the users liked in the first session.

Of course this will probably take some extra time, but we end with the application the user need instead of the application the designer ‘thinks’ the user need.

Thursday, June 21, 2012

Git(hub) for .NET developers

If you missed our session at Community Day 2012 or you want to get the slides, I’ve uploaded the presentation to Slideshare.

I want to thank Gill and co for the speaking opportunity and Kristof Mattei to help me making this a great session!

Optimize the performance of your web applications: Don’t use runAllManagedModulesForAllRequests="true”.

In a lot of web applications I’ve seen (and created myself), the runAllManagedModulesForAllRequests is set to true inside the web.config. In a lot of articles, blog posts and so on… this is mentioned as a good idea. It’s even a default when you create a new ASP. NET MVC application.  However last week I was listening to a Hanselminutes podcast with Nathanael Jones where they said that this was really a bad idea and had a negative impact on the overall performance of your web application.
<system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

Running these modules for all your dynamic content is fine. However doing the same thing for all your static content  is pure overhead and offers no benefits. All your registered HTTP modules run on every request, not just managed requests (e.g. .aspx). This means modules will run on every .jpg, .gif, .css, .html, .pdf etc. 
How can we fix this?
In fact if you are using IIS 7.5 there is not much you need to do, just remove the modules section and you are done.


Remark: Some people on StackOverflow mentioned they had errors after removing this section, in that case I suggest installing the following update: http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=5272

Wednesday, June 20, 2012

dotTrace Memory profiler keeps connecting.

To investigate a memory leak in one of my applications, I'm trying to use  JetBrains dotTRACE Memory profiler. I specified the url of my web application and started a profiling session.

But all I got was the following screen:

dotTraceProfiling

But no luck… instead dotTrace keeps showing ‘Connecting’ but the Mark Memory and Dump Memory buttons never become enabled.

I had no idea why this didn’t work. In the end I noticed that dotTrace Memory 3.5 has a x64 and x32 version. And I had installed the 32bit version on my 64bit machine. After removing the 32bit version and installing the 64bit version instead, the "Connecting" got away and I finally was able to trace my application.

image

Tuesday, June 19, 2012

RavenDB: accessing a specific database using the HTTP API

RavenDB offers the following options to access it:
  • .NET Client API: The Client API allows easy access to it from any .NET language. The .NET Client API exposes all aspects of the RavenDB server to your application in a seamless manner.
  • HTTP API: RavenDB provides an HTTP API for accessing and manipulating data on the server. This API sits next to the C# Client API, providing most of the same functionality, but with a platform agnostic, web friendly interface. Using the HTTP API, it's possible to write a fully functioning RavenDB application using just Javascript and HTML.
For a demo application I’m building I wanted to use the HTTP API but I only had one problem, what’s the correct URL to access data in a specific RavenDB database?
To access data(e.g. docs) in the default database, you can use:
curl -X GET http://localhost:8080/docs/locations/1



But I created a specific database instance, what’s the impact on the URL? After some trial and error I discovered that the syntax is the following:

curl -X GET http://localhost:8080/databases/{databaseName}/docs/{document_id}

Monday, June 18, 2012

VS 20120 RC ALM Virtual Machine

Microsoft released an update of the Visual Studio 2012 RC ALM Virtual Machine. This is the fastest way to understand what is new for application lifecycle management in this release.  This virtual machine is pre-configured with all of the necessary software and sample data for you.

Visual-Studio-2012-Logo

It includes 18 hands-on-labs / demo scripts. 6 of these were upgraded from the Visual Studio 11 ALM virtual machine, 11 of these were upgraded from the older Visual Studio 2010 ALM virtual machine, and one is brand new, highlighting the PreEmptive Analytics integration in Team Foundation Server 2012.

Friday, June 15, 2012

Searching TFS work items in Visual Studio 2010

Looking for a way to search work items in Visual Studio 2010? Check out the Search Work Items addin.

“This plugin for Team System puts a little search box right into Visual Studio to make it easy to find work items. It is an addin for Team Foundation Client (Team Explorer) and is accessible from the Team menu when you're connected to a Team Foundation Server and is also available from a VS Toolbar. You just type in some search text and it runs a work item query for you showing you results across the work item store, or enter a work item ID to immediately open a specific work item.” 

After installing it, a work item search box is added to the Visual Studio toolbar.

 image

Enter a search term,hit [ENTER] and a work item query is invoked behind the scenes. By default the query will search for results inside the Title, History, and Description fields of your work items.

image

If you want to modify which work item fields are searchable, type in "--template" (no quotes) into the search box and hit enter. This will open the search template. Just add another "Or" statement, pick the field name, select an operator, type "[search]" (no quotes) in the value field, and hit ctrl + s to save.

SearchTemplate

Thursday, June 14, 2012

IIS: Management Service Delegation not visible

Today I was configuring our new production environment to enable Automating Deployment with Microsoft Web Deploy. The problem was that I couldn’t find the the Management Service Delegation icon on my Windows Server 2008 R2 server. Luckily, the IIS forums brought me the solution.

It seems that when you install Web Deploy using the Web Platform Installer, not all features are available. So I went back to the download page but this time I select the x64 link instead of clicking on the big Install button.

image

After downloading the package I chose to change my installation. The IIS 7 Deployment Handler and Management Service Delegation UI were shown as not being installed. So I checked this features and continued the installation. After reloading the IIS manager, the Management Service Delegation was finally there.

ManagementServiceDelegation

Wednesday, June 13, 2012

Learn by doing: Linq koans

You want to learn Linq, or increase your knowledge about it. Let’s introduce Linq koans. It allows you to learn LINQ by doing. Based on unit tests, you scroll down the class, fixing each test.(You have to replace the ‘___’ with the correct value.

Koans allow you to 'try out' aspects of a language while working in the language. In these koans, you just download the project, unzip it and open it in VS2010. Work with source the files in the following order:

1) LinqSynax.cs

2) LinqLambdaSyntax.cs

3) ExtendedLinqLamdbaSyntax.cs

As you change the blank (variable) to the correct answer and get the tests to pass, be sure to ask yourself after you get a green bar for each method, 'What did I just learn?'

A sample test:

[TestMethod]
public void LinqResults()
{
Microwavable result = (from x in ObjectsInMicrowave
where x.Name == "Ping Pong Ball"
select x).First();
Assert.AreEqual(___, result.Name);
}

Tuesday, June 12, 2012

JSON to C#

With the increased interested and usage of web(or REST) API’s, sooner or later you’ll have to consume an external JSON-producing service. As a C# developer  it's nice to have locally-defined static types that you can code against. But writing all these classes that match the JSON data is a boring and cumbersome task.

Let’s introduce json2csharp This tool will takeover this task and generates C# classes from JSON for you.

image

How to use it?

Type or paste a JSON string or a URL that produces JSON into the large text area, then click the Generate button.

Let’s take the results from this twitter search(http://search.twitter.com/search.json?q=c%23) and convert it to some C# objects

The JSON result(looks like a lot of work to convert this ourself)…
image
The generated C#objects(clean and simple)

image

Monday, June 11, 2012

NDC 2012: a happy grain of sand

I’m just back from an inspiring trip to NDC Oslo. As always it was a great and fun event. I learned a lot and know what I’ll be studying the next few months…

It all started with an amazing and funny keynote "A happy grain of sand" by Aral Balkan, where he talks about (user) experience design.If you missed it, check it out(you can skip the first minutes if you don’t want to see the singing… yes, indeed the singing Glimlach)

image

Friday, June 8, 2012

System.InvalidOperationException: Dispatcher processing has been suspended, but messages are still being processed.

In a WPF application, when I try to open a specific page, the application crashes with the following error message:
“System.InvalidOperationException: Dispatcher processing has been suspended, but messages are still being processed. at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)”
When I looked at the code, I was calling a method on my ViewModel when a specific event was triggered on my view. Inside this method I try to open a MessageBox and show a warning.
The view code:
private void SampleView_Load(object sender, EventArgs args)
{
            this
               .OnEventTrigger(grdProducts, "SizeChanged")
               .ExecuteCommand("Open1");

}

The viewmodel code:
 
public void Open1()
{
 _windowManager.OpenMessageBox("Open 1 method called.", false);
}

The ExecuteCommand() is a piece of functionality I created myself to have a fluent API to link events to commands(method call on the view model).

When I searched for more information about this exception, I found the following:

The exception is done on purpose to prevent reentrancy bugs caused by weirdness resulting from altering the visual tree, while such an event (which itself has been triggered by the visual tree altering) is firing. If you really must confirm something when the state of a UI element changes, delaying with Dispatcher.BeginInvoke is probably the right thing to do.

This code is already triggered before the form is fully loaded, and this explains why the exception happens. To solve it I changed my ExecuteCommand implementation to invoke the method on the ViewModel on the UI thread:
  

private void ExecuteCommand(Command command)
{
 if (command == null)
     return;

 Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => command.Execute(null)));
}

Thursday, June 7, 2012

Cannot convert anonymous method to type 'System.Delegate' because it is not a delegate type

Last week I tried to pass an anonymous method as a parameter to a method that excepted a delegate. As far as I know, an anonymous method is just an alternative syntax for a delegate. So I expected that it should work. However no luck, the compiler complained with the following error:
“Cannot convert anonymous method to type ‘System.Delegate’ because it is not a delegate type’.”
If anyone can explain me why this doesn’t work, you’re welcome.
In the meanwhile, casting did the trick.
Before:
 Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Normal, () => this.Command.Execute(null)); //Does not compile

After:
 Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => this.Command.Execute(null)));

Wednesday, June 6, 2012

TF80067: The data in the work item is not valid or you do not have permission to modify the data.

When trying to open the Iteration Backlog.xlsm file in Team Explorer, I’m getting the following error:

“TFS80076: The data in the work item is not valid or you do not have permissions to modify the data. Please correct the problem and retry.”

clip_image002

No idea what I did wrong. The only thing I changed were the iterations. So I renamed the first iteration back from ‘Sprint 1’ to the original name ‘Iteration 1’. Afterwards the document opened fine.

Note: Afterwards I found this post on the MSDN forums. There someone mentions that the issue is solved if you also update the related queries after changing the iteration name.

Tuesday, June 5, 2012

‘Strict Mode’ in JavaScript

If you looked at some of the more recent JavaScript samples or had a look at the Windows 8 JavaScript applications, you’ve probably seen the ‘use strict’ statement before. But what is it and why use it?

By applying the ‘use strict’ statement inside your JavaScript, you are enabling Strict Mode. Strict Mode offers a set of enhancements to the JavaScript language and introduces better error-checking into your code. When you use strict mode, you cannot, for example, use implicitly declared variables, or assign a value to a read-only property, or add a property to an object that is not extensible.

Restrictions

It introduces the following restrictions to your code(source: MSDN):

Language Element Restriction
Variable Using a variable without declaring it.
Read-only property Writing to a read-only property.
Non-extensible property Adding a property to an object whose extensible attribute is set to false.
delete

Deleting a variable, a function, or an argument.

Deleting a property whose configurable attribute is set to false.

Duplicating a property Defining a property more than once in an object literal.
Duplicating a parameter name Using a parameter name more than once in a function.
Future reserved keywords Using a future reserved keyword as a variable or function name.
Octals Assigning an octal value to a numeric literal, or attempting to use an escape on an octal value.
this The value of this is not converted to the global object when it is null or undefined.
eval as an identifier The string "eval" cannot be used as an identifier (variable or function name, parameter name, and so on).
Function declared inside a statement or a block You cannot declare a function inside a statement or a block.
Variable declared inside an eval function If a variable is declared inside an eval function, it cannot be used outside that function.
Arguments as an identifier The string "arguments" cannot be used as an identifier (variable or function name, parameter name, and so on).
arguments inside a function You cannot change the values of members of the local arguments object.
arguments.callee

Not allowed.

with Not allowed.

 

Where can I use Strict Mode?

Strict Mode is part of the new EcmaScript 5 standard. For a list of browsers that already support this feature: http://caniuse.com/use-strict . But even if you have to target some browsers that not yet support this standard, I recommend start using Strict Mode today.  You’ll not get compiler errors on these browsers but it has no negative on your application and it forces you to follow a set of recommended best practices.

If you are a Windows 8 Metro style apps HTML/JS developer, Strict Mode is automatically added to the project templates in Visual Studio 11 as WinJS supports Strict Mode.

How to enable Strict Mode?

That’s the easiest part, just add the "use strict" directive to your code (don’t forget to add the quotes).

Remark: However I recommend to not apply the Strict Mode to the global scope as this will impact not only your scripts but also 3th party JavaScript libraries you include.

 

Monday, June 4, 2012

Ajax requests are canceled when hitting escape

The default behavior of most browsers is to cancel all ongoing requests when a user hits escape.  Last week this bit us in the foot, as we ‘forgot’ to expect this behavior and requests were never fired again in a single page web app.

The clean solution is of course to implement cancellation logic for all requests, but as the users were waiting for a solution, we introduced a quick fix.

By handling the keydown and keypress event on the document level, we prevented the Escape from bubbling up to the browser and cancelling all requests.

$(document).keypress(function(e) {
if(e.keyCode == 27) {
e.preventDefault();
}
}

$(document).keydown(function(e) {
if(e.keyCode == 27) {
e.preventDefault();
}
}

Friday, June 1, 2012

Define a preprocessor variable in TFS

Last week I got the following question from a colleague:
Do you have an idea how to define a preprocessor variable in TFS 2010?  Actually, these variables is used by Wix installer in the following project. 
clip_image001
Apparently it is not possible to add this as a classical Msbuild argument (it is possible to add a constant but not define its value). In the nant build script, this is defined like this :
<msbuild project="${src.dir}\${project.name}.sln">

<property name="SolutionDefineConstants" value="Version=${project.version};BinDir=${out.dir}\\" />

</msnbuild>
There are 2 options I’m aware of to solve this problem:
  • Inside the build definition you can pass the parameter for msbuild like /p:DefineConstants="Version=1.2.1.0".
image
  • If the value you want to provide is only available inside the build definition itself(e.g. the build number), you’ll have to open the Build Definition Template and add an extra assign activity to override the MSBuildArguments value.
image
Here is an example where I set the Version constant to the BuildNumber:
MSBuildArguments + " /p:DefineConstants=""Version=" + BuildDetail.BuildNumber + """"