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
Else
cerr = -(1000000 + Err.Number)
End If
errMsg += "|ExecService:" + Err.Description + " " + Err.GetException.StackTrace
log.Error(errMsg)
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).

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

log4net.Config.XmlConfigurator.Configure()

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:

http://www.codinghorror.com/blog/archives/000976.html

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.

Wednesday, 26 September 2007

Drop down list in Excel

I always have a hard time remembering how to make dropdown lists in Excel, her is a nice tutorial of how to do it:
Excel dropdown

And when you make a mistake, as me, this tutorial shows how to edit the list.

edit dropdown

Thursday, 20 September 2007

Playing with sockets in vb.net

I am having trouble with sockets. I send a message and want to retrieve some information. Until now I thought that it was the receive which gave me the problems, but in fact the problem arrives before. Cause the send method throws a SocketException with the text “The attempted operation is not supported for the type of object referenced”.

nb = s.Send(ByteSend, ByteSend.Length, SocketFlags.Peek)

Now this doesn’t really help me. So I looked for the Error code, which were 10045. Looking in the error code list (link) gave me the following additional knowledge (or whatever you want to call this message) :
Windows Sockets Error Codes:

WSAEOPNOTSUPP 10045
Operation not supported.
The attempted operation is not supported for the type of object referenced. Usually this occurs when a socket descriptor to a socket that cannot support this operation is trying to accept a connection on a datagram socket.


Now did that help. I ended giving up on the code so I cant really tell you what the solution is. But for reference, I choose to publish this post anyway. Sorry