Handle empty .resources files gracefully
authorMarek Habersack <grendel@twistedcode.net>
Fri, 9 Mar 2007 18:30:55 +0000 (18:30 -0000)
committerMarek Habersack <grendel@twistedcode.net>
Fri, 9 Mar 2007 18:30:55 +0000 (18:30 -0000)
svn path=/trunk/mcs/; revision=74022

mcs/class/System.Web/System.Web.Compilation/AppResourcesCompiler.cs
mcs/class/System.Web/System.Web.Compilation/ChangeLog

index 34bdfa90a5a563d9075ae782cecd899b1004cb39..667f2a37bd6def3fe419a96f23302bba750fb2ea 100644 (file)
@@ -359,6 +359,9 @@ namespace System.Web.Compilation
                void DomFromResource (string resfile, CodeCompileUnit unit, Dictionary <string,bool> assemblies,
                                      CodeDomProvider provider)
                {
+                       if (String.IsNullOrEmpty (resfile))
+                               return;
+
                        string fname, nsname, classname;
 
                        fname = Path.GetFileNameWithoutExtension (resfile);
@@ -375,6 +378,14 @@ namespace System.Web.Compilation
                        
                        if (!provider.IsValidIdentifier (nsname) || !provider.IsValidIdentifier (classname))
                                throw new ApplicationException ("Invalid resource file name.");
+
+                       ResourceReader res;
+                       try {
+                               res = new ResourceReader (resfile);
+                       } catch (ArgumentException) {
+                               // invalid stream, probably empty - ignore silently and abort
+                               return;
+                       }
                        
                        CodeNamespace ns = new CodeNamespace (nsname);
                        CodeTypeDeclaration cls = new CodeTypeDeclaration (classname);
@@ -415,7 +426,6 @@ namespace System.Web.Compilation
                        // Add the resource properties
                        Dictionary<string,bool> imports = new Dictionary<string,bool> ();
                        try {
-                               ResourceReader res = new ResourceReader (resfile);
                                foreach (DictionaryEntry de in res) {
                                        Type type = de.Value.GetType ();
 
@@ -435,7 +445,7 @@ namespace System.Web.Compilation
                                        cls.Members.Add (cmp);
                                }
                        } catch (Exception ex) {
-                               throw new ApplicationException ("Failed to comipile global resources.", ex);
+                               throw new ApplicationException ("Failed to compile global resources.", ex);
                        }
                        foreach (KeyValuePair<string,bool> de in imports)
                                ns.Imports.Add (new CodeNamespaceImport(de.Key));
index d9ff56a7c1e8ed31bb74b61190c50a875f76c2e4..af6c1f85487cb1ec20d26e546502a996e0f9d5a2 100644 (file)
@@ -1,5 +1,8 @@
 2007-03-09  Marek Habersack  <mhabersack@novell.com>
 
+       * AppResourcesCompiler.cs: attempt to load the resource file
+       earlier in the process, to gracefully handle empty files.
+
        * ThemeDirectoryCompiler.cs: make compiled themes depend on the
        .skin and .css files composing the theme.