.NET Versioning Riddle

September 1, 2017 on 10:10 am | In Uncategorized | No Comments

We have a .NET application compiled with .NET Framework 4.5 as a target.

The riddle is: why does this application work on Windows 7 with only .NET Framework 4.0 installed but not on Windows Server 2003 with the same .NET Framework 4.0 installed?

The answer it twofold. The first part is easy:

1. Why does the application compiled with .NET Framework 4.5 as a target even works with .NET Framework 4.0?

It is because the CLR is still the same. It is 4.0. Have a look with ildasm at a simple exe or dll targeted for .NET Fraemwork 4.5 and you will see:

image

So the app will work but, as Microsoft puts it in https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/versions-and-dependencies “We do not recommend running apps that target a later version of the .NET Framework on the an earlier version of the .NET Framework.” So it will work up until the time where you access some specific .NET 4.5 functionality where it will crash.

So I guess if you want your app to be specific about the minimal .NET Framework Version it needs, you will have to check it yourself. For example as suggested in here: https://www.hanselman.com/blog/NETVersioningAndMultiTargetingNET45IsAnInplaceUpgradeToNET40.aspx

2. The second part of the question is more tricky. Why does it work with .NET Framework 4.0 in Windows 7 but not with the same .NET Framework 4.0 in Windows Server 2003?

As it turnes out (I have not found the answer at Microsoft but on StackOverflow: https://stackoverflow.com/questions/17499351/is-it-possible-to-run-a-net-4-5-app-on-xp) the compiler for the app targeting .NET Framework 4.5 sets the file header (https://msdn.microsoft.com/en-us/library/ms809762.aspx) to be compatible with Windows Version 6.0 (Vista and up – https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions) or newer. You can check it out by using dumpbin /headers from VS command line:

image

4.00 operating system version
0.00 image version
4.00 subsystem version

If you compile the app with .NET Framework 4.0 as a target the file header looks like this:

image

4.00 operating system version
0.00 image version
6.00 subsystem version

So the minimal Windows version is 4.0 being Windows 95 and up.

4Developers conference in Warsaw

March 18, 2014 on 8:41 pm | In Uncategorized | No Comments

jestem_prelegentem_4dev

I will be speaking at the 2014 4Developers conference in Warsaw, Poland. In a matter of fact I have not one session but two! Tja, it’s actually THE one. But divided into two parts. Nevertheless a great deal of .NET continuous integration goodness comes into your direction. Watch out! For details see the conference website (Polish only). 4Developers conference .NET Track. April 4th 2014 at the Gromada Hotel Airport in Warsaw. Don’t miss it!

Classification of automatic software build methods

October 17, 2012 on 12:07 pm | In Uncategorized | No Comments

Here is the online version of my article that was published in a chapter of a book at Opole University of Technology (ISBN 978-83-63015-10-7).

Classification of automatic software build methods

Summary: The process of creating working software from source code and other components (like libraries, database files, etc.) is called “software build”. Apart from linking and compiling, it can include other steps like automated testing, static code analysis, documentation generation, deployment and other. All that steps can be automated using a build description of some sort (e.g. script). This article classifies the automatic software build processes beginning at build script and reaching the various types of continuous integration.

Keywords: software build automation, continuous integration, commanded integration, scheduled software build, triggered software build

Citation:
Kawalerowicz, M. (2012). Classification Of Automatic Software Build Mothods. Prace doktorantów / Články doktorandů (pp. 37–39). Opole, Poland: Opole Univeristy of Technology.

Enjoy!

Standalone portable IIS with your site

April 27, 2012 on 6:38 am | In Uncategorized | 2 Comments

Let’s say you have a following task: your small ASP.NET (MVC) website needs to be run on a computer that does not (necessarily) IIS have installed. How to make it possible?

You can do it using IIS Express. It is a small version of IIS server that Microsoft ships for free with at http://www.microsoft.com/download/en/details.aspx?id=1038. It is shipped with Visual Studio 2010 SP1 too (so there is a chance you already got it in C:\Program Files (x86)\IIS Express). They say it’s not xcopy deployable (meaning you cannot run it without installation) but it kinda is. You have to simply install it on one machine and take out what the files you need (or basically the whole folder) to copy and run it on other machine.

Here is a quick prescription:

1. take your web application and copy it to the folder “web”,

2. take the whole inside of the folder  C:\Program Files (x86)\IIS Express and copy it to the folder “iis”,

3. create a cmd file to run the iis express with your app and place it on the same level as your “web” and “iis” folders, it should look like this:

@echo off
set port=8181
start iis\iisexpress.exe /path:"%CD%\web" /port:%port%
start "%ProgramFiles%\Internet Explorer\iexplore.exe"
http://localhost:%port%

It will start the IIS Express (from “iis” folder) set the web application path to web folder “web” (%CD% is current directory). IIS Express is started on the 8181 port (in fact it does not matter on what port it is started as long this port is free). After that we start the Internet Explorer and direct it to the website. On slower machine it can take some time to start the server (and as we use start command the batch will not wait and start the next command right away) so you can think of a small delay (using for example ping -n 1 1.1.1.1 >nul for 1 second delay).

Such package can be zipped and send to someone to run a local copy of your application. Of course it can be wrapped around another MSI package and automated to pick free port and add an icon to the desktop or start menu.

The only prerequisite for IIS Express to run is .NET Framework 4 and it will run on XP and up. It can run side to side with a “big” version of IIS.

By default IIS Repress hosts only the localhost websites. It is possible to configure it to server over the wire (see http://stackoverflow.com/questions/5235826/using-iis-express-to-host-a-website-temporarily). It should be possible to host a standalone SQL Server version too. But it is a topic for another blog post!

Continuous Integration in Munich

November 23, 2011 on 3:57 pm | In Uncategorized | 1 Comment

Hardy Erlinger, the head of .NET Developers Group München, has just confirmed my session in Munich, Germany. I will be speaking about Continuous Integration in .NET at January 17th. The meeting will take place probably as usual in Firma TESIS at Baierbrunner Str. 15, 81379 München. Start 18:00. Details will be available at the group website www.munichdot.net. Acha, the talk will be in German!

Continuous Integration in .NET book MEAP update

January 21, 2010 on 6:11 pm | In Uncategorized | No Comments

image There are two new chapters available at Manning MEAP site. The third one about build process automation (with MSBuild) and the forth one about choosing the right CI server (covering CCNet, TeamCity and TFS 2010).

And wow the book is third on this weeks bestselling early access titles. Juhu!

Everyone is entitled to broad opinion

October 26, 2008 on 8:18 pm | In Uncategorized | No Comments

I had an interesting dispute with my colleague weather to use only qualified type names in code or not. He insisted that we should not use the using directive to introduce a namespace but to write the fully qualified name every time it is necessary. I had quite opposite opinion but I agreed to give it a try. So I started to write

public class MyClass
{
    public static void Main()
    {
        System.Console.WriteLine("Foo");
    }
}

instead of

using System;
public class MyClass
{
    public static void Main()
    {
        Console.WriteLine("Foo");
    }
}

Unfortunately over time it proofed no value to me. I was not happy with this rule, but I thought I’ll consult the brother audience for opinion before I start a holly war against something that I might not fully understand.

I decided to give stackoverflow.com a try. It is quite new Q&A Service dedicated specially for software developers. I write my question I was given a flood of answers. Some better, some worse. Some hitting the bottom line, some pouring “divine knowledge” of individuals that think they know things better.

Nevertheless the discussion on stackoverflow.com helped my back my opinion. Give it a try!

MTS 2008, Warsaw, Poland

October 12, 2008 on 10:28 pm | In Uncategorized | No Comments

image

Microsoft Technology Summit 2008 (8th and 9th November), the biggest  Microsoft technology event in Poland went quite well. It was my first MTS and I was trying not to expect anything special. And indeed I haven’t experienced anything  earth shaking but altogether it was quite interesting and a good investment of time. I surely learned a few new things and meet interesting people there. I was astonished by the sheer number of attendees that gathered in there. I presume the old communist “castle” in the center of Warsaw the “Palace of Culture and Science” was the only place to accommodate this whole crowd, but it is not a cushy place. It’s big and cold and far from perfect to host a technology event like that. And well… despite the overwhelming size of this place, you almost have to eat you lunch on the floor, because there was no enoimageugh tables ;-)

But I passed the 70-543 Exam there and gained the Microsoft Certified Professional Developer in ASP.NET title. So altogether it was a full success!

What null smaller than 0? Adventures with nullable types in .NET

September 9, 2008 on 9:14 pm | In Uncategorized | No Comments

Lets say we have two nullable integers like this:

int? i = null;
int? j = 0;

Is null smaller than 0

Console.WriteLine(i < j);

False – no it is not.

So probably null is greater than 0

Console.WriteLine(i > j);

False – no it is not greater as well.

All right! So null is equal 0. It has to be, JIT has no other choice, right?

Console.WriteLine(i == j);

Well False too! This two little fellows are not equal too. What? Is it raining frogs and we about to experience Armageddon?

No! We have to use Nullable.Compare() and we will by back in normal world:

switch (Nullable.Compare(i, j))
        {
               case -1:
                  Console.WriteLine("i < j");
              break;
               case 1:
                  Console.WriteLine("i > j");
              break;
               case 0:
                  Console.WriteLine("i == j");
              break;
        }

0 is a little more than null. null is less than 0. null equals null and 0 equals 0.

Uff!

Enum Factory

August 10, 2008 on 9:16 pm | In Uncategorized | 3 Comments

I have a little tip for you. Let’s say you have an enumeration. You need a enumeration constant out of string variable. simply use System.Enum.Parse(). Here a small Snippet Compiler source code.

using System;
using System.Collections.Generic;

public class MyClass
{
    public enum FooBar
    {
        Foo,
        Bar,
        FooBar
    }

    public static void Main()
    {
        WL(FooBarFactory("Foo"));
        RL();
    }

    public static FooBar FooBarFactory(string init)
    {
        try
        {
            return (FooBar)System.Enum.Parse(typeof(FooBar), init);
        }
        catch
        {
            // Do something
            throw;
        }
    }

    #region Helper methods

    private static void WL(object text, params object[] args)
    {
        Console.WriteLine(text.ToString(), args);
    }

    private static void RL()
    {
        Console.ReadLine();
    }

    private static void Break()
    {
        System.Diagnostics.Debugger.Break();
    }

    #endregion
}

Next Page »

Powered by WordPress with Pool theme design by Borja Fernandez.
Text © Marcin Kawalerowicz. Hosting CODEFUSION.