Bug 22059 - Missing TypeLoadException for TypeBuilder.CreateType() with private interface
Summary: Missing TypeLoadException for TypeBuilder.CreateType() with private interface
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: Reflection ()
Version: 3.2.x
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-08-13 00:27 UTC by Andrey Akinshin
Modified: 2014-08-18 21:39 UTC (History)
3 users (show)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Andrey Akinshin 2014-08-13 00:27:32 UTC
*** Overview ***
.NET Runtime should throw TypeLoadException when TypeBuilder.CreateType() creates Type with a declared private interface. Mono does not.

*** Steps to Reproduce ***
The minimal example:

using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Threading;

namespace FooProject
{
    class Program
    {
        static void Main()
        {
            var assemblyBuilder = Thread.GetDomain().DefineDynamicAssembly(
                new AssemblyName("FooAssembly"), AssemblyBuilderAccess.Run);
            var moduleBuilder = assemblyBuilder.DefineDynamicModule("FooAssembly");
            TypeBuilder typeBuilder = moduleBuilder.DefineType("Foo", TypeAttributes.Public,
                typeof(object), new[] { typeof(IFoo) });
            typeBuilder.CreateType();
            Console.WriteLine("DONE");
        }

        private interface IFoo
        {
        }
    }
}

*** Expected Results  ***
Microsoft .NET Runtime throw TypeLoadException for the line typeBuilder.CreateType(); because of the IFoo interface declared as a private. 

*** Actual Results ***
Mono run this code without any Exceptions. 

*** Platforms ***
I check it on:
Kubuntu 14.04, x64, Mono 3.2.8 (Debian 3.2.8+dfsg-4ubuntu1)
Windows 8.1, x64, Mono 3.3.0 (master/6cd4ddc)
Online compiler http://www.compileonline.com/, Mono 2.10.2.0
Comment 1 Andrey Akinshin 2014-08-13 02:07:56 UTC
Checked on:
Kubuntu 14.04, x64, Mono 3.8.1 (master/be86c5d)
Comment 2 Zoltan Varga 2014-08-18 21:39:20 UTC
Fixed in mono master 68e5cc395fd19366ed8e421f2f329fcf91d2b0b0.