How can I emit a dynamic method returning a ref?
I'm navigating the ins and outs of ref returns, and am having trouble emitting a dynamic method which returns by ref. Handcrafted lambdas and existing methods work as expected: class Widget { public int Length; } delegate ref int WidgetMeasurer(Widget w); WidgetMeasurer GetMeasurerA() { return w => ref w.Length; } static ref int MeasureWidget(Widget w) => ref w.Length; WidgetMeasurer GetMeasurerB() { return MeasureWidget; } But emitting a dynamic method fails. Note : I'm using Sigil here. Apologies, I'm less familiar with System.Reflection.Emit . WidgetMeasurer GetMeasurerC() { FieldInfo