Field InitialValue sets only the 1st byte #877
Replies: 2 comments
-
You can't directly a byte[] with an initial value like this. The easiest way to understand is to look at what the compiler is generating in that scenario: class Foo
{
public int[] integers = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 };
} Look at the IL that is generated in either ildasm or ILSpy and replicate that :) |
Beta Was this translation helpful? Give feedback.
-
It creates a private class with a .field assembly static initonly, and a .data with the bytearray, and then in the construction of my class it uses ldtoken to copy data from one field to the other. I was able to replicate and work with it by generating IL directly, but I don't know how I would do it from Cecil, as I get the same issue in the .data field when defining the private class. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm trying to initialize a field with a byte array using InitialValue, but I'm getting a .data section with only the first byte
The code I'm using:
I've found this thread https://groups.google.com/g/mono-cecil/c/uhgICc7RGK0/m/GoYekx_T7lwJ, where KnightC got the same issue, but I don't understand how they've fixed it.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions