Sunday, 24 January 2016

.NET 4.6 and Roslyn

When comparing .NET and Java there used to be a small difference that I considered as an advantage on the .NET side. The JRE does not come with the Java compiler, so even for writing a helloWorld program you'll need to install the JDK. On the other side, the .NET framework used to be installed with the csc and vbc compilers (they are in C:\Windows\Microsoft.NET\Framework64\v4.0.30319 along with the framework assemblies), so you can open a text editor and start to code.

This has changed a bit with .NET 4.6. You still will find a C# compiler in the framework folder, but the crazy thing is that that is not the new, C# 6, Roslyn based compiler. If you run it you'll see this message:

So where is the brand new cool compiler? The shocking answer is, nowhere, the so important Roslyn, on which Microsoft spent like 5 or more years is not part of the Framework, you'll have to install it separately. It'll get installed by Visual Studio 2015 (Community version also, of course) here: %ProgramFiles(x86)%\MSBuild\14.0\bin, but if you don't want to go through the lengthy installation (I've never understood why Visual Studio is such a monster, it takes much longer to install that installing a full OS like Ubuntu, while installing SharpDevelop takes like 2 minutes) you can just install the nuget package (it's mentioned here). By the way, Roslyn is now named The .NET Compiler Platform. Notice that you don't need Visual Studio to install nuget packages, hopefully you can just get the command-line utility (nuget.exe binary) from here.

So, why would Microsoft decide to keep the new compilers away from the framework? I assume they want to keep the standard Framework slim (apart from the "ultra slim" .NET core). Then, why didn't they also remove the old compilers? Well, the reason why the comilers have been a part of the runtime since its early beginnings is because one part of the base library makes use of them, CodeDom. When you use the CodeDom to create code at runtime, it ends up calling the (classic) csc compiler executable (sure it's strange, even when the old compiler is native code, not managed code, I would say that the normal approach would be to have its logic in a dll and have CodeDom call it via PInvoke). Notice that the 2 main view engines for ASP.NET, Razor and aspx, both use CodeDom to compile the views, so removing the compiler from the runtime would break the CodeDom, breaking pretty important existing code (imagine that if after installing .NET 4.6 on a Server all the Web Apps installed there would stop working!!!

So I guess Microsoft kept the old compilers to avoid breaking code but did not include the new ones (which would involve all the Rosly assemblies) to prevent the runtime from getting fatter. The old consequence is that if you add C# 6 features in your views, they will fail to compile at runtime unless that you specify that you are using an updated version of the CodeDom that uses Roslyn rather than the old compilers, CodeDom Providers for .NET Compiler Platform. It is explained here. The astonishing thing is that when passing these assemblies through ILSpy, they do not seem to reference the Roslyn assemblies (Microsoft.CodeAnalysis.dll and so on):

So I would say they are calling running the (new) compiler .exe. Roslyn offers to us a managed API acting as a compiler as a service, so why the hell these new CodeDom providers would need to run the binaries???
Honestly, I have no idea.

Friday, 22 January 2016

Sessions and Logon Sessions

At some point in the past (quite a while ago) I had read something that gave me the impression that (in the Windows OS) Sessions and Logon Sessions were not the same, but had not found any conclusive information on it. The other day the doubt came up again, and this time I came across this excellent answer in StackOverflow that finally sheds light on the subject, and yes, Sessions and Logon Sessions are different things.

As they mention there, in too many occasions Microsoft itself uses the terms arbitrarily, making it all pretty confusing. Reelaborating a bit what the guy says in his answer, we have:

Main Sessions. These are the Session 0 where the Windows Services run, and the other interactive sessions that you can open on one machine, either by login on the machine lying on your desktop (either being the initial user or by the fast switch user option) or by using remote desktops. These are the Sessions that have Windows Stations, Desktops and so on...

Logon Session. This is mainly a security concept. Everytime a user provides its credentials (by loging to the machine, calling CreateProcesAs from your code...) a Logon Session and a primary Access Token are created. The Access Token points to the Logon Session. Notice that when a process creates another process the child receives a copy of the parent's Access Token, that's how we end up with multiple access tokens that point to the same logon session.
If you launch ProcessExplorer and check the Security Tab in one Process properties, you'll see this:

I assume that information there comes from the Primary Access Token for that process. You can see there both the Session and the Logon Session. A Logon Session is associated to a Session. When you do a new interactive logon on a machine (directly, RD, Fast user switch), a new Session and a new Logon Session (associated to it) are created. If you set a Service to run under a certain user account, you'll see that when the service is started a new Logon Session is created and gets associated to Session 0.
If you do Run As as the same user twice to run 2 applications, each Run As will create a different Logon session and Access Token. Those Logon Sessions will be associated to the session from which you did the Run As

Running SysInternal's logonSessions.exe will show you all the logon sessions on your machine. If you run it with the -p option, you'll see all the processes running in that Logon Session.

To summarize: Each process runs with its own Primary Access Token. An Access Token is linked to a Logon Sessions, and we'll have many Processes/Access Tokens linked to a same Logon Session. A Logon Session is linked to a Session, and we'll have many Logon Sessions assigned to the same Session.

Sunday, 17 January 2016


I have to admit that before I moved to France I hardly had any notion about a city called Lille, just "one more middle size French city up in the north". Once here, I found out that if we consider its Urban area or Metropolitan area, its population is right before Toulouse in the ranking of French cities (the city proper is much smaller), making it the fourth after Paris, Lyon and Marseille. Bearing in mind that so far any French city with more than 20.000 inhabitants that I've been to is is well worth the visit (you'll always have a Hotel de Ville, Prefecture, Palais de Justice and Cathedral to delight your eyes), Lille had to be good place for a weekend. As it's a bit far for going by train I delayed it quite a bit, but last weekend I finally made it there (thanks Easyjet!)

Obviously I had done some reading about the city before going there, and it looked pretty promising, but reality quite exceeded my expectations. Lille does not belong to that group of "small Paris like" French cities like Lyon, Nantes or Bordeaux, it goes in the group of "very unique" French cities, like Toulouse, Marseille and Nice.

The main point to take into account is that Lille lies in what is called French Flanders a part of the historical county of Flanders that nowadays belongs to France. It's pretty curious, it would be easier to imagine a "French Wallonia", but well, Brussels was originally a Flemish city, and it's now mainly French speaking... so it's not so unique. Adding to confusion, it seems that this "French Flanders" area has one part that originally spoke Flemish and another (Lille goes there) that initially spoke Picard (a Romance language). The thing is that with its Flemish past, Lille looks absolutely like a Belgian city Anwerp, Ghent or Brussels. Indeed, having been in all of these beautiful cities, I would say that Lille features the most impressive architectonic ensemble of all of them. The "old Flemish" buildings, like the Vieille Bourse, are amazing, but the "neo Flemish" ones, like the Chambre de Commerce have not lowered the bar.

At the end of last century, faced with the decline of their tradicional industries: coal and textiles, local politicians decided to foster the services sector, and they absolutely succeeded, managing to create a huge economical hub just in between of Paris and Brussels. One of the main milestones in conducting this transformation into the service sector was the Creation of EuraLille, the biggest business district in France after La Défense in Paris and La Part-Dieu in Lyon. This district is a real delight for anyone into modern architecture. It's not too impressive in terms of height (120 meters for the tallest building), but the architectonic features are really remarkable and make wandering around the area a real pleasure. I'd really love to see the projected TESO (Toulouse EuroSudOuest) district to become something similar.

Lille can be a bit disconcerting in terms of population. The city proper is only 230.000 inhabitants, the urban area, that includes several cities (Roubaix, Tourcoing, Villeneuve...) of around 80.000, grows to more than 1 million, and then the metropolitan area, that includes several Belgian cities grows to more than 2 millions. Furthermore, less than 40 kilometers away to each side you'll find 2 more metropolitan areas, each of around 1/2 million: Douai/Lens, and Valenciennes, so it's a heavily urban area, resembling the Rhine_Ruhr in Germany, the Flemish Diamond in Belgium, or the Randstad in the Netherlands. Notice that the 4 areas are part of the Blue Banana, the discontinuous corridor of urbanisation in Western Europe.

Last December, the FN was sadly on the verge of winning the regional elections in Nord-Pas de Calais-Picardie. One of the "start measures" that these bastards want to carry out is taking France out of the EU. Obviously the idea is sickening and ridiculous, but in a city with a metropolitan area that crosses the border into Belgium, the "idea" is just senseless.