MEF configuration and parallel transactions

aspnetWhile testing my ASP.NET Web API solution single requests are fine, but multiple requests give HTTP500 after a long wait.

A MEF configuration setting caused parallel transactions and the database provider was unable to handle them.

Setup

ASP.NET Web API offers an extension to use your own IoC. I’m using the MEF implementation from stackoverflow. Below the configuration code with my Handler and Context added.

var registration = new RegistrationBuilder();
registration.ForTypesDerivedFrom<Controller>()
            .SetCreationPolicy(CreationPolicy.NonShared)
            .Export();
registration.ForTypesDerivedFrom<ApiController>()
            .SetCreationPolicy(CreationPolicy.NonShared)
            .Export();
registration.ForTypesDerivedFrom<IHandler>()
            .Export<IHandler>();
registration.ForTypesDerivedFrom<IContext>()
            .Export<IContext>();
var catalog = new ApplicationCatalog(registration);
var container = new CompositionContainer(catalog, true);

Exception

Using Fiddler I’m sending multiple requests to the Web API. The result is HTTP500 An error occurred while starting a transaction on the provider connection. See the inner exception for details. with the inner exception on the server SqlConnection does not support parallel transactions.

Solution

The Handler and Context object are shared between the two requests. While creating a record for the first request the second request starts a transaction for creating it’s record. Setting the CreationPolicy for both objects to NonShared solved it.

registration.ForTypesDerivedFrom<IHandler>()
            .SetCreationPolicy(CreationPolicy.NonShared)
            .Export<IHandler>();
registration.ForTypesDerivedFrom<IContext>()
            .SetCreationPolicy(CreationPolicy.NonShared)
            .Export<IContext>();
Posted in Development | Tagged , , | Leave a comment

Week roundup

Last week recap and links:
Image courtesy of kanate / FreeDigitalPhotos.net

Image courtesy of kanate / FreeDigitalPhotos.net

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

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

Nuget packages folder one level up

nuget logoWe had some issues with our nuget server. Every other build would fail because of a failing nuget restore. We decided to stop restoring the nugets and put them in source control.

Adding the nugets will increase bytes in source control. We want to limit this by moving our packages folder one level up. This way all solutions will use the same packages folder for their nugets. No duplicates = less bytes.

The process is well explained in this answer on stackoverflow. In short:

  • Edit the nuget.config to set a repositorypath to $\..\..\..\packages and disableSourceControlIntegration to false.
  • Then edit the nuget.targets to set PackageDir as $(SolutionDir)\..\packages.
  • Fix the references in the project files

We documented this and instructed the team to make the changes on every (new) solution. New solutions will not need to fix the references as new projects use the correct path to the nuget / packages folder.

The nuget server issue turned out to be a duplicate package. The packages had different names, but with identical nuspec information. After removing the duplicate everything was fine again.

Posted in Development | Tagged | Leave a comment

iPad as third screen

When presenting I’m using the setup below. The big screen, my laptop and iPad all have an important role.

Duplicate laptop and big screen

project_screenUsing “Windows-Key + P” you can select the setup for one extra screen.

The big screen is a Duplicate of my laptop screen. This way I can see what the audience is seeing right on my laptop. Also my demo’s are on the laptop screen and thus visible on the big screen, no need to type looking over my back.

If this is your complete setup disable the presenter view on the Slide Show tab in powerpoint.

Extend to iPad

screen_resolution_multiple_monitorsI’m using my iPad as a third screen. For this I installed Duet Display. My iPad will show the presenter view as it is configured as Extend my desktop in Windows.

Windows 8.1 lets me configure this setup in the Screen Resolution. Select Monitor 1 or 2 and specify the Duplicate desktop on 1 and 2 option. For monitor 3 (iPad) select Extend desktop.

Prepare for the worst hope for the best

My talk at sdn was my first go with this setup. After some dry runs I knew the correct setup and possible problems. On the video you’ll see somewhere at the end that the screen flickers. I did have a backup plan: use the Duplicate laptop and big screen setup from above. But the setup recovered and all was well again.

Below the setup with an extra monitor in stead of a projector. In the middle the iPad (mini) with the presenter view.
three_monitor_setup
Now you know how I setup during presentations. Be sure to test what works for you and always have a backup plan.

References

Art of Speaking by Scott Hanselman
Duet Display to use an iPad as an external monitor
Powerpoint multi-monitor support

Posted in Tooling | Tagged , , | Leave a comment

Week roundup

Last week recap and links:
Image courtesy of kanate / FreeDigitalPhotos.net

Image courtesy of kanate / FreeDigitalPhotos.net

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

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