Skip to main content

Posts

Showing posts from July, 2013

Going from Tasks back to IAsyncResult(the Asynchronous Programming Model pattern)

There are lot’s of posts out there talking about how to go from the traditional APM approach(using the typical BeginXXX and EndXXX syntax with IAsyncResult) to the Task based approach. Probably the easiest way is by using the Task.Factory.FromAsync method. But what if you want to do it the other way around and want to go back from a task to the APM way of working? In my specific case I wanted to wrap the async version of ExecuteNonQuery that returns a Task<int>: Task<int> ExecuteNonQueryAsync(); It had to be mapped to an APM implementation with the following signatures: IAsyncResult BeginExecuteNonQuery(DbCommand command, AsyncCallback callback, object state); int EndExecuteNonQuery(IAsyncResult asyncResult); I started by implementing it myself but there a lot of edge cases, so I was happy to find the following extension method : The implementation of my BeginExecuteNonQuery method became: And the implementation of my EndExecuteNonQuery me

The Reactive Manifesto

After the Agile Manifesto it is now time for the Reactive Manifesto , focusing on the why and how of Reactive systems…

Enable NuGet package restore on the build server

When trying to build a project on our TFS build server, it failed with the following error message: c:\b\1\AppName\.nuget\nuget.targets (88): Package restore is disabled by default. To give consent, open the Visual Studio Options dialog, click on Package Manager node and check 'Allow NuGet to download missing packages during build.' You can also give consent by setting the environment variable 'EnableNuGetPackageRestore' to 'true'. For licensing reasons you have to give consent at least once when using NuGet. The exception message already points us to the solution: we need to add an environment variable. To do this, log into the build server and execute the following steps: Click Start and right-click on Computer . Choose Properties from the context menu Choose Advanced System Settings from the System window. Choose the Advanced tab in the System Properties window and click the Environment Variables button. In the System Var

Team Foundation Server: Map different branches to the same folder using the SAK

Last week when giving a Team Foundation Server for Administrators course, I got a great tip from one of the students(thanks Guy!). Let’s first set the scene and explain the situation. For every release they make a new branch is created(and they do a lot of releases). By default every branch is mapped to a different folder so if you don’t clean up your workspace you end up with lots of folders each containing a specific (released) version of the source code. Because they only need one release on disk at a time, they decided to update the workspace mapping to put the active release in a ‘Release’ folder on their local disk. So with every new release, they update the mapping and map a different release to this ‘Release’ folder. Everyone is still with me? Now the problem is that when they try to load the solution in the release folder, Visual Studio gets confused and gives the following message: There appears to be a discrepancy between the solution's source control information ab

Guidelines for Migrating an Application Built Using WIF 3.5 to WIF 4.5

When going from WIF 3.5 to 4.5 a lot of (breaking) changes were introduced. To help you walk through the migration process, Microsoft created 2 useful articles on MSDN: Guidelines for Migrating an Application Built Using WIF 3.5 to WIF 4.5 Namespace Mapping between WIF 3.5 and WIF 4.5 From the article: Windows Identity Foundation (WIF) was originally released in the .NET 3.5 SP1 timeframe. That version of WIF is referred to as WIF 3.5. It was released as a separate runtime and SDK, which meant that every computer on which a WIF-enabled application ran had to have the WIF runtime installed and developers had to download and install the WIF SDK to get the Visual Studio templates and tooling that enabled development of WIF-enabled applications. Beginning with .NET 4.5, WIF has been fully integrated into the .NET Framework. A separate runtime is no longer needed and the WIF tooling can be installed in Visual Studio 2012 by using the Visual Studio Extensions Manager. This v

Use NHibernate to execute raw SQL

In some cases it’s a lot easier to just write a simple SQL statement instead of using LINQ, HQL or one of the other syntaxes that NHibernate supports. Executing a raw SQL: Converting the result to a typed object:

Unofficial Redis for Windows

While looking for a good distributed cache solution in ASP.NET I felt in love with Redis , a fast and feature rich key-value store solution. Unfortunately there is no official support(yet) for Redis on Windows. However the Microsoft Open Tech group created an unofficial port that works great! From the Redis site: The easiest way to install Redis is through NuGet : Open Visual Studio Create an empty solution so that NuGet knows where to put the packages Go the Package Manager Console : Tools –> Library Package Manager –>Package Manager Console Type Install-Package Redis-64 Go to the Packages folder and browse to the Tools folder. Here you’ll find the Redis-server.exe . Double click on it to start it. Redis is ready to use and start’s listening on a specific port(6379 in my case) Let’s open up a client and try to put a value into Redis. Start Redis-cli.exe . It already connects to the same port by default. Add a value by executing

Some JavaScript lecture for during the holidays

During the year I collect a lot of articles that I should have a look at, now during the holidays I can finally have a look at them. 2 great articles on Smashing Magazine I can recommend are: Journey Through The JavaScript MVC Jungle : A review of some JavaScript frameworks by the same guys that brought us TodoMVC ( a GitHub project that contains the same site written in all possible JavaScript frameworks). It lists the Pros and Cons of each of these frameworks helping you to choose one you’ll like. Designing Better JavaScript APIs : This article talks about designing the APIs that developers will love using . It covers the most important things that you will need to consider before and while writing your own utilities and libraries.

Error after upgrading an MVC 4 project to .NET 4.5

After upgrading an ASP.NET MVC 4 project to .NET 4.5, I was welcomed with the following error message in my output window: ‘CompareAttribute’ is an ambiguous reference between ‘System.ComponentModel.DataAnnotations.CompareAttribute’ and ‘System.Web.Mvc.CompareAttribute’.   And it are the following lines that are causing the issue: It seems that the CompareAttribute in .NET 4.5 has been added to the list of core data annotations making it available in both the System.Web.Mvc and System.ComponentModel.DataAnnotations namespace. Fix the problem by removing the reference to System.Web.Mvc from your class file (by deleting‘using System.Web.Mvc’ line).

Green SSL

I always wondered when browsing around that for some sites a green address bar is shown when using https, where for others it’s just the normal behavior.  Green address bar sites are using something called an Extended Validation Certificate (EV Cert). From Wikipedia : An Extended Validation Certificate (EV) is an X.509 public key certificate issued according to a specific set of identity verification criteria. These criteria require extensive verification of the requesting entity's identity by the certificate authority (CA) before a certificate is issued. Certificates issued by a CA under the EV guidelines are not structurally different from other certificates (and hence provide no stronger cryptography than other, cheaper certificates), but are designated with a CA-specific policy identifier so that EV-aware software can recognize them. The criteria for issuing EV certificates are defined by the Guidelines for Extended Validation Certificates , currently (as o

Things from Build 2013: $returnvalue

One thing I always found annoying(and it seems I’m not the only one) during debugging is that it was not possible to see return values for functions. The only way was to change your code to first assign the return value to a local variable and then return that value. Starting from Visual Studio 2013, you no longer need to do this. Now you can examine the return value of a function when you step over or out of a function during your debugging session. The return value(s) get displayed in the “Autos Windows” (Debug->Windows->Autos) and you can also use the pseudo variable “$ReturnValue” in the Watch and/or Immediate window to fetch the last function’s return value. If you add a breakpoint to the following code block: You can see the return values in the autos window You can also use the last returned value in your immediate window More info: http://blogs.msdn.com/b/visualstudioalm/archive/2013/06/27/seeing-function-return-values-in-the-debugger-in-visual-studio-20

FailSafe: Building Scalable, Resilient Cloud Services

A few months ago, Microsoft introduced the FailSafe Initiative. The mission of the FailSafe Initiative is to articulate recommendations and approaches for delivering resilient and scalable cloud architectures. FailSafe delivers general guidance on building resilient and scalable cloud architectures, guidance for implementing those architectures on Microsoft technologies generally, and scenario specific architectures that implement those architectures in context. Developed by Microsoft Services and the Azure Customer Advisory Team, this series provides both platform agnostic concepts and patterns as well as Windows Azure specific implementation guidance. Some useful links: http://msdn.microsoft.com/en-us/library/windowsazure/jj853352.aspx http://www.windowsazure.com/en-us/develop/net/architecture/ http://msdn.microsoft.com/en-us/library/jj717232.aspx http://code.msdn.microsoft.com/Cloud-Fundamentals-in-1a3ab1bd And of course, don’t forget the Channel 9 series:

ASP.NET Performance eBooks

If you need some extra lecture to read next to the swimming pool, the guys from RedGate sponsored the release of 2 free eBooks: 50 Ways to Avoid, Find and Fix ASP.NET Performance Issues   25 Secrets for Faster ASP.NET Applications! Remark: You need to register first before you can download the eBooks.

Windows Identity Foundation(WIF) Request validation in .NET 4.5

I blogged before about how to solve the ‘A potentially dangerous Request.Form value was detected from the client’ error that you can get back from the ASP.NET request validation when using Windows Identity Foundation. The best way to fix it was creating a custom RequestValidator . If you upgrade your application to use WIF in .NET 4.5 you no longer need this custom validator. Instead the only thing you need to do is setting the RequestValidation option to 4.5 mode in your web.config: <httpRuntime targetFramework="4.5" requestValidationMode="4.5" /> WIF now plays nicely with the request validation in ASP.NET 4.5.

Team Foundation Server 2010 Build: Warning: Cannot find the last label '': no changesets will be associated with the build.

After configuring a build definition for some projects, the build always returned the following warning: Warning: Cannot find the last label '': no changesets will be associated with the build. Some further investigation made me notice that it only happened on projects were there was no successful build (yet). The first time that the build succeeds(no errors), the warning goes away and never comes back.

Impress your colleagues with your knowledge about... <deployment retail=”true”/>

Sometimes when working with C.NETyou discover some hidden gems. Some of them very useful, other ones a little bit harder to find a good way to benefit from their functionality. One of those hidden gems that I discovered some days ago is the retail attribute on the deployment element in your machine.config. When moving your ASP.NET applications to a production environment, you will most likely want to set the compilation debug attribute in web.config to false, as having debug set to true has some downsides: Compilation takes longer as batch optimizations are disabled Scripts and images from WebResources.axd will not be cached on the client Larger memory footprint Code will execute slower because of enabled debug paths Request execution timeout is disabled If you set the retail option to true in your web.config, ASP.NET disables trace output, disables debug capabilities, and disables detailed system-generated error messages for remote users. For applications tha

Using different dataloaders in Effort

Last week I blogged about Effort , a library that helps you write unit test against your Entity Framework code. In that post I showed you how to populate the Effort in-memory database by using CSV files. Turns out that that is not the only way to populate the Effort database. Effort provides multiple built-in data loaders: EntityDataLoader: fetch data from an existing database by utilizing an existing Entity Framework compatible ADO.NET provider. CsvDataLoader: read data records from CSV files CacheDataLoader: speed up the initialization process by wrapping any kind of data loader with a cache layer And of course it is also possible to build your own data loader. More information can be found here .

CSS Float tutorials

I have to admit, I have a big hole in my brain where I could fit some CSS knowledge. Even after years of web development, I still struggle with CSS(don’t ask me why). One of these concepts I always do wrong is CSS floats . With CSS float, an element can be pushed to the left or right, allowing other elements to wrap around it. Float is very often used for images, but it is also useful when working with layouts. One site that helped me understand CSS Float and how to use it is Floatutorial . Floatutorial takes you through the basics of floating elements such as images, drop caps, next and back buttons, image galleries, inline lists and multi-column layouts.