Fix error handling in .NET client
- #2684