Browse by Tags

All Tags » Tips and Tricks (RSS)

Why profiler API causes my .NET application to run as STA?

It seems I’m in a tip giving mood this week. I’d like to tell a story of a bug we had in Isolator…   Last a user complained about a bug that prevented one of VS2010 cronies to work properly. After investigating this issue he found out that using Isolator caused this code: [MTAThread()] static void Main( string [] args) { Console.WriteLine(Thread.CurrentThread.ApartmentState.ToString()); } To write STA on screen. It seems that running along with Isolator caused the thread apartment to transfer...
Posted by dhelper | with no comments

VS2010 Tip – How to run unit tests in 64bit process

One of the reason I used to prefer NUnit was that I could run my tests as x86 or x64 depending on what I needed. I was always strange that Microsoft unit testing framework didn’t have this ability. Luckily for use it seems that Microsoft heard our pain and decided to enable us to run our unit tests in 64bit context. And its very simple to enable – once you know it’s there. Just head to the test configuration (yep – Local.testsettings ) and under Hosts you can set if to run the tests as a 32bit or...

VS2010 tip: How to run unit tests in parallel

Running unit tests can take some time – at Typemock we have about 4,000 unit tests and running them takes 15 minuets. If you always wished it to take half the time (or a quarter of the time) – wait no more! Visual Studio 2010 has a hidden feature called parallel test execution – which means that you can run four tests at the same time on your quad core. Before you start make sure you don’t have any data collection/profiler active. Just go to the test settings (Local.testsettings file) under Data...

Real world unit testing presentation

If you the Israel .NET Developers User Group (IDNDUG) and you’d like to learn more about unit testing you can view my presentation here . I talked about unit tests and how to write good unit tests in the first session. I had a lot of fun and I hope that so did my audience. Additional resources During the break and after the 2nd session (done by Gil Zilberfeld) some of the participants asked what addtioanl resources are available for developers who want to learn more about unit testing – so here they...

How to unit test “un-testable” code (in a nutshell)

Not being able to unit test an essential scenario is one of the reasons developers stop unit testing their code. In fact most of the time when a team decides not to use TDD (Test Driven Development) is because it seems as if they won’t be able to test the production code using unit tests. Most of the time this is just wrong! Of course some scenarios are more difficult to test but in most of them it’s not impossible, just a matter of technique and tools. First – understand the problem Unit tests are...

What to do when Visual Studio fails

For the last 24 hours I had problems compiling one of specific project. The project won’t compile because apparently: “O/R Designer validation failed for file: <FileName> .dbml Error: The operation could not be completed. Unspecified error”. The weird thing was that I didn’t change anything in that project, in fact that project was not changed since the beginning of this year when a single comment was added in one of the project’s files. It seems that the project was not to blame. Further checking...
Posted by dhelper | with no comments

XmlWriter that automatically close elements using IDisposable

System.Xml.XmlWriter provides an easy and lightweight way to write xml strings, unfortunately it has a little gotcha. consider the following xml string (borrowed from IronPython in Action ): Using XmlWriter the following code is needed to create that string: Keep in mind the fact that the code above only creates 5 lines of xml, and as you can probably tell it has a very distinct overhead – for each element/document created you must add a WriteEndX statement, the code quickly becomes unreadable and...
Posted by dhelper | 4 comment(s)

Three different ways to throw events in C#

The Event model in C# finds its roots in the event programming model that is popular in asynchronous programming. The basic foundation behind this programming model is the idea of "publisher and subscribers." In this model, you have publishers who will do some logic and publish an "event." Publishers will then send out their event only to subscribers who have subscribed to receive the specific event. In C#, any object can publish a set of events to which other applications can...