I believe this is a bug.

I have a method which is a property getter. The “IsGetter” property is
correct set to true when the assembly is first initialised. However,
it magically turns to false while the “SetMethod” for a different(!)
property in the same type is queried.

The query to SetMethod triggers InitializeMethods(), which causes
Cecil to try to re-read all the method semantics for all the methods
in this type. For the offending method, the following happens in
ReadMethodSemantics():

* It calls InitializeMethodSemantics(), which immediately returns
because metadata.Semantics != null.
* metadata.Semantics.TryGetValue(...) returns false
* Therefore, it returns MethodSemanticsAttributes.None.

I notice that at the end of ReadMethodSemantics(), there is a line
that says:

    metadata.Semantics.Remove (method.token.RID);

The first time the method semantics are read, they are retrieved
correctly but then removed from this dictionary. The next time the
method semantics are read, the dictionary is still non-null, but the
key is now missing. Therefore, the wrong value is returned.

I think either the key shouldn’t have been removed from the
dictionary, or ReadMethodSemantics() shouldn’t be called twice for the
same method. I don’t know which.

-- 
--
mono-cecil

Reply via email to