Bug 19039 - Runtime crashes when evaluating FieldInfo.MetadataToken in Dynamic Assembly
Summary: Runtime crashes when evaluating FieldInfo.MetadataToken in Dynamic Assembly
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: Reflection (show other bugs)
Version: 3.8.0
Hardware: All All
: Normal normal
Target Milestone: ---
Assignee: Zoltan Varga
URL:
Depends on:
Blocks:
 
Reported: 2014-04-14 15:14 UTC by Eirik Tsarpalis
Modified: 2014-10-13 18:40 UTC (History)
5 users (show)

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


Attachments
F# script file that reproduces the problem. (637 bytes, application/octet-stream)
2014-04-14 15:14 UTC, Eirik Tsarpalis
Details
Shows the error details on mono 3.6.0 (14.62 KB, application/octet-stream)
2014-07-24 08:27 UTC, Dave Thomas
Details
Issue as filed in the Nessos.Vagrant project (42 bytes, text/plain)
2014-09-09 13:16 UTC, Eirik Tsarpalis
Details
Code reproducing the issue in C# interactive (527 bytes, application/octet-stream)
2014-09-10 11:38 UTC, Eirik Tsarpalis
Details
Standalone F# console application that reproduces this issue (47 bytes, text/plain)
2014-10-11 11:08 UTC, Eirik Tsarpalis
Details
F# console application that reproduces crash without need for Mono.Reflection (1.29 KB, application/octet-stream)
2014-10-11 18:27 UTC, Eirik Tsarpalis
Details

Description Eirik Tsarpalis 2014-04-14 15:14:34 UTC
Created attachment 6580 [details]
F# script file that reproduces the problem.

This is a rather obscure bug in mono's Reflection implementation. 
I was able to reproduce this in version 3.4.0 for Mac OS X using the standard Mono.Reflection library in F#.

The error message is as follows:
'* Assertion at reflection.c:7764, condition `field_index >= 0 && field_index < dgclass->count_fields' not met'
Comment 1 Dave Thomas 2014-07-24 08:27:06 UTC
Created attachment 7481 [details]
Shows the error details on mono 3.6.0
Comment 2 Dave Thomas 2014-07-24 08:31:55 UTC
I just built this as an applcation and doesn't crash, it only does so in the context of running as an FSI evaluation session.
Comment 3 Eirik Tsarpalis 2014-08-11 06:24:41 UTC
Yes, I should have clarified that from the start.

I still feel that this is a mono issue rather than an FSI issue. In particular I suspect that this relates to reflection in dynamic assemblies. I tried to reproduce this in mono's own C# interactive, but it seems that generic types are broken overall in the latest version (3.6.0). Is there anything else I could try out? (on par with .NET's CSharpCodeProvider).
Comment 4 Rodrigo Kumpera 2014-08-11 10:45:07 UTC
Eirik, what do you mean by "generic types are broken overall in the latest version (3.6.0)"?

This is the only issue we're aware of, the C# shell has been working fine.
Comment 5 Eirik Tsarpalis 2014-08-11 11:01:28 UTC
Perhaps I'm doing something wrong, but I found it impossible to reference a generic class defined from inside the shell. For example:

Mono C# Shell, type "help;" for help

Enter statements below.
csharp> public class Foo {
      >  
      > }
csharp> typeof(Foo)
Foo
csharp> public class Bar<T> {
      >  
      > }
csharp> typeof(Bar<int>)
(1,2): error CS0584: Internal compiler error: Object reference not set to an instance of an object
Comment 6 Miguel de Icaza [MSFT] 2014-09-09 12:57:47 UTC
Where does one get Mono.Reflectiondll from?
Comment 7 Eirik Tsarpalis 2014-09-09 13:01:14 UTC
It is available on nuget

https://www.nuget.org/packages/Mono.Reflection/
Comment 8 Eirik Tsarpalis 2014-09-09 13:16:45 UTC
Created attachment 7972 [details]
Issue as filed in the Nessos.Vagrant project
Comment 9 Miguel de Icaza [MSFT] 2014-09-10 10:08:13 UTC
This is what I get from the shell:

mac$ csharp
Mono C# Shell, type "help;" for help

Enter statements below.
csharp> public class Bar<T> { }
csharp> typeof(Bar<int>)
Bar`1[System.Int32]
csharp>  

This is with Mono 3.8.0
Comment 10 Miguel de Icaza [MSFT] 2014-09-10 10:15:46 UTC
I am unable to reproduce this issue with Mono 3.8.0
Comment 11 Eirik Tsarpalis 2014-09-10 10:26:25 UTC
This is an irrelevant issue that popped up while trying to reproduce the bug in C# interactive. I filed it under a separate report and was eventually fixed:

https://bugzilla.xamarin.com/show_bug.cgi?id=22393

The reflection issue, as stated in the original description, persists in Mono 3.8.0. I will attempt to produce a reproduction for C# interactive.
Comment 12 Miguel de Icaza [MSFT] 2014-09-10 10:42:36 UTC
You are confused Eirik.

I did two things (a) I commented on the C# REPL issue (comment #9) and (b) I tried the repro.fsx with Mono.Reflection.dll and was unable to reproduce it.

The program completes execution.

Mono JIT compiler version 3.8.0 ((no/45d0ba1 Tue Aug 26 20:33:43 EDT 2014)
Comment 13 Eirik Tsarpalis 2014-09-10 10:50:59 UTC
Strange, I am still getting this failure on repro.fsx with the following build on Ubuntu x64

Mono JIT compiler version 3.8.0 (tarball Thu Sep  4 12:22:04 UTC 2014)
Comment 14 Eirik Tsarpalis 2014-09-10 11:08:54 UTC
I can now confirm that the issue persists in the OS X release of mono 3.8.0. This happens either interactively or by running the script to fsharpi.

"3.8.0 ((no/45d0ba1 Tue Aug 26 20:33:43 EDT 2014)"
Comment 15 Eirik Tsarpalis 2014-09-10 11:38:25 UTC
Created attachment 7985 [details]
Code reproducing the issue in C# interactive

Running 'csharp -r:Mono.Reflection.dll repro.csx' results in the mono runtime crashing.
Comment 16 Eirik Tsarpalis 2014-09-10 12:59:55 UTC
I can confirm that the issue still occurs at the head of the master branch (built from source on Ubuntu x64).

Mono JIT compiler version 3.10.1 (master/bbbcc73 Τετ 10 Σεπ 2014 07:35:57 μμ EEST)
Comment 17 Eirik Tsarpalis 2014-09-10 16:03:13 UTC
Miguel, did you run the reproducing code through F# interactive or as a standalone application?

Crucially, it has to be the former since the problem only affects dynamic assemblies.
Comment 18 Miguel de Icaza [MSFT] 2014-09-10 16:18:19 UTC
Ah, didnt know that bit.

I do not know how to loads fsx into fsharpi, so I used fsharpc, that explains it.
Comment 19 Eirik Tsarpalis 2014-10-11 11:08:13 UTC
Created attachment 8384 [details]
Standalone F# console application that reproduces this issue
Comment 20 Eirik Tsarpalis 2014-10-11 18:27:12 UTC
Created attachment 8386 [details]
F# console application that reproduces crash without need for Mono.Reflection
Comment 21 Zoltan Varga 2014-10-13 18:40:48 UTC
Fixed in mono master 4cba98f8c002cdaca0031d07c348704d27c8f8a7.

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