Bug 59080 - Type information of underlying type for enums compiled by Mono.CSharp.dll seems to be incorrect
Summary: Type information of underlying type for enums compiled by Mono.CSharp.dll see...
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: 5.4 (2017-06)
Hardware: PC All
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2017-08-28 13:47 UTC by Michael Stoyke
Modified: 2017-10-10 15:15 UTC (History)
3 users (show)

See Also:
Tags: bugpool
Is this bug a regression?: ---
Last known good build:


Attachments
Repro (1001 bytes, text/plain)
2017-10-03 13:20 UTC, Michael Stoyke
Details

Description Michael Stoyke 2017-08-28 13:47:19 UTC
(follow up for https://bugzilla.xamarin.com/show_bug.cgi?id=58291)

Tried this with commit 632c5e8e1cd3f5c977d370a6b7f1fcb3319d566e in the Mono repository (branch: 2017-08)

If we try to iterate the fields (reflection) of a class that is using an enum compiled with Mono.CSharp.dll, we get an exception:

System.TypeLoadException: Field 'MyEnumParameter' is an enum type with a bad underlying type
at (wrapper managed-to-native) System.RuntimeType:GetFields_native (System.RuntimeType,intptr,System.Reflection.BindingFlags)
at System.RuntimeType.GetFields_internal (System.String name, System.Reflection.BindingFlags bindingAttr, System.RuntimeType reflectedType) [0x0001a] in <8bab4e9291ac48d3a5b37cf4064ebe75>:0 
at System.RuntimeType.GetFieldCandidates (System.String name, System.Reflection.BindingFlags bindingAttr, System.Boolean allowPrefixLookup) [0x0000f] in <8bab4e9291ac48d3a5b37cf4064ebe75>:0 
at System.RuntimeType.GetFields (System.Reflection.BindingFlags bindingAttr) [0x00000] in <8bab4e9291ac48d3a5b37cf4064ebe75>:0
Comment 1 Marek Safar 2017-10-02 17:12:49 UTC
Michael, could you share a repro with me?
Comment 2 Michael Stoyke 2017-10-03 13:20:26 UTC
Created attachment 25069 [details]
Repro

I've attached Repro.cs, compiling and running it with Mono 5.4.0.199 (beta) results in this exception:

System.TypeLoadException: Field 'test' is an enum type with a bad underlying type
  at (wrapper managed-to-native) System.RuntimeType:GetCorrespondingInflatedConstructor (System.RuntimeType,System.Reflection.ConstructorInfo)
  at System.RuntimeType.GetConstructor (System.Reflection.ConstructorInfo fromNoninstanciated) [0x00014] in <75ffaf6443f740858d084c45da3fa568>:0
  at System.Reflection.Emit.ConstructorBuilder.RuntimeResolve () [0x0000b] in <75ffaf6443f740858d084c45da3fa568>:0
  at System.Reflection.Emit.ModuleBuilder.RuntimeResolve (System.Object obj) [0x0001c] in <75ffaf6443f740858d084c45da3fa568>:0
  at Mono.CSharp.Evaluator.Evaluate (System.String input, System.Object& result, System.Boolean& result_set) [0x00038] in <ac7d30b6a6cd402fa5b7a6440c56ef0b>:0
  at Mono.CSharp.Evaluator.Evaluate (System.String input) [0x00000] in <ac7d30b6a6cd402fa5b7a6440c56ef0b>:0
  at ConsoleApplication.Program.Main (System.String[] args) [0x0003b] in <7d62945435874bf4878f06e4908c4604>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Field 'test' is an enum type with a bad underlying type
  at (wrapper managed-to-native) System.RuntimeType:GetCorrespondingInflatedConstructor (System.RuntimeType,System.Reflection.ConstructorInfo)
  at System.RuntimeType.GetConstructor (System.Reflection.ConstructorInfo fromNoninstanciated) [0x00014] in <75ffaf6443f740858d084c45da3fa568>:0
  at System.Reflection.Emit.ConstructorBuilder.RuntimeResolve () [0x0000b] in <75ffaf6443f740858d084c45da3fa568>:0
  at System.Reflection.Emit.ModuleBuilder.RuntimeResolve (System.Object obj) [0x0001c] in <75ffaf6443f740858d084c45da3fa568>:0
  at Mono.CSharp.Evaluator.Evaluate (System.String input, System.Object& result, System.Boolean& result_set) [0x00038] in <ac7d30b6a6cd402fa5b7a6440c56ef0b>:0
  at Mono.CSharp.Evaluator.Evaluate (System.String input) [0x00000] in <ac7d30b6a6cd402fa5b7a6440c56ef0b>:0
  at ConsoleApplication.Program.Main (System.String[] args) [0x0003b] in <7d62945435874bf4878f06e4908c4604>:0
Comment 3 Marek Safar 2017-10-10 09:36:48 UTC
https://github.com/mono/mono/pull/5754
Comment 4 Marek Safar 2017-10-10 15:15:41 UTC
Fixed in master

Note You need to log in before you can comment on or make changes to this bug.