private ConfigurationCache ReadConfiguration(string hash) { if (!UserFolder.FileExists(UserFolder.DataModelFile)) { return(null); } try { var formatter = new BinaryFormatter(); using (var stream = UserFolder.OpenFile(UserFolder.DataModelFile)) { // if the stream is empty, stop here if (stream.Length == 0) { return(null); } var oldHash = (string)formatter.Deserialize(stream); if (hash != oldHash) { Logger.Information("The cached NHibernate configuration is out of date. A new one will be re-generated."); return(null); } var oldConfig = (Cfg)formatter.Deserialize(stream); return(new ConfigurationCache { Hash = oldHash, Configuration = oldConfig }); } } catch (Exception e) { for (var scan = e; scan != null; scan = scan.InnerException) { Logger.Warning("Error reading the cached NHibernate configuration: {0}", scan.Message); } Logger.Information("A new one will be re-generated."); return(null); } }