Tag Archives: Free Software

Ninject: connect an IProxyFactory component to the kernel

Because it’s the second time that i run into this i will post the solution here so that i (and all the other people that run into the same issue) can easily solve it next time. Anyway, i was playing with Ninject and ran into the following exception:

Error activating XXX: the implementation type YYY requests static interceptors, or dynamic interceptors have been defined.
In order to provide interception, you must connect an IProxyFactory component to the kernel.

If you search for implementations of IProxyFactory you will find the DynamicProxy2ProxyFactory and the LinFuProxyFactory classes. But how can you tell your kernel to use them? This is pretty simple (but hard to find on the web):

Kernel.Components.Connect<iproxyFactory>(new DynamicProxy2ProxyFactory());

Instead of writing this code to connect the ProxyFactory implementation you can also use the XXX module (which does it for you) as following:

var kernel = new StandardKernel(new DynamicProxy2Module(), new BusinessModule());

Using sed

For a couple of days now i’ve been pondering about posting something about my love for GNU text-utilities but never got round to it. A couple of minutes ago i read Phil Windley’s Using Grep and Find post so here is a one-liner that shows how you can add a reference to a msbuild target file to all csproj files in a given folder:

find -name *.csproj -exec sed -i -e '#^</project>$#  <import Project="X:\\BuildTasks\\Corp.targets" />\r\n</project>' {} \;

Or if you are frustrated with System.Diagnostics.CodeAnalysis.SuppressMessageAttributes and want to remove them from all your cs files:

find -name *.cs -exed sed -r -i -e  's#\[.*?SuppressMessage.*?\]##' {} \";

Build OpenSSL with Visual Studio 2008

These days building OpenSSL with Visual Studio 2008 has become really easy. I don’t like to edit .cnf files so i decided to patch the code a little so that the default configuration file becomes openssl.config:

string basePath = @"C:\src\openssl-0.9.8g";

string originalConfigfile = "openssl.cnf";
string updatedConfigfile = "openssl.config";
foreach (string filename in Directory.GetFiles(basePath, "*.*", SearchOption.AllDirectories))
{
 string contents = File.ReadAllText(filename);
 if (contents.Contains(originalConfigfile))
 {
  Console.WriteLine(filename);
  File.WriteAllText(filename, contents.Replace(originalConfigfile, updatedConfigfile));
 }
}

File.WriteAllText(basePath + @"\apps\" + updatedConfigfile, File.ReadAllText(basePath + @"\apps\" + originalConfigfile));

Open a Visual Studio 2008 Command prompt and add references to the Microsoft SDK as following:

SET PATH=%PATH%;C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin
SET LIB=%LIB%;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib
SET INCLUDE=%INCLUDE%;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include

Now we simply have to follow the tasks listed in INSTALL.W32:

perl Configure VC-WIN32 –prefix=c:/openssl
ms\do_masm
nmake -f ms\ntdll.mak
nmake -f ms\ntdll.mak test
nmake -f ms\ntdll.mak install

Happy OpenSSL’ing!

Running .NET applications on Debian GNU/Linux with Mono

Today i noticed Running .Net applications on Linux with Mono and the author wrote the following:

I found that on Debian at this stage I got an error: The assembly mscorlib.dll was not found or could not be loaded. It should have been installed in the ‘/usr/lib/mono/2.0/mscorlib.dll’ directory. I cured that by executing:
$ cd /usr/lib/mono
$ sudo ln -s 1.0 2.0

There is only one error, and it’s in the PEBKAC category. I can understand that the author couldn’t find the TargetFrameworkVersion tag in his project file and generated 2.0 code. What i don’t understand is that he didn’t notice the Other Downloads section and that there are Debian packages available with support for the 2.0 runtime. Ok, apt-get might complain about the packages and you would have to add a key to your keyring as following before you can install the packages:

gpg –recv-keys 7127E5ABEEF946C8
gpg –armor –export 7127E5ABEEF946C8 | apt-key add -

How hard is that? :P

Building apache-win32 with Visual Studio 2005

Today i decided to build apache-win32. Here’s how i did it:

  • Download Apache httpd-2.2.0-win32-src-rev2.zip.
  • Unzip and read README.TXT, INSTALL.TXT and docs/manual/platform/win_compiling.html.en
  • Save awk95.exe as awk.exe in a directory that’s in your %PATH%.
  • Open Apache.dsw with VS2005 and choose “Yes To All” to convert the project.
  • Uncheck abs, mod_deflate and mod_ssl in the the configuration form via Build -> Configuration Manager.
  • Choose InstallBin, click right and Set as StartUp Project.
  • Open InstallBin/Makefile.win and remove the lines 129, 130, 131, 133, 134, 135 and 136.
  • Start debugging (F5). Stop debugging and end the httpd.exe process via your Task Manager.
  • Download and extract zlib-1.2.3.tar.bz2 into srclib/zlib.
  • Prepend “dword ptr” to the second argument of the movd instructions on lines647, 649, 663 and 720 in srclib/zlib/contrib/masmx86/inffas32.asm
  • Open srclib/zlib/projects/visualc6/zlib.dsp, choose the zlib project in the solution explorer. Choose “LIB ASM Release” in the configuration explorer and build zlib.
  • Copy srclib/zlib/projects/visualc6/Win32_LIB_ASM_Release/zlib.lib to srclib/zlib.
  • Check the mod_deflate in the configuration form via Build -> Configuration Manager.
  • Choose the mod_deflate project in the solution explorer and build it.
  • The original openssl-0.9.8a.tar.gz doesn’t compile with Visual Studio 2005 but someone has already made a patch. Download openssl-0.9.8a-vc2005.zip and extract it into srclib/openssl.
  • Open a Visual Studio 2005 Command Prompt and cd to the openssl directory and run: “perl Configure VC-WIN32″ (don’t close this prompt yet).
  • Insert before line 61 in srclib/openssl/ms/do_masm.bat the following line: “perl util\mk1mf.pl debug dll VC-WIN32 > ms\ntdll-dbg.mak”. Now run: “ms\do_masm” and “nmake -f ms\ntdll-dbg.mak”.
  • Check the abs and mod_ssl project in the configuration from via Build -> Configuration Manager.
  • Build the two projects.
  • Done!

GNU screen

Another tool that belongs to my favorites is GNU Screen. A couple of years ago i had a bad internet connection and when i was working on a remote shell i was always logged out and had to start over. I really hated that ;) Today i don’t have this problem anymore, but i like to keep Irssi (an IRC user-agent) running, even when i’m not logged in. TIP Using Screen is an article that gives a couple of other reasons to use it and explains how it works. The default settings suck if you also use GNU Emacs. So i had to figure out a couple of keypresses. With “cat -v” i could easily see what those keypresses were. Here is my .screenrc file:

##############################################
# Author: Tim Van Wassenhove
# Update: 2006-02-06 03:02
##############################################
startup_message off
escape ^Oo

bind i screen -t 'irssi'        3 irssi
bind v screen -t 'vim'          4 vim
bind m screen -t 'mutt'         5 mutt
bind b screen -t 'slrn belnet'  6 slrn -h news.belnet.be
bind r screen -t 'slrn php'     7 slrn -h news.php.net
bind e screen -t 'elinks'       8 elinks http://www.google.com

GNU sort

I already wrote that GNU Core Utilities (GNU Textutils) have become my favorite text processing tools. Today i wanted to sort a couple of lines using the last three numbers of each line. Here is an example:

c:/data/backup/JA-229
c:/data/backup/JA-221
c:/data/backup/JA-233
c:/data/backup/NE-046
c:/data/backup/NE-049
c:/data/backup/JA-217
c:/data/backup/JA-225

With the command “sort -n -t- -k2 myfile.txt” i quickly got what i needed.

Setting up an SSH tunnel

On the machine example there is a (tcp/ip) program listening on port 12345. The protocol it talks is some plaintext language. I want to talk with it, but i don’t want others to know what i’m sending to it. I’m lucky enough to have remote access to that machine via ssh. I setup a tunnel with the following command:

ssh -N -L 12345:example:12345 timvw@example

Now my program can connect to localhost:12345 and ssh will make sure that it ends up at example.:12345 without others being able to see the actual data :) For windows users i suggest that you take a look at Plink.

Format sourcecode with VIM

I once read an article that explained how i could make Vim format my code but i forgot what the command was. Many websearches for “vim indent code” later i had the luminous idea to search for “vim format code” instead. The first site i visited already had the answer i had been looking for: “gg=G”. Simple as that :)

Problem with Base and MySQL support

Today i decided to try out the new OpenOffice.org release. Creating a presentation with Impress went pretty smooth. After that i wanted to check out Base with a MySQL backend but i got an error message that the JDBC driver could not be loaded.

Could not load JDBC driver dialog

I immediately knew that i had to add the MySQL driver to the classpath. A little websearch learned me i have to choose Tools->Options in the menu. And from there i can modify the classpath via the OpenOffice.org->Java panel.

Java configuration dialog

Add MySQL Connector/J to classpath dialog

Could load JDBC driver dialog

After that everything went smooth :) There are so many sites talking about the new release and all the new features but none of them seem to have experienced this. It makes me wonder if they have really tried it out..