Tuesday, 30 October 2007

The type of a vb.net Object

If you need to find verify that an object is of a specific type it can be done in the following way:

If TypeOf Err.GetException() Is DHEException Then

This uses the keyword "TypeOf" and "Is" I have used it to make sure that the exceptions, catched though the bad "On Error" statement, is still handled and the correct error code is returned.

If Err.Number <> 0 Then
If TypeOf Err.GetException() Is DHEException Then
Dim ex As DHEException = Err.GetException
cerr = ex.dheErr
cerr = -(1000000 + Err.Number)
End If
errMsg += "|ExecService:" + Err.Description + " " + Err.GetException.StackTrace
End If

Thursday, 25 October 2007

Configuration exception for log4Net

I have been battling with the following error, for almost three days now:

System.Configuration.ConfigurationException: Error loading XML file c:\windows\microsoft.net\framework\v1.0.3705\Config\machine.config Request for the permission of type System.Security.Permissions.StrongNameIdentityPermission, mscorlib, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed. (c:\windows\microsoft.net\framework\v1.0.3705\Config\machine.config)

I have developed a proxy client which worked perfect when I ran my NUnit tests, but when I tried to make an external application which should use it, there was this error. I finally found the it was a version mismatch between two version of log4net, where I had used 1.0 net version for developing my proxy, I had by mistake added the 1.1 net version of log4net to the application.

Same problem also gave me the following error:

System.TypeInitializationException: The type initializer for "log4net.GlobalContext" threw an exception. ---> System.TypeLoadException: Invalid PInvoke metadata format.
at System.Net.OSSOCK.gethostname(StringBuilder hostName, Int32 bufferLength)
at System.Net.Dns.GetHostName()
at log4net.Util.SystemInfo.get_HostName()
at log4net.GlobalContext..cctor()
--- End of inner exception stack trace ---
at log4net.GlobalContext.get_Properties()
at log4net.Core.LoggingEvent.CreateCompositeProperties()
at log4net.Core.LoggingEvent.LookupProperty(String key)
at log4net.Layout.Pattern.NdcPatternConverter.Convert(TextWriter writer, LoggingEvent loggingEvent)
at log4net.Layout.Pattern.PatternLayoutConverter.Convert(TextWriter writer, Object state)
at log4net.Util.PatternConverter.Format(TextWriter writer, Object state)
at log4net.Layout.PatternLayout.Format(TextWriter writer, LoggingEvent loggingEvent)
at log4net.Appender.AppenderSkeleton.RenderLoggingEvent(TextWriter wriSystem.TypeInitializationException: The type initializer for "log4net.GlobalContext" threw an exception. ---> System.TypeLoadException: Invalid PInvoke metadata format.
at System.Net.OSSOCK.gethostname(StringBuilder hostName, Int32 bufferLength)
at System.Net.Dns.GetHostName()

So if you are fighting with a similar problem, check the versions of you .NET framework and the version of the log4net.

The hint was to read this (link)

Tuesday, 23 October 2007

log4net troubles one among several

After having successfully used log4net to implement a new proxy client ( used nUnit tests to test) I now find myself in some difficulty. Because to test the proxy even further I want to run another program, which uses my Dll to talk to the server.

My first problem is of course that programs are never as loosely coupled as one could wish, and therefore I had to remove some hard coded references from the new test program.

Now that the tests actually run my code, I have a problem with configuring the log4net framework.

First thing is to study the application configuration file a bit, Visual Studio allows you to create a file called app.config by right clicking on the solution title in the solution explorer (the thing usually on the right). This file will then be copied to the bin dir, with the proper name, when the solution is compiled (link).

The thing that should be remember is to add the following line somewhere its sure to be called before the log is used:


At least if you are configuring the log4net in the app.config file.

Thursday, 18 October 2007

Sets created by sql joins

Sorry, no explanation only a link to somebody who does explain, with diagrams:


Tuesday, 9 October 2007

There Ain't No Such Thing As Plain Text.

Encoding, is always a funny thing when you debug distributed application (also client server architectures). For the simple reason, that you test output from the client, might not look the same from the servers point of view, since there might be differences in the encoding.

So remember to think about, what happens to you request string. remember the following example:

Make a string in any given language:

String testString = "Test string";

to print this to the console, use:

System.out.println(testString) <- println uses a default encoding to print it, the bytes in memory.

When the testString goes through several steps, before it is reached by a server.
First et will be encoded to go on the network (socket), and decoded again by the server. There is therefore 3 different places, that a single debug output, can be different from the what the server actually saves.

The following article describe the very basics of encoding, do you self a favor and read it, or something similar.

The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

Its easy and very understandable.