From c97d3dc507fbe236e9e4772031359e911ac20c01 Mon Sep 17 00:00:00 2001 From: ayende Date: Tue, 26 Feb 2008 14:20:27 +0000 Subject: [PATCH] Attempting to fix NRE in CreateBrailBase git-svn-id: https://svn.castleproject.org/svn/castle/trunk@4848 73e77b4c-caa6-f847-a29a-24ab75ae54b6 --- .../Castle.MonoRail.Views.Brail/BooViewEngine.cs | 25 ++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/MonoRail/Castle.MonoRail.Views.Brail/BooViewEngine.cs b/MonoRail/Castle.MonoRail.Views.Brail/BooViewEngine.cs index 2c0cac9eb..d25206455 100644 --- a/MonoRail/Castle.MonoRail.Views.Brail/BooViewEngine.cs +++ b/MonoRail/Castle.MonoRail.Views.Brail/BooViewEngine.cs @@ -49,7 +49,13 @@ namespace Castle.MonoRail.Views.Brail /// used to hold the constructors of types, so we can avoid using /// Activator (which takes a long time /// - private readonly Hashtable constructors = new Hashtable(); + private readonly Hashtable constructors = Hashtable.Synchronized(new Hashtable()); + + /// + /// Used to map between type and file name, this is useful when we + /// want to remove a script by its type. + /// + private readonly Hashtable typeToFileName = Hashtable.Synchronized(new Hashtable()); private string baseSavePath; @@ -456,6 +462,19 @@ namespace Castle.MonoRail.Views.Brail TextWriter output, Type type) { ConstructorInfo constructor = (ConstructorInfo) constructors[type]; + if(constructor==null) + { + string message = "Could not find a constructor for "+type+", but it was found in the compilation cache. Clearing the compilation cache for the type, please try again"; + Log(message); + + object key = this.typeToFileName[type]; + if(key!=null) + { + compilations.Remove(key); + } + + throw new MonoRailException(message); + } BrailBase self = (BrailBase) FormatterServices.GetUninitializedObject(type); constructor.Invoke(self, new object[] {this, output, context, controller, controllerContext}); return self; @@ -497,7 +516,9 @@ namespace Castle.MonoRail.Views.Brail typeof(IController), typeof(IControllerContext) }); - compilations[inputs2FileName[input]] = type; + string compilationName = inputs2FileName[input]; + typeToFileName[type] = compilationName; + compilations[compilationName] = type; } type = (Type) compilations[filename]; return type; -- 2.11.4.GIT