I have a rather convoluted scenario where I want to create a DynamicMethod that's attached to a class in an in-memory AssemblyBuilder. The dynamic method calls a method "GetReplacement" in a (regular) assembly of mine.
This worked fine in .NET 2.0, but in .NET 4.0 I get an error:
MethodAccessException: Attempt by security transparent method 'DynamicClass.Max(Int32, Int32)'
to access security critical method 'xxx.GetReplacement()' failed.
From what I've read, my dynamic method (Max in the error above) is security-transparent because the assembly it's attached to (the AssemblyBuilder) is transparent. I'm guessing the AssemblyBuilder is transparent because it's a dynamic assembly.
How do I make my dynamic method critical or do whatever it takes to grant it permission to call GetReplacement? There are a couple of other methods I want to call in GetReplacement's assembly so fixing the dynamic method would be better than marking GetReplacement in some way.
I'm a bit lost and would love some help!