GenericParameterComparer throws exception #118

Closed
opened 2013-01-18 10:22:49 -06:00 by jlamfers · 4 comments
jlamfers commented 2013-01-18 10:22:49 -06:00 (Migrated from github.com)

GenericParameterComparer throws exception if genericParameter.Owner.MetadatToken.TokenType == TokenType.MemberRef
and index == CodedIndex.TypeOrMethodDef

this happened as I implemented a generic method (with generic parameters of its own) that belongs to a generic interface, after I made that method's declaring type generic.
It all worked after I added a line at Utilities.cs as follows:

case CodedIndex.TypeOrMethodDef:
    ret = token.RID << 1;
    switch (token.TokenType) {
    case TokenType.TypeDef:
        return ret | 0;
    case TokenType.Method:
    case TokenType.MemberRef: //added line
        return ret | 1;
    default:
        goto exit;
    }
GenericParameterComparer throws exception if genericParameter.Owner.MetadatToken.TokenType == TokenType.MemberRef and index == CodedIndex.TypeOrMethodDef this happened as I implemented a generic method (with generic parameters of its own) that belongs to a generic interface, after I made that method's declaring type generic. It all worked after I added a line at Utilities.cs as follows: ``` case CodedIndex.TypeOrMethodDef: ret = token.RID << 1; switch (token.TokenType) { case TokenType.TypeDef: return ret | 0; case TokenType.Method: case TokenType.MemberRef: //added line return ret | 1; default: goto exit; } ```
jbevain commented 2013-01-21 14:05:23 -06:00 (Migrated from github.com)

Hey,

It doesn't look like quite correct, from a metadata point of view. In the assembly, the owner of an actual GenericParameter in the GenericParam can not be a MemberRef.

You're probably doing something that generates a wrong object model for Cecil.

Sadly Cecil doesn't verify much. If you can past some code, I can probably tell what's wrong.

Hey, It doesn't look like quite correct, from a metadata point of view. In the assembly, the owner of an actual GenericParameter in the GenericParam can not be a MemberRef. You're probably doing something that generates a wrong object model for Cecil. Sadly Cecil doesn't verify much. If you can past some code, I can probably tell what's wrong.
awyl commented 2013-09-09 12:47:23 -05:00 (Migrated from github.com)

Sorry to revive this old issue.

I have a similar problem with the master branch. There is no issue if I use tag 0.9.5. Somehow it is the newest nuget/master branch.

I am not sure how it happens as I am not the one who wrote the code utilizing cecil. But after a long debugging session I came down to the same conclusion as @jlamfers. All the code did was to copy a generic method and inject back into the same class under a different name. Somehow the token of this copied method became MemberRef when trying to output the changed assembly.

0.9.5.0 works, 0.9.5.4 doesn't.

Sorry to revive this old issue. I have a similar problem with the master branch. There is no issue if I use tag 0.9.5. Somehow it is the newest nuget/master branch. I am not sure how it happens as I am not the one who wrote the code utilizing cecil. But after a long debugging session I came down to the same conclusion as @jlamfers. All the code did was to copy a generic method and inject back into the same class under a different name. Somehow the token of this copied method became MemberRef when trying to output the changed assembly. 0.9.5.0 works, 0.9.5.4 doesn't.
jbevain commented 2013-09-11 11:12:52 -05:00 (Migrated from github.com)

Hey @awyl

Do you think you could cook-up a simple repro? That would sure help me investigate the issue.

We did change some importing stuff for generics in .4, so it's probably related. But I'd love to have a simple piece of code I could run against both versions.

Hey @awyl Do you think you could cook-up a simple repro? That would sure help me investigate the issue. We did change some importing stuff for generics in .4, so it's probably related. But I'd love to have a simple piece of code I could run against both versions.
awyl commented 2013-09-12 15:45:54 -05:00 (Migrated from github.com)

I extracted the portion of from the library and put it into a separate project.

https://dl.dropboxusercontent.com/u/108285103/CecilTest.zip

I am very new to this IL stuff, and I am not sure whether it is this library or Cecil. Hope this helps.

I extracted the portion of from the library and put it into a separate project. https://dl.dropboxusercontent.com/u/108285103/CecilTest.zip I am very new to this IL stuff, and I am not sure whether it is this library or Cecil. Hope this helps.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-jbevain/cecil#118
No description provided.