Bugzilla – Bug 324055
[PATCH] NullReferenceException when compiling ASP.NET code
Last modified: 2007-09-15 21:24:23 UTC
---- Reported by frederik.carlier@ugent.be 2007-04-14 11:19:52 MST ---- Description of Problem: Compiling the attached ASP.NET-generated code, currently crashes the compiler Steps to reproduce the problem: 1. vbnc aspnet.vb /r:System.Web.dll /target:library /r:VIA.Web.dll Actual Results: Visual Basic.Net Compiler version 0.0.0.4855 Copyright (C) 2004-2007 Rolf Bjarne Kvinge. All rights reserved. Unexpected error: Object reference not set to an instance of an object at vbnc.Helper.EmitArgumentsAndCallOrCallVirt (vbnc.EmitInfo Info, vbnc.Expression InstanceExpression, vbnc.ArgumentList Arguments, System.Reflection.MethodBase Method) [0x00000] at vbnc.PropertyAccessClassification.GenerateCode (vbnc.EmitInfo Info) [0x00000] at vbnc.AssignmentStatement.GenerateCode (vbnc.EmitInfo Info) [0x00000] at vbnc.CodeBlock.GenerateCode (vbnc.EmitInfo Info) [0x00000] at vbnc.CodeBlock.GenerateCode (IMethod Method) [0x00000] at vbnc.MethodBaseDeclaration.GenerateCode (vbnc.EmitInfo Info) [0x00000] at vbnc.MethodDeclaration.GenerateCode (vbnc.EmitInfo Info) [0x00000] at vbnc.SubDeclaration.GenerateCode (vbnc.EmitInfo Info) [0x00000] at vbnc.Helper.GenerateCodeCollection (IEnumerable Collection, vbnc.EmitInfo Info) [0x00000] at vbnc.BaseObjects`1[vbnc.IMember].GenerateCode (vbnc.EmitInfo ) [0x00000] at vbnc.AssemblyDeclaration.Emit (vbnc.TypeDeclaration Type) [0x00000] at vbnc.AssemblyDeclaration.Emit () [0x00000] at vbnc.Compiler.Compile () [0x00000] Compilation took 00:00:01.4908470 Expected Results: Compilation to succeed How often does this happen? Always Additional Information: This prevents an ASP.NET website from working. ---- Additional Comments From frederik.carlier@ugent.be 2007-04-14 11:20:14 MST ---- Created an attachment (id=171798) Source code required to reproduce the issue ---- Additional Comments From frederik.carlier@ugent.be 2007-04-14 11:20:50 MST ---- Created an attachment (id=171799) External assembly required to compile ---- Additional Comments From frederik.carlier@ugent.be 2007-04-14 18:25:23 MST ---- When running inside VS for debugging, the code crashes with this exception: System.InvalidOperationException occurred Message="Not a debug ModuleBuilder." Source="mscorlib" StackTrace: at System.Reflection.Emit.LocalBuilder.SetLocalSymInfo(String name, Int32 startOffset, Int32 endOffset) at System.Reflection.Emit.LocalBuilder.SetLocalSymInfo(String name) at vbnc.Emitter.DeclareLocal(EmitInfo Info, Type Type, String Name) in C:\Documents and Settings\Frederik Carlier\vbnc\source\Emit\Emitter.vb:line 47 The variable type is IParserAccessor and the variable name is "__parser". ---- Additional Comments From frederik.carlier@ugent.be 2007-04-14 19:05:28 MST ---- Created an attachment (id=171800) Source code required to reproduce the issue ---- Additional Comments From frederik.carlier@ugent.be 2007-04-14 19:09:11 MST ---- I added a more consice set of source code that reproduces the bug. Just type 'make' to repro. ---- Additional Comments From frederik.carlier@ugent.be 2007-04-14 19:13:31 MST ---- Created an attachment (id=171801) Source code required to reproduce the issue (tar.gz) ---- Additional Comments From frederik.carlier@ugent.be 2007-04-14 19:50:26 MST ---- This bug is caused by line 75 and 77 in Expressions\Classifications\PropertyAccessClassification.vb In these lines, PropertyInfo.GetSetMethod and PropertyInfo.GetGetMethod are called. These properties, however, only return accessors to *public* properties. See http://msdn2.microsoft.com/en-us/library/2ef4d5h3.aspx: "This is a convenience method that provides an implementation for the abstract GetSetMethod method with the nonPublic parameter set to false." In this case, the class inherits from another class. A reference to a protected (hence non-public) property is being made. It can be verified that this causes the bug by editing VIA.Web.vb and making the pdbTemplate field public. I'll try to create a patch. ---- Additional Comments From frederik.carlier@ugent.be 2007-04-14 20:05:20 MST ---- Created an attachment (id=171802) Proposed fix ---- Additional Comments From frederik.carlier@ugent.be 2007-04-14 20:06:59 MST ---- Added a proposed fix. However: 1. I'm not sure if the code should be verifying the calling class is a subclass of the class that defines the property (is this done earlier?) 2. In it's current state, this allows private properties to be called, too. You probably don't want that. The patch, however, does illustrate how to make the bug go away :) ---- Additional Comments From rolfkvinge@ya.com 2007-04-14 20:41:30 MST ---- The patch is ok and will go in (slightly modified - no checks are necessary since when the compiler starts to generate the code everything is already checked for, so I'll just pass true to the Get*Methods). ---- Additional Comments From rolfkvinge@ya.com 2007-04-16 14:30:01 MST ---- Fixed in r75770. Imported an attachment (id=171798) Imported an attachment (id=171799) Imported an attachment (id=171800) Imported an attachment (id=171801) Imported an attachment (id=171802) Unknown operating system unknown. Setting to default OS "Other".