Aug 5 2012

I’m on the clouds

Category: C# | Virtual Machines | ASP.NET | Cloud | Azure — Duke @ 17:47

Great! the blog is online again! finally it is persistent! I mean.. it will stay online 24/7,because it is on azure!

I’ve tried several solution but at the end I’ve found the most suitable for me.

A virtual machine instance with IIS installed on it. then an endpoint opened on the port 80, and finally  my lovely DynDNS that routes my domain name with an A record on the VIP address of the Virtual Machine.

I’m happy

it works

and the database is hosted on a separate instance of SqlServer!

some may ask why to not use the web instances (shared or reserved) available in azure, they should be ideal to host a simple blog

yes they are but….

shared instances doesn’t allow custom DNS (still wondering why)

reserved instances have a price that is too higher

and last but not least. a virtual machine allows you to do what you want on it… that is not exactly what one need in case of production website (because it force you to do all the maintenance, antivirusing, patching etc…) but it is ideal for a small experimental site.

Azure is amazing, especially the new HTML portal, I’ve done everything in 3 hours without no training at all, and I’ve tried several solution (also the shared sites, yes….)

great job MS, now lover the price of the reserved site instances or allow custom dns on the shared ones.


Dec 30 2011

Simple ASP.NET MVC script manager

Category: ASP.NET | C# | MVC3 — Duke @ 15:57

I remember that some months ago I’ve found a beauty video of a beauty component that allows to manage .js and .css files from an MVC application.

Unfortunately I’ve lost the link and I don’t remember the name of the component.

I’ve searched the seven seas of the internet but… nothing. Things went worst today when I realized I need a script manager.

I’ve searched, browsed and digged the internet again but the best I’ve found is the “Simple script manager” on codeplex, that is well far from being “beauty”

So, I’ve started my own simple script manager. for now it is very basic. it does almost nothing but at least it is in full “MVC” style, by using and respecting the existing design of MVC3, differently from the other things I’ve found.


so: here is the code More...

Tags: , ,

Dec 22 2011

Compare two objects’ hierarchy

Category: C# | Linq — Duke @ 17:47

I think that everyone sometime is in the situation to understand which are the difference between two objects.

Sometime it is easy but sometime is not. Imagine that you have to prepare for your user a log of all the difference and changes that has been applied on a complex document object model.

I’m in this situation: I have NHibenrate that maps a database. As usual the principal entity of the domain have dozens and dozens of sub entities.

This complex structure is subject to revision from the user. There is a workflow to generate and approve a newer version of the object graph, but as the graph is complex, the user want to have a report of what is changed. from the last approved version. ok: now I have an graph of objects that represent the current situation, and a graph of objects that represent the last approved version.

How to solve this issue? Next: once you have discovered where the objects differs, you maybe want to see which is the actual value and understand which was the old value and which is the new one. Finally, maybe you want to revert some of the difference…. how you can do it in an efficient and powerful way? the reply is EXPRESSIONS From linq on, .NET have gained one of the best thing I ever seen in a programming language, the ability to manipulate code as it is data.

This possibility is SIMPLY AMAZING. I’ve already used this in SyncWcf and now I’ve another clue that makes me love expression more and more. so what I’ve done? give a look at the code below: More...

Tags: , , , ,

Nov 3 2011

OnDeleteCascade Attribute for Entity Framework 4.2

Category: — Duke @ 19:22

So boring that EF is still under construction but I love the multiple ways it allows me to do the thing.

I think that for small size projects, attribute decoration is ideal, and much more convenient than code mapping.


anyway I’ve found myself in a situation where I’ve a class “product” that has multiple images, and I want that when someone deletes a product, all the associated images goes away too.

For sure I can do this by code, but my project is quite small and I would like to have an attribute that does the trick

So as this is a quite challenging thing I’ve started writing my custom attribute More...


Oct 30 2011 MVC3: entity framework 4.1 UniqueValue attribute validator

Category: ASP.NET | C# | Linq | MVC3 — Duke @ 15:28

I’m playing with MVC3 and EF4.1 (magic unicorn version) for a nice project I’m working on, and I’ve found myself in the situation to validate some fields against value duplication

(think about username, or other things that must be unique).

Unfortunately we don't have [Unique] constraint attribute in EF4.1 yet, so I’ve thought to leverage on the validation infrastructure of MVC3 to ensure uniqueness of the values.

I like the simplicity and expressiveness of the attributes then I’ve implemented my UniqueValueAttribute class.

this is remarkable because now I have a simple way to decorate every model attribute I want to be unique

(lot of fun code follows) More...


Sep 26 2011

Visual Studio 2010 my tests doesn’t pass if I run them, but pass if I debug!

Category: — Duke @ 18:45

today I had a bizarre experience using nhibernate.

I’m writing an audit trail system on the top of nhibernate, that have to satisfy certain regulatory requisites.

Of course I’ve a lot of test that proves that my work is proceeding in the right direction. But this morning I’ve added few line of code to introduce a new feature that at the end requires a “references” clause in the nhibernate mapping.

Suddenly some of the test went broken.

I’ve tought that I’ve wrote something wrong in my code so I’ve run the test in debug mode… and guess what? all the test pass…

I’ve then tought that there was some particular situation (maybe some file locked or god-knows-what-like situation that have caused the transient… or what I’ve supposed to be a transient) and then everything was returned normal.

so I’ve wrote other few lines of code and run the test again and BANG! red again…

this time I’ve started investigating more, I’ve lost the whole morning

the symptoms were the followings.

1) if I RUN the test form the test list windows of visual studio, some of the test (and always the same tests) systematically fails.

2) if I DEBUG the failing tests from within the test result window or the test list window the exact same test pass

3) from the moment when the test PASS in DEBUG, I could RUN the test again from the test result windows, and they KEEP passing

4) if for any reason I RUN again the same exact test from the test list window they start failing again.


the error message when they fail was something like “the property method get_Xyz could not be found”

and in fact that was the property I was working on.


at the end I’ve discovered the cause.

the Code coverage instrumentation was activated on the assembly I was editing.

for a reason that nobody will ever know, visual studio have cached somewhere (probably over the rainbow) something about how to instrument the assembly I was working on.

no mater how I’ve tried to delete the BIN and OBJ and TestResults of all the involved projects… they keep presenting the same behavior.

Guess what? this visual studio magical cache went for another unknown reason out of date.

and the result (I’ve figured out) was that out of date code was keep injected in my code causing all the sort of the bad things… but only if I RUN the test.

Luckily the DEBUG of the test doesn’t inject (outdated) the instrumentation code.


Once understood that the code coverege was the cause it was easy to solve.

just shut the code coverege down, recompiled everything, runned the code => green, debugged the code=> green!

after this I’ve turned on the code coverage again and tested the tests another time: green again! YAY!


So, if your test starts to become reds without any reason, give a look at the code coverage Sorriso


Sep 22 2011

Visual Studio 2010 Expression Tree Debugger Visualizer: how to make it work.

Category: C# | Visual Studio — Duke @ 19:21

I’m developing a quite complicated (it is always complicated when you have to manage big trees) project.

As in the project there are a lot of trees that are moving around (never seen a tree walking down the streets?)  and transforming themselves I’ve thought that it could be nice to use a Debug Visualizer to have a clearer view of the structure of these expression trees.

I know, the visual studio 2010 have the new DebugView property that makes it inspect the tree.. but it is still complicated to read when you have kilometric long namespace names that ends in generic object that in turn uses generic parameters with (again) long names.

it is a mess Triste

so I’ve decided to use the old but still good Expression tree visualizer available from the Visual studio 2008 C# code samples.

Downloaded, changed the reference to the Microsoft.VisualStudio.DebuggerVisualizers.dll library so to reference the newest one (C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.VisualStudio.DebuggerVisualizers.dll) and then compiled.

But here starts the problem:

My configuration is Windows 7 64 bit Ultimate and Visual studio 2010 Ultimate (with latest service packs and everything)

My projects are all in .Net 4.0 at the moment I'm writing.

I’ve compiled the visualizer, put it in the right folder

C:\Users\Duke\Documents\Visual Studio 2010\Visualizers

and BAM! …. nothing Triste

nothing appear, no magnifier  when I hover an expression reference.

I’ve tried to moving the visualizer in all the possible valid location (also considering the 64 bit architecture) but noting!

Binged and Googled… I’ve found that many people have had the same issue.

So I’ve started looking inside the actual code, and here it is!


[assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizer), typeof(ExpressionTreeVisualizerObjectSource), Target = typeof(Expression), Description = "Expression Tree Visualizer")]

Sooooo wrong! I’ve fixed it this way


[assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizer), typeof(ExpressionTreeVisualizerObjectSource), Target = typeof(Expression<>), Description = "Expression Tree Visualizer")]

Note typeof(Expression) transformed in typeof(Expression<>)

The type to visualize should be the generic one to work with the last version of the framework.

Recompiled, dropped in the right folder and this time IT WORKS!

Ok! now it works like a charm I hope this could help also other people with the same issue Sorriso


Aug 19 2011

SyncWcf published!

Category: — Duke @ 18:49

I’ve published SyncWcf on codeplex:

there is a lot of reason that have moved me to do this work during my holidays.

First of all I need it. it is too complicated to maintain the code that silverlight require to call a webservice. the fact that it needs an asynch version of the service interface is inaceptable to me.

the fact that there are two unrelated interfaces that logically represents the same thing, it is substantially wrong to me

Second: I think that my team need it. I’m working with people on a business-line project. these people are very good developers but they have no experience with silverlight. it is the first project they works on that uses such kind of technology.

I think they are still try to handle the correct way to implement model-view-viewmodel, and I don’t think they need to understeand the extra complexity of the async call for wcf.

Third: “Add service reference” generates code difficult to understand, hard to handle and very prone to generate errors. I really think that there is a better way if the server side code and the client side code are in the same hands, I want the two things are strongly related, I want to use refactoring tools at server side  and the modifications are propagated on the client side as well, I don’t want to remember to myself to do “update service reference”. Anyone has got good reasons to dislike the automatically genererated client proxies…

to me they are good in case the service I have to interface to is from a 3rd party or it comes from a technology that is not .NET or in any case it is not something “internal” to my project (some external system I have to interface to)


All these reasons moved me to write SyncWcf.

One of the nicer part to me is the fact that SyncWcf uses only Silverlight assemblies: no need to include any other 3rd party library (no need of castle or any other proxy generator)

Another think I like most is the way you call an operation by using lambdas… and the fact that out and ref parameters really works in the way it is intended!

Last, thewre is the full support to intellisense. To me intellisense is one of the greatest inventions, I have payed a lot of attention in supporting it the best way possible.

I’m using SyncWcf in a real project, so I have the chance to see it in action. anyway I think there is still lot of things to do to improve it.

For example I suppose there should be place to enhancement in the area of the duplex communications, but unfortunately my project are not using these at the momet… so feedbacks will be greatly appreciated (not only on the duplex part… on everything you think could improve the library)!

So, the library is in a stable state now, there is documentation, how tos, manuals source code and binaries ready to be downloaded. just run on codeplex and press “download”

The bits are waiting for you! and I’m waiting your feedbacks!!


Jul 8 2011

Windows Phone Marketplace error c101c404

Category: Windows Phone — Duke @ 11:34

It is a couple of month I’ve started receiving the error c101c401 when I try to buy something using my windows phone.

I’ve tried to fix for what was possible to me, but I’ve not found the solution.

Today I had a day off from work and I’ve thought to call the support: first thing about the windows phone support I’ve to say: they are amazing!

I’ve never ever found a support service so gentle and competent, I rate them 10 out of 10!

The girl that have answered to me called me back at least 5 times today proposing new ways to solve the solution, searching in their KB and providing useful information to solve the issue.

At the end we have solved the problem and it was (as often happens) a stupid thing that have caused the issue: or better there was two issue



Mar 14 2011

Stairs the game

Category: — Duke @ 15:27

It’s a couple of week I’ve started to work on a project, the codename is “Stairs” (twitter hashtag #stairsgame) and it is an Indie game for Windows Phone 7 (and therefore XNA).

At the moment it will be just for WP7, no plans to port in on XBOX or PC.

The game is a sort of puzzle, but rather than point on the innovation in the gameplay It will focus on the visuals.

I want to make it appear as an anime. I love Hayao Miyazaki and I want to make something that may remember the feelings of his movies.

Of course I’m not that good in drawing, unfortunately, but I want to make the character very “live” and fort his reason the game will be animated using traditional MANUAL animation.

I’ll draw all the frames on paper, but I don’t want another game where the object appear made by paper… I don’t like that style too much.

I want to make the real thing, real traditional animation: with animation disk, peg bars, punched paper and alcohol-based markers. Pencils and rubbers will be a must, the background will be painted and all the art will be produced outside the computer.

Of course the pc will play a role in the digitalization and maybe in the fixing of some defects, but I hope it will be the minor part.

I’ve always loved to draw, and sadly in the last year I don’t had the chance to practice too much so my skill was lowered a lot… from when I was at my top, but I’m studying and practicing every evening and watching a lot for anime and reading manga, also I’ve studied some books and other I will study soon.

I hope to make something visually pleasant, and that feels different from the other heartless games.

if you are interested in a daily update on the project follow me on twitter A bocca aperta.

Ok the today plan is to setup the Visual studio solution, not so hard, huh?

I hope to post some screen shoots of the game soon but not today obviously, I hope you like the idea behind the game!

More about the gameplay in the next post!