How can I work around this exception? - C#