I have a method which generates a DynamicMethod using ILEmit, and I want to inline its contents inside an expression tree. I need to do this in order to write the expression tree to an assembly.
I can compile the DynamicMethod and include that into the tree, but this prevents me from writing the expression tree to an assembly with the following error:
CompileToMethod cannot compile constant 'BulkUtil+BlitMethod[Byte]' because it is a non-trivial value, such as a live object. Instead, create an expression tree that can construct this value.
Since I'm generating the body of the method anyways, I figured I'd just inline it into the tree so that it could be output. However, because the method generates unsafe code I don't know how to translate it directly.
Is there a way to directly add IL to an expression tree?