An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
@Domgrar, Welcome to Microsoft Q&A, based on my test, I almost reproduced your problem. And according to my research, there is no related doc to explain it. However, I find another way to use the code without any problems.
Please remove the reference Interop.UIAutomationClient.dll in your project and install the nuget-package Interop.UIAutomationClient.
After testing, I find the code will not generate that error(Tested in .NET Framework 4.8 console app):
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.