Previous | Index | Next 

[PRB] Most VB.NET methods don’t work well with strings that contain ASCII 0 characters

Most methods in the VB6 runtime – for example, GetAttr and SetAttr - automatically truncate a string to the first ASCII 0 char; this behavior is very convenient when working with strings returned from Windows API calls, for example. Unfortunately, the corresponding VB.NET methods don’t truncate the string and therefore throw the following exception

        Illegal characters in path

VB Migration Partner’s support library comes with a set of replacement file-related methods that fix this behavior and automatically truncate their string arguments at the first ASCII 0 char. The provided methods are: ChDir6, ChDrive6, FileCopy6, FileLen6, MkDir6, RmDir6, GetAttr6, SetAttr6, Kill6.

However, please notice that VB Migration Partner doesn’t automatically map the native VB.NET methods to the replacement methods listed above, because relatively few programs may suffer from this minor behavior difference. If you want to enforce the string truncation you should manually change the VB.NET method into the VB Migration Partner’s method.

Such change can be performed easily and automatically by means of the following pragma:

 '## PostProcess "\b(?<fn>ChDir|ChDrive|FileCopy|FileLen|MkDir|RmDir|GetAttr|SetAttr|Kill)(?=\()", 
         "${fn}6"

As with all PostProcess pragmas, you can change its scope so that it works for the entire project or for a single file. Additionally, you can change the regular expression in its first argument to limit its effect to a subset of all file-related methods.

 

Previous | Index | Next