Skip to content

[Bug]: Failure to load assembly: Constant type i4 is not compatible with field type GenericInst #84

@jakobhellermann

Description

@jakobhellermann

Bug Description

I'm trying to load a .dll containing CIL, and I'm getting this error:

❌ Failed to load assembly: Malformed - src/metadata/tables/constant/owned.rs:116: Constant type I4 is not compatible with field type: GenericInst(ValueType(Token(0x02001b4f, table: 0x02, row: 6991)), [GenericParamType(0)]) (token: 184552971)

The type def referenced by the token 6991 is the Transformations enum here:

public abstract class TransformVector<T> : FsmStateAction where T : NamedVariable
{
  public enum Transformations
  {
  	TransformPoint,
  	TransformDirection,
  	TransformVector,
  	InverseTransformPoint,
  	InverseTransformDirection,
  	InverseTransformVector
  }
  
  ...
}

By just allowing

            // For complex types (Class, ValueType, etc.), we can't easily validate without
            // full type resolution, so we allow them (conservative approach)
            // Note: This also covers Null and Class constants to complex types
            | (_, TypeSignature::Class(_) | TypeSignature::ValueType(_)) => true,

             // new
            | (_, TypeSignature::GenericInst(_, _)) => true,

in TypeSignature::accepts_constant, I seem to get past this (althrough loading still fails with another error).

Steps to Reproduce

cargo run --example basic path/to/lib.dll

Expected Behavior

I expect the assembly to load

Actual Behavior

it didn't

❌ Failed to load assembly: Malformed - src/metadata/tables/constant/owned.rs:116: Constant type I4 is not compatible with field type: GenericInst(ValueType(Token(0x02001b4f, table: 0x02, row: 6991)), [GenericParamType(0)]) (token: 184552971)

The type def referenced by the token 6991 is the Transformations enum here:

public abstract class TransformVector<T> : FsmStateAction where T : NamedVariable
{
  public enum Transformations
  {
  	TransformPoint,
  	TransformDirection,
  	TransformVector,
  	InverseTransformPoint,
  	InverseTransformDirection,
  	InverseTransformVector
  }
  
  ...
}

Sample File

The assembly is from a game on steam, I don't really wanna upload it here. If you're interested in helping debug this I could it to you privately.

Code Sample

basic example

Error Output

dotscope Version

0.4.0

Rust Version

1.92.0-nightly

Operating System

Windows

OS Version

Linux

Architecture

x86_64

Additional Context

By just allowing

            // For complex types (Class, ValueType, etc.), we can't easily validate without
            // full type resolution, so we allow them (conservative approach)
            // Note: This also covers Null and Class constants to complex types
            | (_, TypeSignature::Class(_) | TypeSignature::ValueType(_)) => true,

             // new
            | (_, TypeSignature::GenericInst(_, _)) => true,

in `TypeSignature::accepts_constant`, I seem to get past this (althrough loading still fails with another error).

Checklist

  • I have searched existing issues to make sure this is not a duplicate
  • I have provided a minimal code sample that reproduces the issue
  • I am using the latest version of dotscope

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions