C# saving a bitmap results in generic GDI+ error

If you save a bitmap the following exception can pop up:

Possible causes:

  • You tried to save the file with an invalid filename or in a directory that doesn’t exist
  • You constructed a bitmap from a memorystream that has been closed (the bitmap takes ownership of the MemoryStream and you are not allowed to close it yourself!)
  • You opened a bitmap from a file (-> which created a filestream) and you try to save another bitmap to the same file (-> doesn’t work because the file is blocked)

C# Scale bitmap

The following code scales a bitmap from the filesystem to a defined width:

C# Multithreading

Execute code in the UI Thread

Oracle SQL-Script output

First you need to activate it and call the script:

In the script you can output something with that line:

After the script has been executed you can see the output for example in the Script Output tab of SQLDeveloper.

PInvokeStackImbalance Excpetion

If you get a PInvokeStackImbalance exception it could be:

  • One parameter has a wrong type (p. x. int changed to long)
  • The CallingConvention of the DllImport. Change it in the declaration:

    for example to

C# Show Console in WPF App

Use the following snippet to declare the Win32 function

and this one to show the console