Missing ConnectionString parameter in Entity Framework Constructor

15. März 2016

After working several years with LinQ2SQL and the DBContainer classes I recently switched over to Entity Framework.

When starting my new WebApplication project I compared LinQ2SQL, ADO.Net and EF6 with some possible database operations and finally decided to pick EF as it got the best results. (Details and my regrets may be following up on another blog post).

So when working with EF I also decided to place all files in a seperate project as I had to share the classes among several subprojects. Unfortunately this construct ends in not sharing application settings (app.config / web.config) so I was looking for some way to pass a connection string along with the constructor, as the web.config settings wouldn’t be recognized.

Thanks to StackOverflow and Google I found the most obvious:
The EF-context files inherit from DBContext which owns such an constructor. But the automated generated files lack of this constructor.


So the obvious is (shame on me that I didn’t saw this in first place) to add the missing constructor by hand:


But unfortunately this file is auto-generated – it will be overwritten each time you change something in the designer.

So to prevent the unwandet deletion of your manual constructor is easy if you know how: All you need is a partial class which simply adds the missing constructor:


And that’s it… 🙂


Creating Documents with DirectSmile Crossmedia totally dynamical

11. März 2014

Today I would like to blog about creating dynamic documents with the new DirectSmile Crossmedia V6.

When talking about a ‚dynamic document‘ I mean a document whose content will be constructed on a dynamic way. For this blog I will allow the user to pick several chapters from a list and will get a PDF in return. So the final document will need to be build based on the users selection.

To achieve my goal I will first need a PURL which allows my user to pick several available chapters. Thisfor I will need the ‚MultiSelect‘ item from the extension items library.

So my basic PURL will require a firstname, a lastname and a selection of several chapters:

Simple setup for our PURL

Simple setup for our PURL

Creating a dynamic document which will be rendered as PDF requires a XML which we call DocML. This is a language which allows you to create documents just with a XML syntax. Please see the manual (Document and Composition XML Commands) for more details about DocML.

The multiple selection will be stored as a stringlist with pipes as delimeter. Next we will need to create a new ’scripted data relation‘ to generate the DocML which will generate our document based on the users selection.

So just add a new scripted datarelation and edit it to read from the current table row and split the string by ‚|‘:

A first setup for our data relation.

A first setup for our data relation.

As we now have all informations needed to set up our document we will start creating our XML. We will simply create new pages for every valid entry in our splitted string which contains only a single image referencing to a PDF file containing the selected chapter which I’ve uploaded to my template images before.

In case your chapters are longer than single pages you will need another database containing individual informations about each chapter so you can regard these in your JavaScript. But for our small example we simply assume that each chapter only consists of one single page.

Final DataRelation with full DocML result.

Final DataRelation with full DocML result.

Also we need a ButtonAction defined inside our DataRelation so that we can write the DocML to our database. Please recognize that I’ve also added a second condition (Mode ===‘ ButtonAction‘):

In the head section of the DataRelation we define a ButtonAction to trigger the write-2-db from outside.

In the head section of the DataRelation we define a ButtonAction to trigger the write-2-db from outside.

This ButtonAction needs to be assigned to our submit button on the PURL:

Assign the ButtonAction from the DataRelation to the submit button.

Assign the ButtonAction from the DataRelation to the submit button.

So after that we will only need to create a dummy document which needs to be web editable – this will allow us to render this document on our page but with our DocML as payload to overwrite the content with our dynamic one.

Configure the dummy document to pick the DocML from the correct database column

Configure the dummy document to pick the DocML from the correct database column

And finally we have all we want. We can now use this document to be rendered on a PURL, sent to the workflow or attached to an e-mail.

If you want to try this on your own please use the attached ZIP file to import this example campaign.

Finally to say: Many thanks to my dear colleague Wolfgang – without his work this article would not have been possible!

Creating random strings for a dummy table

23. Januar 2014

Today I worked on a JavaScript placed in a DirectSmile Crossmedia campaign, which is currently used for supporting auto-completion based on a list of entries coming from a DataRelation. The customer who uses this script asked if we could allow prefixes which will not being recognized by the auto-completion.

Well, sounded like a challenge – perfect for me as I like such things, challenge accepted! Before I could begin I had to get some dummy data… but how?

So I could just create an empty campaign, fill the database with dummy data I have to write on my own and then link it with a DataRelation to the real campaign.

This approach sounds like a plan – but on the other hand it sounds like a lot of manual work to do. And as software engineers are lazy by nature I had the idea for a slightly different approach:

With the latest release of DirectSmile CrossMedia a new feature has been introduced: Scripted DataRelations! This special DataRelation uses JavaScript to produce data. So all I had to do was create some JavaScript which will create my dummy string which fulfills my needs.

To create a random string in JavaScript all you need is a string with all wanted chars – in my case I separated the capital letters from the normal ones and placed them in two strings:


var possible = „abcdefghijklmnopqrstuvwxyz“;

Now you only need a random number between 0 and the length of each source-string:

for (var i = 0; i < 10; i++) {

randomString += possible.charAt(Math.floor(Math.random() * possible.length));


This will create you a random string with 10 characters. Could be enough for my needs but it could even be „fancier“ – using capitals in front of each cityname and different string lengths:

So I’ve added a random length variable with at least four characters and a maximum of 16:

var length = Math.floor(4 + Math.random() * 12);

And added this to my for-loop:


var possible = „abcdefghijklmnopqrstuvwxyz“;

var length = Math.floor(4 + Math.random() * 12);

var randomString = possibleCapital.charAt(Math.floor(Math.random() * possibleCapital.length));

for (var i = 0; i < length; i++) {

randomString += possible.charAt(Math.floor(Math.random() * possible.length));


Now I’ve got a nice function which will render me one single random string with a capital letter at the beginning. So all I needed to do now is to call this snippet of code a couple of times and add each string to my DataRelation output.

After adding a Scripting Relation…

Add a Scripting Relation

… in my campaign I’ve just copy & pasted the code from above to it’s editor…

Edit the data source

… and modified the section where the data is added to the „newRow“ variable:

if(Mode == „GetCount“)
    MyTable.ResultCount = 100;
else if(Mode == „LoadData“)
    var possibleCapitals = „ABCDEFGHIJKLMNOPQRSTUVWXYZ“;
    var possible = „abcdefghijklmnopqrstuvwxyz“;
    var tResult = “;
    for (var n = 0; n < 101; n++) {
        tResult = ‚NAV ‚ + possibleCapitals.charAt(Math.floor(Math.random() * possibleCapitals.length));
        var length = Math.floor(4 + Math.random() * 12);
        for (var j = 0; j < length; j++) {
            tResult += possible.charAt(Math.floor(Math.random() * possible.length));
    var newRow = MyTable.AddRow();
    newRow.SetValue(„ID“, n);
    newRow.SetValue(1, tResult);
As you can see I’ve already placed my specific prefix to the random string variable („NAV „). And finally I had my data presented:
See the result
And finally I could begin my work on the auto-completion with the nearly correct values 🙂 Challenge won!!

Problems with Internet Explorer (10)11 and ASP.NET

28. November 2013

Recently we’ve received a support request about an issue concerning the DirectSmile Card and Gift Shop. Customers who use IE11 will continously be prompted to log in again when trying to order.

After some investigation (it was more like searching the needle in the haystack) we’ve been able to pin this issue down to a more general problem with Microsofts ASP.NET framework: When Microsoft introduced the new Internet Explorer 11 (and this happened also to the version 10) they have changed the user agent string delivered by the browser to the server. This string will be parsed by the ASP.NET framework to identify the browser and it’s capabilities (eg cookie support). This is also a problem for the document web-preview in DirectSmile Integration Server as the AJAX-calls will fail when using IE11.

Unfortunately the regular expression Microsoft uses for the parsing was not prepared for version 10 and 11 – with version 10 it simply failed that there are now two digits (9 –> 10) written. And with version 11 the whole string has been changed so the complete regular expressions needs to be changed.

So when a shop customer logs in the browser is recognized to not support cookies – therefor the IIS will switch to cookieless session states which result in a URL with an extra session ID. As the membership provider who is in responsibility for managing the logins does not support cookieless sessions, the customer will continously be prompted to log in.

Fortunately there is already a hotfix which will hopefully become part of the regular server updates soon: http://support.microsoft.com/kb/2836939/en-us – you won’t need to update all settings by hand.

So after installing this patch your software should work again for Internet Explorer 11

For more technical details I recommend these nice article from Scott Hanselman:


Missing Silverlight Unit Tests in VS2012

31. Juli 2013

When you are missing the Silverlight unit test project templates in Visual Studio 2012 then you should check this link: http://social.msdn.microsoft.com/Forums/silverlight/en-US/180283df-6cac-45fd-bdce-ff3aec31cb7c/unable-to-create-a-silverlight-unit-test-project-on-vs2012

The problem is that the Silverlight Toolkit will install the template files to the first Visual Studio folder found – or even the default folder in case you installed your VS to a different location. So when you have VS2010 and VS2012 installed on your computer this may be the reason why you will not find the templates in VS2012.

To fix this simply lookup the ZIP files in the VS2010 folder (eg C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplates\VisualBasic\Silverlight\1033 and C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\VisualBasic\Silverlight\1033) and copy the Silverlight Test zips to the equivalent VS2012 folder.

Finally you will need to start „devenv.exe /installvstemplates“ manually to apply the new templates.

To create or use a new test project you will currently also need the Silverlight Unit Test Adapter – this will enable VS2012 to make the project visible as test in the testbrowser.

If this plugin does not fix the error message when creating a new test project you may need to edit the MyTemplate.vstemplate file inside the project templates ZIP:

Just edit the following line in the „Wizzard“-section to raise the version:
<Assembly>Microsoft.VisualStudio.Silverlight, Version=, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>

I had to go through all the steps to get the project working… Hope Microsoft will fix this soon.


There seems that there exists a different approach via NuGet (see in the answer here):

Just install „Install-Package SilverlightToolkit-Testing“ to the Testproject and manually add the „usings/imports“ to your test classes.

Unfortunately it was too late for me when I found this link – any comment approving this way would be great!


Another problem came up with the „TestDiscoverer“ (test explorer won’t show the new tests). To fix this I had to add the missing DLLs to the GAC via gacutil:

Open the Visual Studio Command prompt as administrator, go to C:\Program Files (x86)\Microsoft SDKs\Silverlight\v5.0\Toolkit\dec11\Testing and there use gacutil to add the missing DLLs Microsoft.Silverlight.Testing.dll and Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight.dll

Still I’m struggeling to get my tests working – but finally they’re executed… Maybe my solution will come with a new post soon.


Touch & Gestures in JavaScript with Windows 8

29. Januar 2013

Recently I had to implement touch & gesture support in JavaScript for a Windows 8 touch device (Asus Ultrabook). As I prior had to add Android support to my existing iOS-library I picked a nice framework: hammer.js which supports iOS & Android… but even then they recently updated to support Windows RT on a Surface this did not work out on our new Asus Ultrabook which we bought especially for developing touch support with JavaScript.

So I had to study how Microsoft did implement their touch support. Pretty fast I stumbled over their well documented library. But unfortunately I had to discover that (again) Microsoft did something on their own: Even if Android and iOS did manage to support nearly the same eventtypes („touchstart“, „touchmove“, „touchend“) so you can easily use the same code for both device types, Microsoft introduced two proprietary event types: MSPointer and MSGesture.

So this lead to the point where I had to extend the nice hammer.js framework with new code which handles the special Microsoft events. You can find a fork on github which I will try to add it to the original framework soon when I’ve finished testing.

The main thing about the gesture support is that you have to create a MSGestureObject for each element you want to handle gestures – otherwise you will only get PointerEvents and will need to handle all interpretation by yourself. After you registrated such an object you will get the events with a plentyfull of information about the current gesture and it’s changes – like rotation and scaling. But here comes the disappointment: The online documentation only names it as rotation but unfortunately it’s more like a translation of the CSSMatrix which is also a proprietary object of Microsoft to handle CSS-transformations. So as I wanted to extend a framework which delivers a wrapper-event with these information I had to pull back and calculate the scaling and rotation by myself instead of using the quite cool but in this scenario unuseful features.

During my work I stumbled over several issues with the MSPointer & MSGesture events which I would like to share:

Event Bubbeling
One issue is that the event bubbeling in IE10 works bottom-up – on iOS or Android it’s top-down… so after realizing this (and it unfortunately took quite long) I finally got an answer why I retrieved events from the wrong HTML elements – something which can be real disturbant when you try to register the MSGestureObject only for these elements you want events for.

Dual Events
Another problem is that even when MSGesture-events are fired the browser still continues to throw the MSPointer-events – fortunately this is something positive as you can now record your own „touches“-array… As the MSGestureEventObject comes with already calculates scale and rotation, they simply miss an array of touches with the coordinates of the finger-tips… As the hammer.js and my own implementation take big usage of these arrays I had to implement my own array with the MSPointerEvents.

Still MouseEvents
On our Ultrabook we had also the problem that the touch device also fires a Mouse-event each time you tap or drag something… as this is normally not to be expected the initial author of the hammer.js-framework simply ignored this and interpreted each mouse event as a touch-event… I expected Windows 8 to hold back the mouse events as I’m really only touched the screen.

Finally there is to say that there does not really exists a nice debug-tool for the IE10 in touch-mode (or Metro-Style or however it is called)… so I had to turn back to classic „debug.print“/“console“-debugging by writing my own debug-console to the DOM… Every iOS-developer without Safari 6 (see my last post) will know what I mean.

UPDATE: Currently I’m struggeling with identifying whether the IE10 comes as Metro or desktop version… unfortunately there is no clear way to identify. The best practice is that you can only hope the desktop version is not started as 64-bit application and so you can lookup the userAgent-string. See this stackoverflow question for more details.

Our next question is how a Microsoft Surface behaves with Windows 8? On Windows RT it seems to simply send „touch“ events as there is a contributor of the hammer.js-framework who added Surface-support without interpreting new event types. But unless I do not have a Surface-device in my hands I will not be able to say something about it. But when I get hold of such a device I will post an article of course.