Bugzilla – Bug 320229
[GMCS] Nullable types assignment crashes reflection
Last modified: 2007-09-15 21:24:23 UTC
---- Reported by vlm@lionet.info 2006-02-02 06:50:19 MST ---- Please fill in this template when reporting a bug, unless you know what you are doing. Description of Problem: When a nullable member of a class is assigned, reflection crashes in mono_object_unbox when trying to GetValue the object. Steps to reproduce the problem: 1. Create a nullable string member of a class. 2. Assign this member of a class to some "value". 3. Use fieldInfo.GetValue() on that member. Experience assertion failure. Actual Results: [vlm@nala:~]> mono mono_object_unbox.exe This statement can be reached ** ERROR **: file object.c: line 2978 (mono_object_unbox): assertion failed: (obj->vtable->klass- >valuetype) aborting... Abort trap [vlm@nala:~]> Expected Results: [vlm@nala:~]> mono mono_object_unbox.exe This statement can be reached THIS STATEMENT CANNOT BE REACHED [vlm@nala:~]> How often does this happen? 100% reproducible. Additional Information: ========================================================= using System; using System.Reflection; public class UnboxingProblem { public string? s; public static void Main() { UnboxingProblem problem = new UnboxingProblem(); FieldInfo[] fieldInfoList; fieldInfoList = problem.GetType() .GetFields(BindingFlags.Public | BindingFlags.Instance); FieldInfo fieldInfo = fieldInfoList[0]; object value = fieldInfo.GetValue(problem); if(value != null) Console.WriteLine("EXPECTATION FAILED"); problem.s = "string"; Console.WriteLine("This statement can be reached"); value = fieldInfo.GetValue(problem); Console.WriteLine("THIS STATEMENT CANNOT BE REACHED"); if(value == null) Console.WriteLine("EXPECTATION FAILED"); } } ========================================================== ---- Additional Comments From vlm@lionet.info 2006-02-02 06:51:24 MST ---- Created an attachment (id=169215) Shortest C# source exploiting the problem. ---- Additional Comments From vargaz@gmail.com 2006-02-09 09:46:09 MST ---- Fixed in SVN HEAD and 1.1.13. BTW, using string? does not have any advantage over using string, since reference types are already 'nullable'. ---- Additional Comments From vlm@lionet.info 2006-02-09 13:01:49 MST ---- String is of no importance; just for the sake of this test case. Thanks! ---- Additional Comments From bmaurer@users.sf.net 2006-02-09 16:27:33 MST ---- This should not work in the first place: C:\Program Files\Microsoft Visual Studio 8\VC>"C:\Documents and Settings\bmaure \Desktop\x.exe" Unhandled Exception: System.TypeLoadException: GenericArguments[0], 'System.Str ng', on 'System.Nullable`1[T]' violates the constraint of type parameter 'T'. Nullable<T> should be where T : struct. So the patch should probably be backed out, and the signature on nullable fixed. ---- Additional Comments From vargaz@gmail.com 2006-02-10 16:39:08 MST ---- The Nullable signature is now fixed. ---- Additional Comments From vargaz@gmail.com 2006-02-11 07:54:57 MST ---- The runtime changes are also reverted, so the original testcase is no longer valid. Imported an attachment (id=169215) Unknown bug field "cf_op_sys_details" encountered while moving bug <cf_op_sys_details>MacOS X 10.4</cf_op_sys_details> Unknown operating system unknown. Setting to default OS "Other".