Rory Primrose

Learn from my mistakes, you don't have time to make them yourself

View project on GitHub

ThreadStatic gotcha with ASP.Net

I had a requirement recently in a service implementation that business rules at any point throughout the execution of a service request could determine a message to return in the header of the response. Because these circumstances don’t affect the execution of the request (no exception is thrown), I needed a loosely coupled way of recording all the required messages and handling them higher up the stack.

Storing data against the executing thread was the obvious solution. I considered manually storing information in the context data of the thread, but then thought this would be a great opportunity to use the ThreadStaticAttribute. I coded this up and it all seemed to work well.

Read More

DisconnectedContext when debugging with MSTest

I have been hitting a DisconnectedContext issue when I’ve been running MSTest in the Visual Studio IDE with the debugger attached. At first I thought it was an issue with debugging WF, but it is now also happening with LINQ to SQL.image

The debugging on the thread of the executing test appears to be stopped when this is hit. Other threads/tests in the test run will still hit breakpoints however.

Searching the net hasn’t yielded any pointers. Anyone out there have some information about this?

Read More

Sense of satisfaction

I just found out that something I came up with a few years ago in another job has hit production and is making a big difference. There were a lot of people involved in supporting the idea and some innovators who took the concept and applied it in ways I didn’t think of. Overall it is a great result and I’m very happy to see such a change being applied.seal

Read More

Quick tip for undoing unchanged TFS checkouts

Reviewing changesets with a large number of files that haven’t changed can be a significant waste of time. Sliming changesets down to only changed files is a great idea before checking in files.

I have previously been doing this manually which in itself is time consuming. Fortunately the TFS power toys package comes with a handy utility to automatically uncheck out any files that haven’t changed. Running TFPT.exe uu /r will do the trick. Running up an instance of the Visual Studio command prompt and entering in this command can also be a hassle. Thankfully Visual Studio makes this easy with the support for external tools.

Read More

Custom fields support with SqlMetadataStore in the sync framework

I am putting together a sync framework provider and have come across some issues that do not appear to be documented. I’m adding custom fields to the item metadata so that I can store additional information for items that are synchronised with another provider. To do this, you define the custom fields for items as part of initializing the metadata store. The tricky thing is that it isn’t clear what data types are supported and how to correctly use the data types that are supported.

I have the following initialization code.

Read More

Transport connection closed exception with nDumbster

I have been using nDumbster on a project to unit test sending emails. It has been an interesting experience working with this little tool. It is a great product but has been out of development for a while and has some issues.

The more I started using nDumbster in test runs, the more I was finding that it wasn’t working so well. I was consistently getting the following exception:

Test method [TestName] threw exception:  System.Net.Mail.SmtpException: Failure sending mail. —>  System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.. System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine) System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String& response) System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) System.Net.Mail.SmtpClient.Send(MailMessage message) System.Net.Mail.SmtpClient.Send(MailMessage message)

Read More

CodeDom does not support the ConditionalAttribute

I need to output some debug statements from a PolicyActivity as I’m having some issues with running a workflow from a unit test. Adding some Debug.WriteLine statements to the rule set seems like a good idea given that I am not getting the WF designer step through experience from MSTest. I thought about whether CodeDom checks for the Conditional attribute before it invokes a method.

CodeDom evaluates the xml rules and executes the instructions in C#. At compile time, native C# is striped of any method call that is decorated with a ConditionalAttribute that does not match the additional compilation symbols of the build configuration. For example, the Debug.WriteLine statement is decorated with Conditional(“Debug”) attribute so any calls to this method in a typical Release build configuration will get stripped out as the Debug compilation symbol is not defined. What about CodeDom though?

As expected, CodeDom does not check the ConditionalAttribute marker on methods it invokes. As such, debugging methods are evaluated and invoked at runtime regardless of the build configuration.

Read More

ActivityValidator passes compiler but fails in designer

I have a custom WF activity that uses a type converter to convert from a source object to a destination object. I added an ActivityValidator to the activity to check that the TypeConverterType property specified to use for the conversion derives from TypeConverter.

The code originally looked like the following.

Read More

Neovolve ReSharper Plugins 1.1 Released

I have just released a new version of ReSharper Plugins. This version updates the identification and conversion of value types in cref xml documentation references and now supports ReSharper 4.5

Get the goods here.

Read More