Redirect Registry by Modifying .NET Executable

Yesterday I was troubleshooting an application that was migrated to Citrix XenApp.

The application is able to use a high precision scale which is attached to the client pc’s com port. This com port is redirected to XenApp.

While testing users reported several issues, let’s have a look at them.

Error configuring COM Port
Within the application the comport to which the scale is connected must be configured:

De compoort lezer staat uit

After pressing "Registreer" to register the new com port the following error message was shown

Er staat geen compoort in het register. Registreer eerste de juiste compoort

Read more

Returning a string from unmanaged dll to .net

I write most of my code in unmanaged languages such as Delphi and C/C++. Sometimes I need to interface my code to .net code in which case I create a dll.

A recurring thing is that I need to return string to .net.

There are many ways to do this of course but in all cases we need to manage memory: who will allocate the memory for the string and who is responsible for freeing it?

Read more

warning CS0618: 'System.Net.IPAddress.Address' is obsolete

For a call to a WinApi function I needed to convert an IP Address to an Integer in C#.

This can be done using the System.Net.IPAddress class:

using System.Net;

IPAddress ipa = IPAddress.Parse("");

uint ip = (uint)ipa.Address;

Although this works, the compiler issues a warning: 

warning CS0618: ‘System.Net.IPAddress.Address’ is obsolete: ‘This property has been deprecated. It is address family dependent. Please use IPAddress.Equals method to perform comparisons.′

This warning is issued because the Address property is not IPv6 compatible. The warning can be suppressed like this:

using System.Net;

IPAddress ipa = IPAddress.Parse("");

#pragma warning disable 612, 618
uint ip = (uint)ipa.Address;
#pragma warning restore 612, 618

But it would be better to use the non deprecated GetAddressBytes() Method:

using System.Net;

IPAddress ipa = IPAddress.Parse("");
uint ip = System.BitConverter.ToUInt32(ipa.GetAddressBytes(), 0);

Calling a function inside another assembly in .NET

Red Gate .NET ReflectorI wanted to call a hash function from a .net executable from my code. My first step was to inspect the executable with Reflector.

The Hash function was in a namespace called Core:

namespace TheExe.Core
    internal static class AssemblyInfo
    internal static class StringExtensionMethods

internal static class StringExtensionMethods
    // Methods
    public static string Hash(this string original, string password);
    // More methods...

Notice that the Core namespace is marked as internal so it was not meant to be callable outside of the executable. It’s still possible to call it using Reflection:

Read more

Could not load file or assembly 'System.Configuration'

Today I was asked to troubleshoot an executable that didn’t work correctly on Windows XP Embedded.

On startup it displayed the following message:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or ass
embly 'System.Configuration, Version=, Culture=neutral, PublicKeyToken=b0
3f5f7f11d50a3a' or one of its dependencies. The system cannot find the path spec
File name: 'System.Configuration, Version=, Culture=neutral, PublicKeyTok
en=b03f5f7f11d50a3a' ---> System.IO.DirectoryNotFoundException: The system canno
t find the path specified. (Exception from HRESULT: 0x80070003)

I verified that System.Configuration.dll was present (in C:\Windows\Microsoft.NET\Framework\v2.0.50727).

Read more