Image file cannot be deleted in vb.NET

I have a program that displays an image from an image file – in this case a bitmap file – using Image.FromFile(Filename). I  want to delete the file before closing the program. But it was failing when it tried to use My.Computer.FileSystem.DeleteFile(FullName) with the error “The process cannot access the file ‘<filename>’ because it is being used by another process.”

The solution is to dispose of the image.

The reason is that Image.FromFile places a lock on the file and holds it open. Disposing of the image releases the lock and closes the file.

 

 

Crystal Reports “Invalid Keycode” in Visual Studio 2015

Problem:

I developed an application in Visual Studio 2015 which uses Crystal Reports to produce reports. The report designer was working fine until I installed the application on my machine using an InstallShield LE installation project. After that, when I opened a report file in Visual Studio, I got an “Invalid Keycode” message and the report designer was blank. If I re-installed Crystal Reports For Visual Studio again the error went away and everything was back to normal.

Cause:

When  Crystal Reports For Visual Studio is installed it adds a keycode to the registry.

On my machine, the key name is

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Crystal Reports\Keycodes\CRNET

When InstallShield LE installs the Crystal Reports runtime engine merge module, by default it removes the keycode.

Solution:

Find the keycode in the registry (I used regedit).regedit

In Visual Studio, open the installation project; look under section 2 for the Redistributables; find and highlight the Crystal Reports runtime engine merge module redistributable.

redistibutables

Right click on this item and select Properties from the popup menu.

Select the Configurable values tab and look for the Keycode value in the list.

mergemoduleprops

Add the Keycode value (from the registry).

Save and build the installation project.

Now, when the Crystal Reports runtime engine merge module is installed, the keycode will not be lost.