Fix possible dereference of NULL pointer

Use g_set_error() instead of doing it manually and forgetting to check
whether the pointer is NULL or not before dereferencing it.

Spotted by clang --analyze.
Remove a few dead assignments

Spotted by clang --analyze.
C#: Correctly parse enums with a base type specifier

See CSharp Language Specification 14.1.