Skip to content

System.InvalidCastException: 'Unable to cast object of type 'System.Object[]' to type 'System.String'.' #724

Description

@klangille

Hi,

I'm in process of updated my project to version 8.14.0 and getting this exception:

System.InvalidCastException: 'Unable to cast object of type 'System.Object[]' to type 'System.String'.'
This exception was originally thrown at this call stack:
    IKVM.Runtime.StubGen.StubGenerator.EncodeElementValue.AnonymousMethod__3(IKVM.ByteCode.Encoding.ElementValuePairTableEncoder)
    IKVM.ByteCode.Encoding.AnnotationEncoder.Annotation(IKVM.ByteCode.Utf8ConstantHandle, System.Action<IKVM.ByteCode.Encoding.ElementValuePairTableEncoder>)
    IKVM.Runtime.StubGen.StubGenerator.EncodeElementValue.AnonymousMethod__1(IKVM.ByteCode.Encoding.AnnotationEncoder)
    IKVM.ByteCode.Encoding.ElementValueEncoder.Annotation(System.Action<IKVM.ByteCode.Encoding.AnnotationEncoder>)
    IKVM.Runtime.StubGen.StubGenerator.EncodeElementValue(IKVM.ByteCode.Encoding.ClassFileBuilder, ref IKVM.ByteCode.Encoding.ElementValueEncoder, object)
    IKVM.Runtime.StubGen.StubGenerator.EncodeElementValue.AnonymousMethod__2(IKVM.ByteCode.Encoding.ElementValueEncoder)
    IKVM.ByteCode.Encoding.ElementValueTableEncoder.ElementValue(System.Action<IKVM.ByteCode.Encoding.ElementValueEncoder>)
    IKVM.Runtime.StubGen.StubGenerator.EncodeElementValue.AnonymousMethod__0(IKVM.ByteCode.Encoding.ElementValueTableEncoder)
    IKVM.ByteCode.Encoding.ElementValueEncoder.Array(System.Action<IKVM.ByteCode.Encoding.ElementValueTableEncoder>)
    IKVM.Runtime.StubGen.StubGenerator.EncodeElementValue(IKVM.ByteCode.Encoding.ClassFileBuilder, ref IKVM.ByteCode.Encoding.ElementValueEncoder, object)
    ...
    [Call Stack Truncated]

I'm not super familiar with the IKVM source but ChatGPT assures me the fix is the have the line in StubGenerator.EncodeElementValue changed because the array is name value pairs and should be advancing by 2.

from: for (int i = 1; i < v.Length; i++)
to: for (int i = 2; i < v.Length; i += 2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions