greetings,

i think i found a bug in CompilerBase::GetFormNamespace().  the bug occurs
when you use a resx file that has no corresponding .cs file (ie, if i had a
Transform.resx in my project, but no Transform.cs).  GetFormNamespace()
tries to open the corresponding source file using File.OpenText(), but in
the given case the call fails resulting in a FileNotFoundException being
thrown.  This kills the build.

attached is a modification to the function that wraps the call in a try /
catch / finally and returns "" if no corresponding file can be found.  this
fits with the existing behavior, from what i can tell.

thanks,

--b


protected virtual string GetFormNamespace(string resxPath){
        
    // Determine Extension for compiler type
    string extension = GetExtension();
    string retnamespace = "";
    
    // open matching source file if it exists
    string sourceFile = resxPath.Replace( "resx", extension );

    StreamReader sr=null;
    try {
      sr = File.OpenText( sourceFile );
     
      while ( sr.Peek() > -1 ) {                               
        string str = sr.ReadLine();
        string matchnamespace =  @"namespace ((\w+.)*)";                               
 
        string matchnamespaceCaps =  @"Namespace ((\w+.)*)";    
        Regex matchNamespaceRE = new Regex(matchnamespace);
        Regex matchNamespaceCapsRE = new Regex(matchnamespaceCaps);
            
        if (matchNamespaceRE.Match(str).Success ){
          Match namematch = matchNamespaceRE.Match(str);
          retnamespace = namematch.Groups[1].Value; 
          retnamespace = retnamespace.Replace( "{", "" );
          retnamespace = retnamespace.Trim();
          break;
        }
        else  if (matchNamespaceCapsRE.Match(str).Success ) {
          Match namematch = matchNamespaceCapsRE.Match(str);
          retnamespace = namematch.Groups[1].Value;                     
          retnamespace = retnamespace.Trim();
          break;
        }
      }
    }catch(System.IO.FileNotFoundException) { // if no matching file, dump out
      return "";
    }finally {
      if(sr != null)
        sr.Close();
    }
    return retnamespace;
}

Reply via email to