il

How does protobuf-net handle readonly fields?

情到浓时终转凉″ 提交于 2019-11-30 20:06:47
I use protobuf-net to serialize/deserialize my data. I have some rather simple classes, so that's no real problem. As far as I know, protobuf-net uses IL generation to create serialization/deserialization code. While I have readonly fields in my model, I wonder how is it possible to write to such a field with IL? I can plainly see it works well, but I don't know why... I've tried to spy it in the code, but it's a bit too complicated. My attempts to generate such code myself always result in IL validator errors. Actually, I can't get it to fail - at least, when generating in memory. Let's start

Why is the .ctor() created when I compile C# code into IL?

你说的曾经没有我的故事 提交于 2019-11-30 17:35:54
With this simple C# code, I run csc hello.cs; ildasm /out=hello.txt hello.exe . class Hello { public static void Main() { System.Console.WriteLine("hi"); } } This is the IL code from ildasm. .class private auto ansi beforefieldinit Hello extends [mscorlib]System.Object { .method public hidebysig static void Main() cil managed { .entrypoint // Code size 13 (0xd) .maxstack 8 IL_0000: nop IL_0001: ldstr "hi" IL_0006: call void [mscorlib]System.Console::WriteLine(string) IL_000b: nop IL_000c: ret } // end of method Hello::Main .method public hidebysig specialname rtspecialname instance void .ctor(

Why is the .ctor() created when I compile C# code into IL?

孤街浪徒 提交于 2019-11-30 16:37:42
问题 With this simple C# code, I run csc hello.cs; ildasm /out=hello.txt hello.exe . class Hello { public static void Main() { System.Console.WriteLine("hi"); } } This is the IL code from ildasm. .class private auto ansi beforefieldinit Hello extends [mscorlib]System.Object { .method public hidebysig static void Main() cil managed { .entrypoint // Code size 13 (0xd) .maxstack 8 IL_0000: nop IL_0001: ldstr "hi" IL_0006: call void [mscorlib]System.Console::WriteLine(string) IL_000b: nop IL_000c: ret

Create DynamicMethod to assign value to a property?

巧了我就是萌 提交于 2019-11-30 15:37:22
问题 This is a learning exercise. I created a method that takes a Foo and a string and sets the A property. I used the Reflector disassembly to make the following emit code. The disassembly looks like this: .method private hidebysig static void Spork(class ConsoleTesting.Foo f, string 'value') cil managed { .maxstack 8 L_0000: ldarg.0 L_0001: ldarg.1 L_0002: callvirt instance void ConsoleTesting.Foo::set_A(string) L_0007: ret } Ok, so I modeled my emit code after that: using System; using System

What CLR/.NET bytecode tools exist? [closed]

余生颓废 提交于 2019-11-30 15:12:30
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I'm well aware of Java tools for manipulating, generating, decompiling JVM bytecode (ASM, cglib, jad, etc). What similar tools exist for the CLR bytecode? Do people do bytecode manipulation for the CLR? 回答1: Bytecode is a binary format. .NET assemblies work pretty different in terms of how they store the

What is your recommendation for a good book on the .NET CLR and CIL? [closed]

北城以北 提交于 2019-11-30 14:27:50
Do you know any good book about the workings of the CLR, the .NET Framework and CIL as opposed to any specific .NET language? Regardless of any other books, you will definitely need ECMA-335 standard for a detailed specification of CLR and CIL. With sufficient experience, it may actually be sufficient on its own. Also, "Expert .NET 2.0 IL Assembler" looks like it matches your requirements, though I haven't read it and can't comment on its quality. Amazon description looks promising, though: Topics include managed executable file structure, metadata table structure, Microsoft IL instructions,

Interlocked.CompareExchange<Int> using GreaterThan or LessThan instead of equality

允我心安 提交于 2019-11-30 11:26:55
问题 The System.Threading.Interlocked object allows for Addition (subtraction) and comparison as an atomic operation. It seems that a CompareExchange that just doesn't do equality but also GreaterThan/LessThan as an atomic comparison would be quite valuable. Would a hypothetical Interlocked.GreaterThan a feature of the IL or is it a CPU-level feature? Both? Lacking any other option, is it possible to create such a feature in C++ or direct IL code and expose that functionality to C#? 回答1: Update to

DynamicMethod is much slower than compiled IL function

流过昼夜 提交于 2019-11-30 10:52:15
问题 I wrote a simple object copier that copies public properties. I can't figure out why the Dynamic method is a lot slower than the c# version. Durations C# method : 4,963 ms Dynamic method : 19,924 ms Note that - as I run the dynamic method before starting the stopwatch - the duration do not include the compilation phase. I run that in Debug and Release mode, in x86 and x64 mode, and from VS and from the command line with roughly the same result (dynamic method is 400% slower). const int

Creating method dynamically, and executing it

北城余情 提交于 2019-11-30 10:41:19
问题 Background: I want to define few static methods in C# , and generate IL code as byte array, from one of these methods, selected at runtime (on client), and send the byte array over network to another machine (server) where it should be executed after re-generating the IL code from the byte array. My Attempt: (POC) public static class Experiment { public static int Multiply(int a, int b) { Console.WriteLine("Arguments ({0}, {1})", a, b); return a * b; } } And then I get the IL code of the

IL offsets missing when silverlight assembly is compiled in release mode

霸气de小男生 提交于 2019-11-30 09:15:18
I followed these instructions to add IL offsets to Silverlight stack traces . This works great when building in DEBUG mode however our production/qa build process compiles everything using RELEASE mode which seems to loose the IL offset information. In release mode all the IL offsets end up being "0xffffffff". Using reflector to compare the debug/release assemblies I noticed the DebuggableAttribute was used differently. DEBUG build: [assembly: AssemblyVersion("1.0.0.0")] [assembly: ComVisible(false)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations |