Nuget trouble

nuget logoKeeping the versions of packages in sync was difficult today.
My MVC website must load and display a controller / view from another project. The assembly is in the bin folder and the objects are loaded using Structuremap. When running the website the debugger stopped with this error:

Could not load file or assembly ‘WebGrease, Version=1.5.1.25624,
Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its
dependencies. The located assembly’s manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)

Seems to be a version difference between my MVC website and the loaded project. Visual Studio did supply me with a warning and a solution:

Found conflicts between different versions of the same dependent
assembly. In Visual Studio, double-click this warning (or select
it and press Enter) to fix the conflicts; otherwise, add the
following binding redirects to the “runtime” node in the
application configuration file:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
 <dependentAssembly>
  <assemblyIdentity name="WebGrease" culture="neutral" 
publicKeyToken="31bf3856ad364e35" />
  <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" 
newVersion="1.5.2.14234" />
 </dependentAssembly>
</assemblyBinding>

But I don’t want to specify what version to use in my configuration.
The solution was to uninstall and (re)install a package

uninstall-package Microsoft.AspNet.Web.Optimization
install-package Microsoft.AspNet.Web.Optimization

Now both projects use the 1.5.2 version of the WebGrease package. Only needed to figure out what package to re-install.

Posted in Development | Tagged , , , | 1 Comment

Correct CSV files with ghost quotes

Last week I helped out a colleague of the Business Intelligence team. Some CSV input files contained extra quotes (“) in text fields. That threw off the import because the quote is also used to surround strings. Below the regular expression that made his day.

// allowed are 
//  - quote at begin of file, (?!^)
//  - quote at begin of line, (?<!\r\n)
//  - ; following quote (?<!;)
//  - quote following ; (?!;)
//  - quote at end of file (?!$)
//  - quote at end of line (?!\r\n)
//  - rest of quotes must be replaced
string pattern = "(?!^)(?<!\r\n)(?<!;)\"(?!;)(?!\r\n)(?!$)";
string input = File.ReadAllText(sourceFile);
string output = Regex.Replace(input, pattern, "_");
File.WriteAllText(destinationFile, output);
ID;Description;Price
100;"Hello world";"$450"
101;"Wrong "code"";"$300"
ID;Description;Price
100;"Hello world";"$450"
101;"Wrong _code_";"$300"

For the regular expression I used regexhero.net. Kick-ass online tool for regex testing.

[edit]
30 jan 2014 added end-of-line character for processing file at once. ^ and $ are only beginning and end of file, not per line. fixed with \r\n check.
[/edit]

Posted in Development | Tagged , | 1 Comment

Week roundup

On twitter I read this post:


Since I have a wordpress blog and like a challenge, here is the daily post in my Zero to Hero sequence.

Publish a roundup post

Here are the best articles I’ve read/seen last week:

  • Scott Hanselman does a quick demo of Node.js on Windows Azure friday. Not everything goes as planned. See how he troubleshoots and fix the problem in this half hour video on Channel 9.
  • Google-ing for MVC plugin solutions, this article about the razorgenerator bubbled up. David writes about a Visual Studio extension and nuget package to generate code from your razor file. Now razor can live in a class library.
  • Since day 4 of zero to hero I started following programmerinnervoice on wordpress. His sequence about design patterns are a good read about the GOV patterns everybody knows, but forgets to use 😐

What are your best reads this week? Leave them in the comments below.

Posted in Uncategorized | Tagged , , , , | Leave a comment

Blue Monday, the day(s) after

On twitter I read this post:


Since I have a wordpress blog and like a challenge, here is the daily post in my Zero to Hero sequence.

publish a post inspired your Blue Monday post

imageGarfield is my kind of humor. Simple, to the point and sometimes pure evil. I had stacks of them as a kid.

On Techdays 2012 day 2 Astrid Hackenberg started her presentation with a Garfied commic about the state of the audience. The talk was about multi-tenant windows azure applications, but I had to look that up.

The power of Garfield is the way it triggers you. Usually there are 3 drawings, some with text. You have to imagine what happens when you go from one drawing to the next. Read them on garfield.com.

Posted in Uncategorized | Tagged , | Leave a comment

xUnit in Visual Studio

xUnitMy current project requires xunit for unit testing. I’m used to mstest as it is build into visual studio, but xunit integration is transparent with the extension installed.

Setup

To get xUnit working with the Test explorer install the xUnit.net runner extension. Also install the xUnit package from nuget for your project. Now you’re good to go.

Visual Studio has support for snippets. I added the factm snippet to expand to a method with the Fact attribute on it. Download my snippet from here.

Thoughts

I’m missing the Assert.Inconclusive method for reminding me about incomplete tests. Also I must stop clicking New Unittest and start creating New Class.

Where mstest uses an ExpectedException attribute, xunit uses Asserts.Throws. This makes the code more readable.
Xunit has Assert.Contains to check strings for containing a string. I was doing a check for true on string.Contains, the xunit method is shorter. Short is good 😉

References

Posted in Test | Tagged , , , , , | Leave a comment