May 30

Redirect Registry by Modifying .NET Executable

Remko WeijnenComments Off on 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

Continue reading »

Mar 13

Returning a string from unmanaged dll to .net

Remko WeijnenComments Off on 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?

Continue reading »

Oct 12

warning CS0618: ‘System.Net.IPAddress.Address’ is obsolete

Remko WeijnenComments Off on 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("10.4.2.91");

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. http://go.microsoft.com/fwlink/?linkid=14202′

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("10.4.2.91");

#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("10.4.2.91");
uint ip = System.BitConverter.ToUInt32(ipa.GetAddressBytes(), 0);
Oct 02

DevExpress TileItems: Drag and Drop and Click

Marco HokkeComments Off on DevExpress TileItems: Drag and Drop and Click

Author: Marco Hokke


DevExpress
offers a nifty little control in its collection of editors: the TileControl It’s a control that offers a Metro-style interface using tiles, grouped together, and with a scrolling-mechanism that mimics the Metro interface.

In a normal desktop environment, however, this interface lacks a standard way of dragging and dropping individual tiles onto a different control. For example, for one of our products we want the user to be able to drag a tile onto a DevExpress ChartControl, and configure what data is shown on the axes of the ChartControl.

In standard .Net controls the drag and drop behavior is implemented in the MouseDown event using .Net’s DoDragDrop method. But TileItems lack this event; all you have to work with are the ItemPress and ItemClick events. This post will show you how to use these two events to implement both drag and drop functionality and keep the standard click function of the TileControl. Note that in order to do this, we must disable the TileControl’s ability to rearrange its tiles.

Continue reading »

Aug 22

Calling a function inside another assembly in .NET

Remko WeijnenComments Off on 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:

Continue reading »

Jul 18

Could not load file or assembly ‘System.Configuration’

Remko WeijnenComments Off on 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=2.0.0.0, Culture=neutral, PublicKeyToken=b0
3f5f7f11d50a3a' or one of its dependencies. The system cannot find the path spec
ified.
File name: 'System.Configuration, Version=2.0.0.0, 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).

Continue reading »

May 30

.Net data-adapter’s DeleteCommand exception

Marco HokkeComments Off on .Net data-adapter’s DeleteCommand exception

I hit an exception when adding auto-generated commands from a CommandBuilder object to a DataAdapter object. Specifically, when assigning the return value of the CommandBuilder.GetDeleteCommand() method to the DeleteCommand property of the DataAdapter object. The exception message reads: “Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information.”. The exception may also be thrown when adding a command to the UpdateCommand property of a DataAdapter object.

The exception message is not very helpful in finding the problem and fixing it. After some research I found that the reason this exception is thrown is because both the DeleteCommand and the UpdateCommand require a primary key in the table they are meant to modify. When the table does not have one, the DeleteCommand and UpdateCommand cannot accurately identify which row to delete or update, and they will throw the exception mentioned above.

The solution is simply to add a primary key to the table you want the DataAdapter object to connect to.

Apr 27

Tabstops in a .Net CheckedListbox

Marco HokkeComments Off on Tabstops in a .Net CheckedListbox

imageFor one of my projects I needed to create a simple CheckedListbox containing various entries of a specific entity, of which the user may select one (and only one). I wanted the entries of this listbox to be more than just the instance name of an entity; they should also include a description and optionally other data depending on the type of entity. And I wanted these items to be lined up.

One way to do this is to use a gridview, but it was too much hassle and gridviews generally don’t look very good. Should you consider this choice: note that the checked listbox I use does not have columnheaders.

There is an out-of-the-box way to line up the various items in each line of the checked listbox. This post will tell you how to achieve this.

Continue reading »

Oct 21

True is not true (?)

Ingmar VerheijComments Off on True is not true (?)

The string 'True' is not a valid Boolean value.

This error is thrown when an XML file is read into a DataSet using “System.Boolean” as DataType.
Continue reading »