Fix type conversion bug. First preparations for Java -> C# replacement.