0

I have a C# roslyn code analyzer that needs to analyze the usage scenarios of generic method invocations of a given class. I am gathering all the references to the method, the generic type parameters and so forth and then want to invoke the methods (via reflection) to analyze the output to report potential diagnostics in the analyzer. Is there a way from a Roslyn-Compilation.Assembly to a System.Reflection.Assembly? If not, is there any other way?

The Analyzer project and the solution to be analyzed are under my control.

Thanks!

Eike S
  • 300
  • 1
  • 11
  • It's not clear what you mean by a way from one assembly to another. Please describe your problem with more details and add a code sample if it can be helpful. – AndrewSilver Aug 30 '21 at 17:05
  • 1
    Even if you could do this, you really shouldn't. For example, what if such a method contains `while (true) { }`. That could very well happen while a developer is typing the code, and an IDE such as Visual Studio might decide to run the analyzer at any point in time. Also, the code could crash in all sorts of bad ways, and bring down the compiler or your IDE. – Kris Vandermotten Aug 31 '21 at 12:44
  • @KrisVandermotten valid – Eike S Sep 01 '21 at 13:17

1 Answers1

1

You can't do this: when your analyzer is running we haven't actually built the assembly yet. Furthermore, there's no guarantee your built thing can actually run. If I'm using a Windows machine to say build a project that only runs on Linux...that won't work well.

Jason Malinowski
  • 18,148
  • 1
  • 38
  • 55