autofac/Autofac

Support Delegate Factories when compiled in AOT mode

Aperta

#1449 aperta il 26 mar 2025

 (2 commenti) (0 reazioni) (0 assegnatari)C# (827 fork)batch import
enhancementhelp wanted

Metriche repository

Star
 (4327 stelle)
Metriche merge PR
 (Merge medio 3h 24m) (10 PR mergiate in 30 g)

Descrizione

Problem Statement

Using delegate factories in Autofac when AOT mode is on causes exceptions because it emits JIT compiled methods. I was not sure whether to open this as a bug or not as I didn't know if it is a supported use case. At the very least, this documentation page https://autofac.readthedocs.io/en/latest/advanced/delegate-factories.html could be updated to state that AOT is not supported.

Desired Solution

Frankly, I'm not sure if its possible to easily support this use case, but perhaps it can be done by generated source code. The desired solution is that delegate factories would work in AOT mode.

Alternatives You've Considered

We could refactor our code base to manually resolve these dependencies but we loose a lot of flexibility.

Additional Context

This problem was discovered when deploying a iOS app in release mode

Guida contributor