Mono.Cecil does not set the HasFieldRVA field on a FieldDefinition when the InitialData property is set to non-null #728
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I'm trying to use the
FieldDefinition.InitialDataproperty to emit a static array into an image using the.datadeclaration feature in ECMA-335.However, it seems that any data assigned to this field is dropped and not emitted as a
.datadeclaration in the image.I know that Mono.Cecil supports round-tripping the
InitialDatafield from a loaded assembly back to disk if it hasn't been modified, but it seems that modifying it or assigning it on a new field is unsupported.Hi @jkoritzinsky,
Thank you for filing this. That definitely sounds like a bug, which might be annoying because from a quick look that should not happen:
https://github.com/jbevain/cecil/blob/master/Mono.Cecil/FieldDefinition.cs#L114
https://github.com/jbevain/cecil/blob/master/Mono.Cecil/AssemblyWriter.cs#L1595
Any chance you could start a PR with a failing test?
I'll work on putting together a failing unit test for this.
While putting together a unit test, I found the issue.
When a new field is created in Mono.Cecil and an array is assigned to the
InitialValuefield, Mono.Cecil correctly emits the value and will read it back in. However, Mono.Cecil does not set theHasFieldRVAflag, so other tools like ILDasm and ILSpy do not correctly recognize that an RVA has been assigned.When I manually set the
HasFieldRVAflag, the other tools recognize the RVA. So thankfully I have a workaround.It would be nice if the
FieldDefinitionclass would add that flag when theInitialDataproperty is set. I'll update the issue title.Hah! That makes sense. Yes we should do that, should be has simple as:
@jkoritzinsky want to send a PR with the test & the fix?
Yes, I'll send a PR with a targeted test and fix.