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.

Unable to round-trip with unresolved enum constants

See original GitHub issue

It looks like this was discussed in https://github.com/jbevain/cecil/issues/236, and implemented for attributes, but not fields or default parameters.

repro.tar.gz

    static void Method(MyEnum e = MyEnum.B)
    {
    }
var a = ModuleDefinition.ReadModule("./cecil_const/bin/Debug/netstandard2.0/cecil_const.dll");
a.Write("out.dll");
Unhandled exception. Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'const_ref, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
   at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
   at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name)
   at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
   at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
   at Mono.Cecil.ModuleDefinition.Resolve(TypeReference type)
   at Mono.Cecil.TypeReference.Resolve()
   at Mono.Cecil.Mixin.CheckedResolve(TypeReference self)
   at Mono.Cecil.MetadataBuilder.GetConstantType(TypeReference constant_type, Object constant)
   at Mono.Cecil.MetadataBuilder.AddConstant(IConstantProvider owner, TypeReference type)
   at Mono.Cecil.MetadataBuilder.AddParameter(UInt16 sequence, ParameterDefinition parameter, ParamTable table)
   at Mono.Cecil.MetadataBuilder.AddParameters(MethodDefinition method)
   at Mono.Cecil.MetadataBuilder.AddMethod(MethodDefinition method)
   at Mono.Cecil.MetadataBuilder.AddMethods(TypeDefinition type)
   at Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type)
   at Mono.Cecil.MetadataBuilder.AddTypes()
   at Mono.Cecil.MetadataBuilder.BuildTypes()
   at Mono.Cecil.MetadataBuilder.BuildModule()
   at Mono.Cecil.MetadataBuilder.BuildMetadata()
   at Mono.Cecil.ModuleWriter.<>c.<BuildMetadata>b__2_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.Write(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
   at Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
   at Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters)
   at Mono.Cecil.ModuleDefinition.Write(String fileName)

We are seeing what looks like the same issue in https://github.com/dotnet/sdk/issues/3668#issuecomment-642836981.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jbevaincommented, Jun 11, 2020

Hey @sbomer, I’m happy to look at what it would take to bring the same optimization as custom attributes (copying the blob instead of deconstructing the constant value), but in the context of the linker the reference should be resolvable for everything to work.

0reactions
Pcookiecommented, Jul 21, 2023

Some more context: The unresolved reference in the case we hit looks like it was part of a code path that only lights up when an optional package is added and used in the app. Without that package, the dangling reference doesn’t cause any problems at runtime, but it still prevents the linker from writing this assembly (when trying to keep everything in it). We do have a workaround, but it would be great if round-tripping worked for scenarios like this.

I encountered this problem. What should I do to resolve it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

c++ - Forcing improper enum values?
I'm curious as to how the last two enums (e3 and e4) are allowed to compile and attain any value you want to...
Read more >
Examining Enums - The Reflection API
This reflection Java tutorial describes using reflection for accessing and manipulating classes, fields, methods, and constructors.
Read more >
Enums
No namespace - You must prefix constants of an int enum with a string (in this case SEASON_ ) to avoid collisions with...
Read more >
IBM Rational Rhapsody User Guide
dynamically roundtrip the changes back into the model and its graphical views. Rational Rhapsody supplies four editions to create specific types of projects ......
Read more >
Should one test the values of an enum using unit tests?
In other words, if you start from a passing test suite, and comment out any single enum value, then at least one test...
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