Intercepting DLL Methods, is it possible? #76468
-
I am working on a .NET 9 Console Application with a NuGet package. As far as I know, NuGet packages are essentially DLL files that are cached on my PC and added to my project as a reference. The package includes a specific method that creates an HttpClient and provides it to other parts of the library. I want to set the While this solution works, I'm looking for a way to accomplish this using the unmodified package from NuGet. This way, I could benefit from future updates without having to manually fetch the repository each time. I am aware of the preview interceptors feature introduced in C# 12, but I understand that it requires the code's specific line and column, in order to intercept that call. How can this work with a compiled DLL file? Thank you for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
It cannot. This is not possible with Roslyn. |
Beta Was this translation helpful? Give feedback.
-
Interceptors apply to source code before they are emitted into assemblies. To modify the compilation results, IL post-processing approaches like Fody are required. |
Beta Was this translation helpful? Give feedback.
Interceptors apply to source code before they are emitted into assemblies. To modify the compilation results, IL post-processing approaches like Fody are required.