question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.InvalidCastException in Mono.Cecil.MetadataBuilder.GetConstantSignature

See original GitHub issue
System.InvalidCastException: Unable to cast object of type 'System.Byte' to type 'System.String'.

   at Mono.Cecil.MetadataBuilder.GetConstantSignature(ElementType type, Object value)
   at Mono.Cecil.MetadataBuilder.AddConstant(IConstantProvider owner, TypeReference type)
   at Mono.Cecil.MetadataBuilder.AddField(FieldDefinition field)
   at Mono.Cecil.MetadataBuilder.AddFields(TypeDefinition type)
   at Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type)
   at Mono.Cecil.MetadataBuilder.AddTypeDefs()
   at Mono.Cecil.MetadataBuilder.BuildTypes()
   at Mono.Cecil.MetadataBuilder.BuildModule()
   at Mono.Cecil.ModuleWriter.<BuildMetadata>b__0(MetadataBuilder builder, MetadataReader _)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
   at Mono.Cecil.ModuleWriter.BuildMetadata(ModuleDefinition module, MetadataBuilder metadata)
   at Mono.Cecil.ModuleWriter.WriteModuleTo(ModuleDefinition module, Stream stream, WriterParameters parameters)
   at Mono.Cecil.ModuleDefinition.Write(Stream stream, WriterParameters parameters)
   at Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters)
   at Mono.Cecil.AssemblyDefinition.Write(String fileName)

  --- removed ---

Built with the latest commit.

I believe the offending line is https://github.com/jbevain/cecil/blob/master/Mono.Cecil/AssemblyWriter.cs#L1915 (AssemblyWriter.cs:1915), however I have no clue about the codebase so I don’t really know what this line is supposed to do or how to debug it. Unfortunately I cannot share the assembly, but please tell me if I can do something to assist.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ruhanijebcommented, Jul 10, 2019

Here is my visual studio details: Microsoft Visual Studio Professional 2019 Version 16.1.5 VisualStudio.16.Release/16.1.5+29025.244 Microsoft .NET Framework Version 4.7.03062

Installed Version: Professional

VisualStudio.Mac 1.0 Mac Extension for Visual Studio

Xamarin 16.1.0.545 (d16-1@db7c858e8) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 16.1.0.418 (remotes/origin/d16-1@5b958bb10) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 16.2.112 (4db4af4) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 9.3.0.23 (HEAD/d0b48056f) Xamarin.Android Reference Assemblies and MSBuild support. Mono: mono/mono/2018-08@3a07bd426d3 Java.Interop: xamarin/java.interop/d16-1@5ddc3e3 LibZipSharp: grendello/LibZipSharp/d16-1@44de300 LibZip: nih-at/libzip/rel-1-5-1@b95cf3f ProGuard: xamarin/proguard/master@905836d SQLite: xamarin/sqlite/3.27.1@8212a2d Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-1@acabd26

Xamarin.iOS and Xamarin.Mac SDK 12.10.0.157 (6bd9475) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Attaching my detailed log: detailedlog.txt

0reactions
PeterPolacekcommented, Feb 1, 2023

I found the problematic code for Mono.Cecil.dll, so i edited because of this error. So you can try it … Mono.Cecil.zip

Read more comments on GitHub >

github_iconTop Results From Across the Web

PowerPoint Interop ConvertToAfterEffect Won't Compile in ...
InvalidCastException : Specified cast is not valid. at Mono. ... at Mono.Cecil.MetadataBuilder.GetConstantSignature(ElementType type, Object value) at Mono.
Read more >
Mono.Cecil type cast error on build server
[Full Path To My obj\Test dll].dll(-1,-1): OpenAccess Enhancer error 0: System.InvalidCastException: Unable to cast object of type 'Mono.
Read more >
Mono.Cecil producing "Invalid CIL"
I am using Mono.Cecil to perform the patch; however, something about the way it's recompiled is causing ANY modified method to throw an ......
Read more >
Viewing online file analysis results for '0Harmony.dll'
Guest System: Windows 7 32 bit, Professional, 6.1 (build 7601), ... Description: PE32 executable (DLL) (console) Intel 80386 Mono/.
Read more >
InvalidCastException Class (System)
An InvalidCastException exception is thrown when the conversion of an instance of one type to another type is not supported. For example, attempting...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found