提交 784d21f5 编写于 作者: R Rodrigo Kumpera

Fix AssemblyBuilder::GetTypes () with unfinished types.

	* AssemblyBuilder.cs (GetTypes): Raise ReflectionTypeLoadException
	if any type was not finished.

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

	Fixes #640288
上级 c101a18b
......@@ -825,6 +825,19 @@ namespace System.Reflection.Emit
}
}
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;
}
......
......@@ -1776,6 +1776,32 @@ public class AssemblyBuilderTest
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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册