Archive for the 'Computer Science' Category

Page 5 of 7

“UnauthorizedAccessException” in your ASP.NET application

If you get an “UnauthorizedAccessException” or when all else fails try the following on the windows command line:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>aspnet_regiis.exe -i

It really performs miracles :)

VMware Server auf Ubuntu 6.06 AMD64

Bekannterweise macht das Installationsskript des VMware Servers ein paar Probleme falls irgendwelche Bibliotheken nicht installiert sind. Oder besser gesagt, es bricht (meistens) ohne Fehlermeldung einfach ab! :(

Genau dieses Problem hatte ich letztens bei der Installation des VMware Servers auf einem 64 “bittigem” Ubuntu 6.06. Nach einer fast endlosen Suche im Web habe ich doch noch die Lösung gefunden: Es fehlte das Paket “ia32-libs”, das einfach mit APT nachinstalliert werden muss:

apt-get install ia32-libs

Ubuntu-Kernel auf 1&1 Root-Server L64 neu kompilieren

Seit September habe ich nun einen eigenen Root-Server bei 1&1. Obwohl es auf der Produktübersicht nicht dargestellt wird, bietet 1&1 doch verschiedene vorinstallierte Server-Betriebssysteme (Images) zur Auswahl:

  • SuSE 10.1 (mit oder ohne Plesk) – 32 oder 64 bit
  • SuSE 9.3 (nur mit Plesk) – 32 oder 64 bit
  • Fedora Core 6 – 32 oder 64 bit
  • Ubuntu 6.06 – 32 oder 64 bit
  • Debian 3.1 stable/sarge – 32 oder 64 bit

Nach langem Ausprobieren habe ich mich letztendlich für eine 64 “bittige” Ubuntu-Installation entschieden. (Mit ist im Übrigen aufgefallen, dass die 32 bit-Images auf einem 64 bit-System nicht funktionieren und hoffe, dass das Problem bei 1&1 bereits bekannt ist.) Das Ubuntu-Minimal-Image ist wirklich ideal, wenn man den Server “per Hand”, also ohne Plesk-Gedöns o.ä., konfigurieren möchte.

Allerdings gibt es dabei einen kleinen Wermutstropfen: die Jungs und Mädels von 1&1 haben zwar einerseits eine halbwegs aktuelle Kernel-Version (bei mir 2.6.16.53) in das Image integriert, nur leider haben sie erstens den Kernel mit dem veralteten GCC 3.x übersetzt und zweitens die Kernel-Sourcen nicht mitgeliefert. Das ist sehr, sehr unangenehm genau dann wenn man zusätzliche Kernel-Module übersetzen und einbinden möchte. (Das ist zum Beispiel dann der Fall, wenn ein VMware-Server installiert wird.)

Ist aber kein Problem, man kompiliert und installiert den vorhandenen Kernel, mit der identischen Konfiguration, einfach neu! Zuerst ist es allerdings sinnvoll, die Paketliste (apt-get update) und die Pakete an sich (apt-get upgrade) zu aktualisieren. Anschließend sollte noch das benötigte Handwerkszeug (apt-get install) installiert werden.

apt-get update
apt-get upgrade
apt-get install build-essential kernel-package

Okay, dann ist es auch schon an der Zeit, die Kernel-Quellen von kernel.org herunterzuladen (wget) und im Verzeichnis /usr/src zu entpacken (bunzip2). Optional sollte noch der symbolischen Link (ln) “linux”, der immer auf die Quellen der gerade installierte Kernel-Version zeigt, in diesem Verzeichnis angelegt werden.

cd /usr/src
wget http://www.eu.kernel.org/pub/linux/kernel/v2.6/linux-2.6.16.53.tar.bz2
bunzip2 < linux-2.6.16.53.tar.bz2 | tar xvf -
ln -s linux-2.6.16.53 linux

Und nun wird es ernst: In das Quellen-Verzeichnis (linux) wird zunächst die bestehende Konfigurationsdatei hineinkopiert (cp), d.h. die alte Konfigurationsdatei ist auch gleichzeitig die neue, da ja der Kernel mit der identischen Version lediglich neu kompiliert wird. Anschließend wird der Übersetzungsprozess ausgeführt (make). (Mit dem Parameter --revision kann ein eineindeutiger Revisionsname festgelegt werden.)

cd linux
cp /boot/config-2.6.16.53-070731a .config
make oldconfig
make-kpkg --initrd --revision v1 binary

Das wäre geschaft! Jetzt muss nur noch der Debian Paket Manager (dpkg) angeworfen werden, um das neu erstellte Kernel-Image zu installieren. Noch kurz dem Boot-Manager LILO (lilo) Bescheid geben, dass es einen neuen Kernel gibt und abschließend mit reboot das komplette System neustarten.

cd ..
dpkg -i kernel-image-2.6.16.53_v1_amd64.deb
lilo
reboot

Sollte der Neustart nicht funktioniert haben, kann man sich mit der Remote-Console genau anschauen, wo es hängt. Alternativ vielleicht das ganze System mittels Server-Initialisierung neuinstallieren und einen neuen Versuch wagen! :)

Disabling Shell History Logging

It is just a simple setting I need everytime installing a new unix machine. May be it’s paranoid but in my opinion the file-based history logging should be disabled for security reasons – at least in the root account. You can easily do that by open the .bashrc file in the particular home directory and add the following line(s):

export HISTFILESIZE=0

Disables the file-based history logging.

export HISTSIZE=0

Disables the history logging.

By the way zero in the two statements above means: 0 entries in the history = history is disabled :)

Adding locales to Ubuntu

Lately I was confronted with the problem making Gallery2 (which I installed here) multilingual. Of course Gallery2 supports nearly “all” languages out of the box. The only additional thing you have to do is installing gettext and the corresponding locales. Apropos locales: I think that’s very well to say but how can you do this the command line way?

Firstly open the following file, find your favored locale and copy the line into the clipboard:

/usr/share/i18n/SUPPORTED

Now paste the previously selected locale into the following file:

/var/lib/locales/supported.d/local

Finally let the package manager update the new locale settings:

dpkg-reconfigure locales

That’s it!

MSBuild XSLT Task

Regarding my former article now I’d like to give you a further example for a helpful MS Build task – namely XSLT.

The following task implementation takes the definitions of a source file, a target file as well as a XSLT file and transforms the file by using these properties. Internally it uses the method XslCompiledTransform.Transform() for the transformation process. As you can see at line 40-43 it’s a only a simple code snippet:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
 
namespace XSLTTask
{
    public class XSLT : Task
    {
        private string xsltFile;
 
        private string sourceXmlFile;
 
        private string targetXmlFile;
 
        [Required]
        public string XsltFile
        {
            get { return xsltFile; }
            set { xsltFile = value; }
        }
 
        [Required]
        public string SourceXmlFile
        {
            get { return sourceXmlFile; }
            set { sourceXmlFile = value; }
        }
 
        [Required]
        public string TargetXmlFile
        {
            get { return targetXmlFile; }
            set { targetXmlFile = value; }
        }
 
        public override bool Execute()
        {
            bool result = true;
 
            Log.LogMessage("Transforming from {0} to {1} using {2}",
                SourceXmlFile, TargetXmlFile, XsltFile);
 
            try
            {
                XslCompiledTransform xslTransform = GetXslTransform(XsltFile);
                XmlReader xmlReader = GetXmlReader(SourceXmlFile);
                XmlWriter xmlWriter = GetXmlWriter(TargetXmlFile);
                xslTransform.Transform(xmlReader, xmlWriter);
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e);
                result = false;
            }
 
            return result;
        }
 
        XslCompiledTransform GetXslTransform(String file)
        {
            XslCompiledTransform xslTransform = new XslCompiledTransform();
            xslTransform.Load(GetXmlReader(file));
            return xslTransform;
        }
 
        XmlReader GetXmlReader(String file)
        {
            return new XmlTextReader(GetTextReader(file));
        }
 
        XmlWriter GetXmlWriter(String file)
        {
            TextWriter textWriter = new StreamWriter(file);
            return new XmlTextWriter(textWriter);
        }
 
        TextReader GetTextReader(String file)
        {
            return new StreamReader(file);
        }
    }
}

And here comes the task definition embedded in a MSBuild project file:

1
2
3
4
5
6
7
8
9
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
  DefaultTargets="Default">
  <UsingTask AssemblyFile="XSLTTask.dll" TaskName="XSLT" />
  <Target Name="Default">
    <XSLT SourceXmlFile="input.xml"
          TargetXmlFile="output.xml"
          XsltlFile="transform.xslt"  />
  </Target>
</Project>

MSBuild Sleep Task

Do you know how to pause a MS Build task? Here I’d like to give you an option by writing a simple task which can be included in a project file.

First create a new C# Class Library Solution called “SleepTask”, Copy & Paste the following C# code and compile the entire solution. But don’t forget to add the Microsoft.Build.Framework and Microsoft.Build.Utilities references in your project.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System;
using System.Threading;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
 
namespace SleepTask
{
    public class Sleep : Task
    {
        public override bool Execute()
        {
            Thread.Sleep(Timeout);
            return true;
        }
 
        private Int32 timeout;
        public Int32 Timeout
        {
            get { return timeout; }
            set { timeout = value; }
        }
    }
}

Now write a new MS Build project file (e.g. Project.xml) and Copy & Paste the following XML tags. With the “Timeout” attribute you can define the timeout in milliseconds for the SleepTask (e.g. 3 seconds). Before running the project you have to copy the SleepTask.dll assembly into the folder of your Project.xml file, of course.

1
2
3
4
5
6
7
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
  DefaultTargets="Default">
  <UsingTask AssemblyFile="SleepTask.dll" TaskName="Sleep" />
  <Target Name="Default">
    <Sleep Timeout="3000" />
  </Target>
</Project>

Finally run your MS Build task by typing the following command (use the Visual Studio Command Prompt) and see that the task is paused because of the defined timeout.

MSBuild Project.xml

Visual Studio 2005 Image Library

Here comes the path to the Visual Studio 2005 Image Library ’cause I forget that every time. There’s a ZIP file that contains almost all well-known bitmaps for menubars und toolbars as well as animations for windows and dialogs. Just extract that archive and assign the images to your forms. That’s it!

C:\Program Files\Microsoft Visual Studio 8\Common7\
   VS2005ImageLibrary.zip

Tapping the Mono C# compiler (mcs) [cont'd]

Regarding my former article now I’d like to give you a continued HowTo for tapping the Mono C# compiler with support for generics, nullable types and friend assemblies. Compared to the mcs tool (.NET 1.1 target runtime) you have to compile the gmcs fork (.NET 2.0 target runtime) of the mono compiler project.

As shown in my previous post first of all you must run the jay parser generator. But now please use the cs-parser.jay input file in the gmcs directory. Again jay will create the output file cs-parser.cs.

In the first step create a new Visual Studio solution and choose C# Class Library as project type. Afterwards add all *.cs files of the following directories to your project:

+ MONO-SRC\mcs\mcs
+ MONO-SRC\mcs\gmcs

Preferably you can put the whole mono stuff in a subdirectory of your solution and import the files listed above as links. Don’t forget to exclude the following two files because they are already present:

- MONO-SRC\mcs\mcs\AssemblyInfo.cs
- MONO-SRC\mcs\mcs\generics.cs

Finally please also add all files of …

+ MONO-SRC\class\Mono.CompilerServices.SymbolWriter

… as soon as the CryptoConvert.cs file of:

+ MONO-SRC\class\Mono.Security.Cryptography

In the second step define the following three Conditional Compilation Symbols in your Project Properties via the Build pane:

  • GMCS_SOURCE
  • MS_COMPATIBLE
  • NET_2_0

From now on you can compile gmcs. Well, there still exists a few warnings but I think you can ignore that till anytime gmcs becomes the default mono compiler :)

Enumerating Outlook contacts & Updating birthdays in Outlook calendar

Today I’d like to give you a short example how to enumerate all contacts in Microsoft Outlook 2003:

1
2
3
4
5
6
7
8
9
10
11
12
13
Sub enum_update()
  Dim namespace As namespace
  Dim contacts As MAPIFolder
  Dim contact As ContactItem
 
  Set namespace = Application.GetNamespace("MAPI")
  Set contacts = namespace.GetDefaultFolder(olFolderContacts)
 
  For Each contact In contacts.Items
    contact.LastName = contact.LastName
    contact.Save
  Next
End Sub

If you import contacts from a personal folder file (.pst) the birthdays in all contacts won’t be updated in the calendar. Don’t worry, just run the VB script above. It simply simulates a change in each contact and saves it again :)