Skip to content

Commit

Permalink
Fix AssemblyBuilder::GetTypes () with unfinished types.
Browse files Browse the repository at this point in the history
	* AssemblyBuilder.cs (GetTypes): Raise ReflectionTypeLoadException
	if any type was not finished.

	* AssemblyBuilderTest.cs: Add test for GetTypes () and incomplete
	TypeBuilders'.

	Fixes #640288
  • Loading branch information
kumpera committed Sep 20, 2010
1 parent c101a18 commit 784d21f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions mcs/class/corlib/System.Reflection.Emit/AssemblyBuilder.cs
Expand Up @@ -825,6 +825,19 @@ public override FileStream GetFile (string name)
}
}

if (res != null) {
ArrayList exceptions = null;
foreach (var type in res) {
if (type is TypeBuilder) {
if (exceptions == null)
exceptions = new ArrayList ();
exceptions.Add (new TypeLoadException (string.Format ("Type '{0}' is not finished", FullName)));
}
}
if (exceptions != null)
throw new ReflectionTypeLoadException (new Type [exceptions.Count], (Exception[])exceptions.ToArray (typeof (Exception)));
}

return res == null ? Type.EmptyTypes : res;
}

Expand Down
Expand Up @@ -1776,6 +1776,32 @@ public void GetCustomAttributes_NotCreated ()
ab.GetCustomAttributes (true);
}


[Test]
public void GetTypesWithUnfinishedTypeBuilder ()
{
AssemblyBuilder ab = genAssembly ();
ModuleBuilder mb = ab.DefineDynamicModule("tester", "tester.dll", false);
mb.DefineType ("K").CreateType ();
var tb = mb.DefineType ("T");

try {
ab.GetTypes ();
Assert.Fail ("#1");
} catch (ReflectionTypeLoadException ex) {
Assert.AreEqual (1, ex.Types.Length, "#2");
Assert.AreEqual (1, ex.LoaderExceptions.Length, "#3");
Assert.IsNull (ex.Types [0], "#4");
Assert.IsTrue (ex.LoaderExceptions [0] is TypeLoadException, "#5");
}

tb.CreateType ();
var types = ab.GetTypes ();
Assert.AreEqual (2, types.Length, "#5");
foreach (var t in types)
Assert.IsFalse (t is TypeBuilder, "#6_" + t.Name);
}

private static void AssertAssemblyName (string tempDir, AssemblyName assemblyName, string abName, string fullName)
{
AppDomain currentDomain = AppDomain.CurrentDomain;
Expand Down

0 comments on commit 784d21f

Please sign in to comment.