5

My goal is to display information about the methods of some classes in an uploaded dll. Loading the assembly, finding the desired classes and their methods was already successfully done. Now I was trying to show whether a method is declared "async" or not.

I found a thread that tells me how to do it: How can I tell if a C# method is async/await via reflection?

Anyway, while testing, when I call this

(AsyncStateMachineAttribute)methodInfo.GetCustomAttribute(typeof(AsyncStateMachineAttribute))

I got a System.IO.FileNotFoundException - "Could not load file or assembly '{assembly identifier}' or one of its dependencies. The system cannot find the file specified.".

I found this exception in an unanswered thread, but it did not help me: How to prevent MemberInfo.IsDefined from throwing FileNotFoundException on irrelevant attributes?

I understand that the method I am looking at has an attribute that my code does not know. I do not want to load that reference because it is only a test case and many other different attributes can be found in the same situation.

So, I need an answer to one of two questions:

  1. Is there a way to get the attribute "AsyncStateMachineAttribute", if it exists, ignoring the errors on other attributes?

  2. Is there another way to check whether a method (from MethodInfo) is async?

Thanks in advance! :)

Community
  • 1
  • 1
JoaoRibeiro
  • 808
  • 7
  • 24

0 Answers0