Questions tagged [reflection.emit]
The System.Reflection.Emit namespace contains classes that allow a compiler or tool to emit metadata and Microsoft intermediate language (MSIL) and optionally generate a PE file on disk.
reflection.emit
752
questions
0
votes
0
answers
32
views
Replacing a method call via reflection in C# does not work in a Unity environment
In Unity6 (6000.0.7f1), I've tried to redirect a method call to my own method using the MethodRedirect extension method from this GitHub repo.
From the Scenario1 example code in the GitHub repo, I ...
0
votes
0
answers
73
views
Trying to do struct delegate optimization with runtime generated struct C#
I do a lot of hashing in hot path; these hashing function looks something like this: f(input) mod size. I do not know size beforehand.
When tested, I got a significant speedup from compiler ...
0
votes
0
answers
43
views
using reflection to assign a dynamically created property
I am looking to assign a dynamically created property value but apparently I only get the value assigned to the backing field and not the actual property value when I call to propertyInfo.SetValue(...
2
votes
2
answers
56
views
Why is this Reflection.Emit code causing an AccessViolationException?
As a general rule, managed code is not supposed to be able to cause access violations. That happens in native code or in unsafe code. But somehow, with a bit of playing around with some Reflection....
1
vote
1
answer
60
views
How to use a generic type with a runtime-defined type parameter in Reflection.Emit
Running this under .NET 8.
IJoinable<T1, T2> already exists in the codebase as a generic interface. It declares one method, T2 Join(T1 value). The types being used for the type parameters (...
1
vote
2
answers
104
views
Use c# reflection to inline method calls "manually"
I'm running math heavy code on GPU with ILGPU, I organized it in modular classes segregated by interfaces to implement different algorithms that are modular.
Now ILGPU allows only to run static ...
0
votes
1
answer
35
views
C# Reflection emit invalid program when calling emited method from generic type that implements interface
I am generating a proxy dynamically in C# to wrap over a derived type from an interface, intercepting the methods from the interface and calling another method with the intercepted parameters.
My ...
0
votes
0
answers
32
views
C# Reflection Emit Invalid program exception when implementing generic interface
I am implementing a dynamic proxy class that implements an interface and exposes the methods inside that interface giving the user the option to call the method on the original object.
The proxy class ...
1
vote
1
answer
42
views
What is wrong with this Reflection.Emit for value conversion delegates?
Sorry for this long question but I feel I have to provide a bit more background as my issue is very specific.
Bigger picture
I am developing on a Unity tool to be used specifically for Embedded Linux ...
0
votes
1
answer
89
views
.NET reflection emit - what am I doing wrong in writing this method in MSIL?
I am trying to dynamically create a delegate that returns a list of the values of all properties defined on an object, using reflection emit in C#.
I have started with the examples given here:
https://...
0
votes
0
answers
80
views
Generating Complex Objects with Dynamic Properties Using Reflection Emit at Runtime
So The concept in my head kind of straightforward I'm just unsure how to implement this correctly.
I've got a class called Banana and a class Called Dog for simplicity sake.
Banana has a Dictionary of ...
0
votes
1
answer
44
views
How to stop Reflection.Emit from creating a console window?
I am generating an executable with System.Reflection.Emit (in .NET Framework, so I can save it to disk) and I want the generated exectuable to not have a console window (it should just perform some ...
1
vote
1
answer
77
views
Undefined behavior when trying to Memory.Slice using il.Emit
I am trying to write a dynamic method that takes ReadOnlyMemory<byte> and processes it. But I have experienced very weird behavior when trying to slice the memory. It seems like the arguments to ...
0
votes
0
answers
21
views
How to embed .manifest file using Reflection.Emit?
I want to embed a .manifest file inside my generated assembly (I am using .NET Framework 4.8.1).
There is a method called DefineManifestResource on ModuleBuilder, but I'm not sure if it is the right ...
2
votes
1
answer
52
views
Emitted properties do not appear in the debugger
I use System.Reflection.Emit to create classes at runtime that implement various interfaces which contain methods and properties.
When generating a class, I generate one concrete method for each ...