756 questions
2
votes
1
answer
146
views
How do I use .NET reflection to emit generic interfaces and a class which implements them
I am trying to use .NET reflection to emit a class and some interfaces which the class implements. However, I cannot seem to correctly implement the interfaces that are generic, as that results in ...
1
vote
1
answer
53
views
How to Deserialize json document using reflection.emit.modulebuilder in system.text.json [closed]
We have a local Web API used for internal clients to retrieve data. We use application/json to transport the data across the Web API.
The retrieved JSON data has a simple structured class 'Response'. ...
0
votes
0
answers
24
views
Recreate/Replace Type generated vis Reflection.Emit [duplicate]
I've created a dynamic Type similarly to how it is done in this answer. I'd like to be able to recreate/replace this type at runtime, but the only way I found to do so would be via unloading the whole ...
0
votes
0
answers
78
views
Is it possible to execute IL instructions one by one using System.Reflection.Emit?
In the preceding C# code, I'm creating a dynamic method and adding a few IL instructions to it, and then invoking the dynamic method:
var assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new(&...
0
votes
0
answers
85
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 ...
2
votes
2
answers
85
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
2
answers
157
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 ...
1
vote
1
answer
58
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
53
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 ...
2
votes
1
answer
80
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 ...
1
vote
0
answers
257
views
How to call .NET Framework methods in their own process from .NET 7?
I'm working on a .NET 7 WPF application that relies on a .NET Framework (4.8.1) library that uses Reflection.Emit (with AssemblyBuilder.Save). When I call methods from that library from my application,...
-2
votes
1
answer
98
views
Is it possible to have implicit conversion operators being called during casts made by a method generated dynamically ? (eg: IL emit)
I have have the following classes A and B:
public class A
{
}
public class B
{
public static implicit operator A(B value)
{
return new A();
}
}
As expected, the following ...
0
votes
0
answers
234
views
How to set default property value of class type in C# System.Reflection.Emit
I am using System.Reflection in C# to create a dynamic object class at runtime.
This is the example object class that I want to create at runtime.
public class RequestForTest
{
public string ...
0
votes
0
answers
89
views
Emit local variable which is not a standard type and assign a value to it
We can assign a variable using EMIT which has a standard type such as string, etc.
But how can I assign a non-standard type such as Type?
DynamicMethod dynamicMethod
= new ...
1
vote
1
answer
70
views
Method overload emitted via dynamic IL is not being called
So I am attempting to create a class that will wrap up all the bits necessary to implement a single-instance application (SIA). It should be a drop-in replacement for Application.Run<T>().
...
1
vote
2
answers
91
views
How to change the .maxstack size of constructor and methods in dynamic assembly
I want to dynamically create an assembly using the functionality provided System.Reflection.Emit. The assembly should be identical to the assembly that results from compiling the following C# code:
...
0
votes
1
answer
69
views
How to do a circular dependency with System.Reflection.Emit
I have a generation framework that can generate dll using system.reflection.emit but have a case that i dont think can be solved with Emit, or atleast i have not figured out to do a minimal repro that ...
0
votes
1
answer
274
views
C# Getting a previously defined method builder from the type builder
Consider the following C# code:
var methodBuilder1 = typeBuilder.DefineMethod("GetMedalIds", MethodAttributes.Public | MethodAttributes.HideBySig, CallingConventions.HasThis, typeof(int[]), ...
2
votes
1
answer
213
views
Creating MetadataReference from in-memory assembly created with Reflection.Emit
I have created an assembly, module and classes in a dynamic assembly using Reflection.Emit in .NET6. I unable to reference that assembly in my CSharpCompilation; I can't use MetadataReference....
1
vote
0
answers
403
views
How to dynamically add an instance method to type from loaded assembly in runtime?
I have .NET 6.0 app which dynamically loads .NET Framework 4.8 assembly. Calling method from this assembly with reflection throws this exception:
System.MissingMethodException: Method not found:
'...
0
votes
1
answer
191
views
How to create dynamic function with unsure parameters in C# Emit
I want to create dynamic function in my project, but the number of function parameters is not sure,maybe two,maybe three or more,and then i want to run a static function already in the project,the ...
0
votes
0
answers
477
views
How to create a dynamic method in C# which uses an "in" parameter?
I try to create a dynamic method in .NET which has an "in" parameter, but it throws an exception in the EmitCall line:
public struct Context
{
public string MyString { get; set; }
}
...
0
votes
0
answers
49
views
Creating Dymamic Method throws en exception
I want to create some dynamic method whcih has 2 cycles: in first some N values are pushed onto evaluation stack, in second - these N values are popped from stack. But CreateMethod throws ...
2
votes
1
answer
301
views
How do I use TypeBuilder to create derived type with static field of base type?
I am having an issue using TypeBuilder to dynamically create a derived type that has a static field of the base type, that is initialized to a new instance of the created type.
Essentially, I want to ...
0
votes
1
answer
1k
views
System.MissingMethodException: Method not found: '?' when trying to build a custom dynamic type with a delegate method
I am trying to dynamically build a type with a method that calls into an external delegate by using System.Reflection.Emit. However when I try to call this method, my program crashes with the ...