Home » C# » Unit testing System.UnauthorizedAccessException: [InvalidCrossThreadAccess]

Unit testing System.UnauthorizedAccessException: [InvalidCrossThreadAccess]

When unit testing you can get this kind of error if you try to use a class that use different thread of the main one.

At first, I haven’t realized that I were using another thread because I was testing my Shape class. After some minutes, I realized that I were using the System.Windows.Shape and not mine… once the reference set correctly I were able to remove this error and have my test working.

Test method UT.ShapeTest.CreateNewShape threw exception: System.UnauthorizedAccessException: [InvalidCrossThreadAccess]
Arguments: …

If you like my article, think to buy my annual book, professionally edited by a proofreader. directly from me or on Amazon. I also wrote a TypeScript book called Holistic TypeScript

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.