Roslyn: Compile C# Expressions Without Using the Scripting API

I have an application that processes table structures. Tables have columns and some columns may contain expressions. For example, an expression may look like “row.Price * row.Quantity”. The compiled code should be loaded into the current AppDomain. Also, I didn’t want to use the existing Roslyn Scripting API because I could not get my head around the handling of AppDomains and referencing assemblies in that (I had too little time to dig into that). If you have read this post, you might have an idea what’s comming next. The current post can be understood as an update to the older post with adaptions adjustments to the current version of Roslyn (0.6.4033103-beta).Read More »

WF 4.0: NullReferenceException in ActivityXamlServices.Load

I tried to dynamically load a workflow XAML from a database. Simple task, I thought, because there is an API for that (the ActivityXamlService class). Unfortunately, when calling ActivityXamlServices.Load I hit these two issues:

  1. When the workflow XAML contains the “x:Class” attribute: A XamlObjectWriterException stating that “Cannot create unknown type ‘{http://schemas.microsoft.com/netfx/2009/xaml/activities}Test.MyActivity’.” (“Test.MyActivity” being the full name of the workflow activity).
  2. When I remove the “x:Class” attribute: A NullReferenceException without any further explanation from inside the ActivityXamlService.GetCompilerSettings method.

Read More »

Fast Named Formats In C#

The .NET Framework supports string formats since the first day. String format patterns look like “My name is {0} and I am {1} years old”. Optionally, the placeholders inside the curly brackets, called format items, can include other format strings – e.g. to format numbers or dates in a special way. Great stuff. But what if I had an object whose properties I want to directly reference in the format string like “My name is {Name} and I am {Age} years old”?Read More »