//private FileInfo AbsolutePath(string relativePath) //{ // return new FileInfo(Path.Combine(ProjectFile.DirectoryName, relativePath)); //} /// <summary> /// Determine the location of the business lofic XML file for this project /// </summary> /// <remarks> /// The following locations will be searched in order for a /// file with an XPath of /Project/ProjectType that matches (case insenstive) /// the ProjectType of this project object. /// /// 1. ProjectFolder /// 2. %APPDATA%\RAVE\XML /// 3. SOFTWARE_DEPLOYMENT\XML /// /// </remarks> private FileInfo LoadBusinessLogicXML() { List <string> SearchFolders = new List <string>() { ProjectFile.DirectoryName, Path.Combine(ucProjectExplorer.AppDataFolder.FullName, Properties.Resources.BusinessLogicXMLFolder), Path.Combine(ucProjectExplorer.DeployFolder.FullName, Properties.Resources.BusinessLogicXMLFolder), }; foreach (string folder in SearchFolders) { string xmlPath = Path.ChangeExtension(Path.Combine(folder, ProjectType), "xml"); if (File.Exists(xmlPath)) { try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(xmlPath); System.Diagnostics.Debug.Print(string.Format("Using business logic at {0}", xmlPath)); return(new FileInfo(xmlPath)); } catch (Exception ex) { Exception ex2 = new FileLoadException(string.Format("Error Loading business logic from the following path." + " Remove or rename this file to allow RAVE to continue searching for alternative {0} business logic files.\n\n{1}", ProjectType, xmlPath), ex); ex2.Data["FilePath"] = xmlPath; throw ex2; } } } return(null); }
// Reads whatever there is in a config file and returns a Dictionary. // The file must containt 'key = value' pairs in separate lines, otherwise // The method throws an exception private static Dictionary <string, string> ReadConfigFromFile(string pathToFile) { FileLoadException exception = new FileLoadException("Could not read config file!"); Dictionary <string, string> config = new Dictionary <string, string>(); StreamReader sr = new StreamReader(pathToFile); while (!sr.EndOfStream) { // Read line string line = sr.ReadLine(); // Check if it is a equals-sign separated pair string[] kvpair = line.Split('='); if (kvpair.Length != 2) { throw exception; } // Rremove leading/trailing whitespace string key = kvpair[0].Trim(); string val = kvpair[1].Trim(); // Input key/value pair into dictionary config[key] = val; } return(config); }
private void WriteFusionLogWithAssert(StringBuilder sb) { for (System.Exception exception = this.Exception; exception != null; exception = exception.InnerException) { string fusionLog = null; string fileName = null; FileNotFoundException exception2 = exception as FileNotFoundException; if (exception2 != null) { fusionLog = exception2.FusionLog; fileName = exception2.FileName; } FileLoadException exception3 = exception as FileLoadException; if (exception3 != null) { fusionLog = exception3.FusionLog; fileName = exception3.FileName; } BadImageFormatException exception4 = exception as BadImageFormatException; if (exception4 != null) { fusionLog = exception4.FusionLog; fileName = exception4.FileName; } if (!string.IsNullOrEmpty(fusionLog)) { this.WriteColoredSquare(sb, System.Web.SR.GetString("Error_Formatter_FusionLog"), System.Web.SR.GetString("Error_Formatter_FusionLogDesc", new object[] { fileName }), HttpUtility.HtmlEncode(fusionLog), false); return; } } }
// // Encapsulates the assembly ref->def matching policy. // private static bool AssemblyNameMatches(RuntimeAssemblyName refName, RuntimeAssemblyName defName, ref Exception preferredException) { // // The defName came from trusted metadata so it should be fully specified. // Debug.Assert(defName.Version != null); Debug.Assert(defName.CultureName != null); if (!(refName.Name.Equals(defName.Name, StringComparison.OrdinalIgnoreCase))) { return(false); } if (refName.Version != null) { if (!AssemblyVersionMatches(refVersion: refName.Version, defVersion: defName.Version)) { preferredException = new FileLoadException(SR.Format(SR.FileLoadException_RefDefMismatch, refName.FullName, defName.Version, refName.Version)); return(false); } } if (refName.CultureName != null) { if (!(refName.CultureName.Equals(defName.CultureName))) { return(false); } } // Strong names are ignored in .NET Core return(true); }
public static void Ctor_String() { string message = "this is not the file you're looking for"; var exception = new FileLoadException(message); ExceptionUtility.ValidateExceptionProperties(exception, hResult: HResults.COR_E_FILELOAD, message: message); Assert.Null(exception.FileName); }
public static void FileLoadException_ctor_string() { string message = "this is not the file you're looking for"; FileLoadException fle = new FileLoadException(message); Utility.ValidateExceptionProperties(fle, hResult: HResults.COR_E_FILELOAD, message: message); Assert.Equal(null, fle.FileName); }
private PopupDialog createLoadExceptionDialog(FileLoadException loadException) => new OkPopupDialog { Icon = FontAwesome.Solid.Bug, HeaderText = @"File loading error", BodyText = loadException.Message, };
public static void FileLoadException_ctor() { FileLoadException fle = new FileLoadException(); Utility.ValidateExceptionProperties(fle, hResult: HResults.COR_E_FILELOAD, validateMessage: false); Assert.Equal(null, fle.FileName); }
public static void Ctor_Empty() { var exception = new FileLoadException(); ExceptionUtility.ValidateExceptionProperties(exception, hResult: HResults.COR_E_FILELOAD, validateMessage: false); Assert.Null(exception.FileName); }
public static void Ctor_String_Exception() { string message = "this is not the file you're looking for"; var innerException = new Exception("Inner exception"); var exception = new FileLoadException(message, innerException); ExceptionUtility.ValidateExceptionProperties(exception, hResult: HResults.COR_E_FILELOAD, innerException: innerException, message: message); Assert.Equal(null, exception.FileName); }
public static void Ctor_String() { string message = "this is not the file you're looking for"; var exception = new FileLoadException(message); ExceptionUtility.ValidateExceptionProperties(exception, hResult: HResults.COR_E_FILELOAD, message: message); Assert.Null(exception.FileName); }
public static void FileLoadException_ctor_string() { string message = "this is not the file you're looking for"; FileLoadException fle = new FileLoadException(message); Utility.ValidateExceptionProperties(fle, hResult: HResults.COR_E_FILELOAD, message: message); Assert.Equal(null, fle.FileName); }
public static void FusionLogTest() { string message = "this is not the file you're looking for"; string fileName = "file.txt"; var innerException = new Exception("Inner exception"); var exception = new FileLoadException(message, fileName, innerException); Assert.Null(exception.FusionLog); }
public static void Ctor_String_String() { string message = "this is not the file you're looking for"; string fileName = "file.txt"; var exception = new FileLoadException(message, fileName); ExceptionHelpers.ValidateExceptionProperties(exception, hResult: HResults.COR_E_FILELOAD, message: message); Assert.Equal(fileName, exception.FileName); }
// // Encapsulates the assembly ref->def matching policy. // private bool AssemblyNameMatches(RuntimeAssemblyName refName, RuntimeAssemblyName defName, ref Exception preferredException) { // // The defName came from trusted metadata so it should be fully specified. // Debug.Assert(defName.Version != null); Debug.Assert(defName.CultureName != null); Debug.Assert((defName.Flags & AssemblyNameFlags.PublicKey) == 0); Debug.Assert((refName.Flags & AssemblyNameFlags.PublicKey) == 0); if (!(refName.Name.Equals(defName.Name, StringComparison.OrdinalIgnoreCase))) { return(false); } if (refName.Version != null) { if (!AssemblyVersionMatches(refVersion: refName.Version, defVersion: defName.Version)) { preferredException = new FileLoadException(SR.Format(SR.FileLoadException_RefDefMismatch, refName.FullName, defName.Version, refName.Version)); return(false); } } if (refName.CultureName != null) { if (!(refName.CultureName.Equals(defName.CultureName))) { return(false); } } AssemblyNameFlags materialRefNameFlags = refName.Flags.ExtractAssemblyNameFlags(); AssemblyNameFlags materialDefNameFlags = defName.Flags.ExtractAssemblyNameFlags(); if (materialRefNameFlags != materialDefNameFlags) { return(false); } byte[] refPublicKeyToken = refName.PublicKeyOrToken; if (refPublicKeyToken != null) { byte[] defPublicKeyToken = defName.PublicKeyOrToken; if (defPublicKeyToken == null) { return(false); } if (!ArePktsEqual(refPublicKeyToken, defPublicKeyToken)) { return(false); } } return(true); }
public static void FileLoadException_ctor_string_string_exception() { string message = "this is not the file you're looking for"; string fileName = "file.txt"; Exception innerException = new Exception("Inner exception"); FileLoadException fle = new FileLoadException(message, fileName, innerException); Utility.ValidateExceptionProperties(fle, hResult: HResults.COR_E_FILELOAD, innerException: innerException, message: message); Assert.Equal(fileName, fle.FileName); }
public static void Ctor_String_Exception() { string message = "this is not the file you're looking for"; var innerException = new Exception("Inner exception"); var exception = new FileLoadException(message, innerException); ExceptionUtility.ValidateExceptionProperties(exception, hResult: HResults.COR_E_FILELOAD, innerException: innerException, message: message); Assert.Equal(null, exception.FileName); }
public void GetFusionLog_Fail_ControlPolicy() { FileLoadException fle = new FileLoadException(); Assert.IsNull(fle.FusionLog, "FusionLog"); // we don't have to throw the exception to have FusionLog // informations restricted (even if there could be no // data in this state). }
public void GetFusionLog_Pass() { FileLoadException fle = new FileLoadException("message", "filename"); Assert.AreEqual("message", fle.Message, "Message"); Assert.AreEqual("filename", fle.FileName, "FileName"); Assert.IsNull(fle.FusionLog, "FusionLog"); // note: ToString doesn't work in this case }
public void NoRestriction() { FileLoadException fle = new FileLoadException("message", "filename", new FileLoadException("inner message", "inner filename")); Assert.AreEqual("message", fle.Message, "Message"); Assert.AreEqual("filename", fle.FileName, "FileName"); Assert.IsNull(fle.FusionLog, "FusionLog"); Assert.IsNotNull(fle.ToString(), "ToString"); }
public static void FileLoadException_ctor_string_string_exception() { string message = "this is not the file you're looking for"; string fileName = "file.txt"; Exception innerException = new Exception("Inner exception"); FileLoadException fle = new FileLoadException(message, fileName, innerException); Utility.ValidateExceptionProperties(fle, hResult: HResults.COR_E_FILELOAD, innerException: innerException, message: message); Assert.Equal(fileName, fle.FileName); }
public void FullRestriction() { FileLoadException fle = new FileLoadException("message", "filename", new FileLoadException("inner message", "inner filename")); Assert.AreEqual("message", fle.Message, "Message"); Assert.AreEqual("filename", fle.FileName, "FileName"); Assert.IsNull(fle.FusionLog, "FusionLog"); // ToString doesn't work in this case and strangely throws a FileLoadException Assert.IsNotNull(fle.ToString(), "ToString"); }
private void SetMessageField() { if (_message == null) { if ((_fileName == null) && (HResult == HResults.COR_E_EXCEPTION)) _message = SR.Arg_BadImageFormatException; else _message = FileLoadException.FormatFileLoadExceptionMessage(_fileName, HResult); } }
// Token: 0x06000A11 RID: 2577 RVA: 0x0002077C File Offset: 0x0001E97C private void SetMessageField() { if (this._message == null) { if (this._fileName == null && base.HResult == -2146233088) { this._message = Environment.GetResourceString("Arg_BadImageFormatException"); return; } this._message = FileLoadException.FormatFileLoadExceptionMessage(this._fileName, base.HResult); } }
private void ReadFromJson() { try { using StreamReader sr = new StreamReader(_dataPath); data = JsonConvert.DeserializeObject <JsonDataFileWrapper>(sr.ReadToEnd()); } catch (Exception ex) { Exception dataExcepion = new FileLoadException("data file could not be read. invalid file/format.", ex); data = new JsonDataFileWrapper(); InitializeJson(); ReadFromJson(); throw dataExcepion; } }
public void ErrorMessageShownWhenLoadAssemblyFromThrowsFileLoadException() { IAddInTree addInTree = MockRepository.GenerateStrictMock <IAddInTree>(); DerivedRuntime runtime = new DerivedRuntime(addInTree, "Missing.dll", String.Empty); FileLoadException ex = new FileLoadException("Test"); runtime.LoadAssemblyFromExceptionToThrow = ex; runtime.Load(); string expectedErrorMessageStart = "The addin 'Missing.dll' could not be loaded:\n" + "System.IO.FileLoadException: Test"; string errorMessage = runtime.ErrorMessageDisplayed; Assert.IsTrue(errorMessage.StartsWith(expectedErrorMessageStart), errorMessage); }
public void ErrorMessageShownWhenLoadAssemblyFromThrowsFileLoadException() { List <AddIn> addIns = new List <AddIn>(); DerivedRuntime runtime = new DerivedRuntime("Missing.dll", String.Empty, addIns); FileLoadException ex = new FileLoadException("Test"); runtime.LoadAssemblyFromExceptionToThrow = ex; runtime.Load(); string expectedErrorMessageStart = "The addin 'Missing.dll' could not be loaded:\n" + "System.IO.FileLoadException: Test"; string errorMessage = runtime.ErrorMessageDisplayed; Assert.IsTrue(errorMessage.StartsWith(expectedErrorMessageStart), errorMessage); }
public static void FileLoadException_ToString() { string message = "this is not the file you're looking for"; string fileName = "file.txt"; Exception innerException = new Exception("Inner exception"); FileLoadException fle = new FileLoadException(message, fileName, innerException); var toString = fle.ToString(); AssertContains(": " + message, toString); AssertContains(": '" + fileName + "'", toString); AssertContains("---> " + innerException.ToString(), toString); // set the stack trace try { throw fle; } catch { Assert.False(string.IsNullOrEmpty(fle.StackTrace)); AssertContains(fle.StackTrace, fle.ToString()); } }
public static void FileLoadException_ToString() { string message = "this is not the file you're looking for"; string fileName = "file.txt"; Exception innerException = new Exception("Inner exception"); FileLoadException fle = new FileLoadException(message, fileName, innerException); var toString = fle.ToString(); AssertContains(": " + message, toString); AssertContains(": '" + fileName + "'", toString); AssertContains("---> " + innerException.ToString(), toString); // set the stack trace try { throw fle; } catch { Assert.False(string.IsNullOrEmpty(fle.StackTrace)); AssertContains(fle.StackTrace, fle.ToString()); } }
private string GetFileLoadingErrorMessage(FileLoadException exception, Version quartzVersion, Assembly quartzAssembly) { if (exception.FileName.StartsWith("Quartz,")) { string[] fileNameParts = exception.FileName.Split(',', '='); if (fileNameParts.Length > 2 && fileNameParts[1].Trim().Equals("Version", StringComparison.InvariantCultureIgnoreCase)) { string expectedVersion = fileNameParts[2]; return(string.Format( @"Quartz.NET version mismatch detected. CrystalQuartz expects v{0} but {1} was found in the host application. Consider adding the following bindings to the .config file: <dependentAssembly> <assemblyIdentity name=""Quartz"" publicKeyToken=""{2}"" culture=""neutral""/> <bindingRedirect oldVersion=""0.0.0.0-{3}.9.9.9"" newVersion=""{1}""/> </dependentAssembly>", expectedVersion, quartzVersion, GetPublicKeyTokenFromAssembly(quartzAssembly), quartzVersion.Major)); } } return(exception.Message); }
/// <summary> /// Load all assemblies from directory /// </summary> public static void LoadAssemblies() { var parentDir = AppDomain.CurrentDomain.BaseDirectory; var assemblies = Directory.GetFiles(parentDir, "*.dll", SearchOption.TopDirectoryOnly); foreach (var assemblyFile in assemblies) { if (AppDomain.CurrentDomain.GetAssemblies().Any(loadedAssembly => NamesMatch(loadedAssembly, assemblyFile))) { continue; } try { Assembly.LoadFrom(assemblyFile); } catch (Exception ex) { var loadEx = new FileLoadException("Failed to load assembly file " + assemblyFile, ex); Console.WriteLine(ExceptionPrinter.Print(loadEx)); } } }
public static string ToString(FileLoadException aThis) { throw new NotImplementedException("FileLoadException.ToString()"); }
public void GetFusionLog_Fail_ControlEvidence() { FileLoadException fle = new FileLoadException(); Assert.IsNull(fle.FusionLog, "FusionLog"); }
public static void FileLoadException_ctor() { FileLoadException fle = new FileLoadException(); Utility.ValidateExceptionProperties(fle, hResult: HResults.COR_E_FILELOAD, validateMessage: false); Assert.Equal(null, fle.FileName); }
public static void Ctor_Empty() { var exception = new FileLoadException(); ExceptionUtility.ValidateExceptionProperties(exception, hResult: HResults.COR_E_FILELOAD, validateMessage: false); Assert.Null(exception.FileName); }
public static void FusionLogTest() { string message = "this is not the file you're looking for"; string fileName = "file.txt"; var innerException = new Exception("Inner exception"); var exception = new FileLoadException(message, fileName, innerException); Assert.Null(exception.FusionLog); }
public static IrdFile Load(string path) { Exception ex = null; bool update_ird_file = false; IrdFile ird = new IrdFile(); try { ird.FullPath = path; using (Stream s = Open(path)) { using (CrcCalculatorStream crc = new CrcCalculatorStream(s, true)) { using (BinaryReader br = new BinaryReader(crc)) { // Read magic byte[] magic = br.ReadBytes(4); if (magic.AsString() != MAGIC.AsString()) { ex = new FileLoadException("Invalid IRD file", path); throw ex; } // Read version ird.Version = br.ReadByte(); if (ird.Version != IrdVersion) { if (!CompatibleVersions.Any(v => v == ird.Version)) { ex = new FileLoadException("Unsupported IRD file version (Found version " + ird.Version + ")", path); throw ex; } update_ird_file = true; } ird.gameId = Encoding.ASCII.GetString(br.ReadBytes(9)).Trim('\0'); ird.GameName = br.ReadString(); // Read version of update file byte[] update = br.ReadBytes(4); ird.UpdateVersion = Encoding.ASCII.GetString(update).Trim('\0'); // Read the gameversion byte[] gameVersion = br.ReadBytes(5); ird.GameVersion = Encoding.ASCII.GetString(gameVersion).Trim('\0'); byte[] appVersion = br.ReadBytes(5); ird.AppVersion = Encoding.ASCII.GetString(appVersion).Trim('\0'); // Read header and footer sectors ird.Header = br.Uncompress(); ird.Footer = br.Uncompress(); // Read region hashes int amountOfHashes = br.ReadByte(); for (int i = 0; i < amountOfHashes; i++) { byte[] hash = br.ReadBytes(0x10); ird.RegionHashes.Add(hash); } // Read file hashes int amountOfFiles = br.ReadInt32(); ird.FileHashes = new Dictionary <long, byte[]>(amountOfFiles); for (int i = 0; i < amountOfFiles; i++) { long sector = br.ReadInt64(); byte[] hash = br.ReadBytes(0x10); ird.FileHashes.Add(sector, hash); } // Read amount of attachments and extra config fields int extraConfig = br.ReadUInt16(); int attachments = br.ReadUInt16(); // Yes, we don't use these for now, but we might in the future ird.Data1 = br.ReadBytes(0x10); ird.Data2 = br.ReadBytes(0x10); ird.PIC = br.ReadBytes(0x73); } ird.Crc = (uint)crc.Crc; } byte[] crcValue = new byte[4]; s.Read(crcValue, 0, 4); if (ird.Crc != BitConverter.ToUInt32(crcValue, 0)) { ex = new FileLoadException("Invalid CRC value in the IRD file", path); throw ex; } } if (update_ird_file) { Interaction.Instance.ReportMessage("Updating IRD file to latest version: " + Path.GetFileName(path)); ird.Save(path); } return(ird); } catch (ZlibException) { // Annoying bug in the zlib decompression of Ionic.Zip if (ex != null) { throw ex; } return(ird); } catch (EndOfStreamException e) { throw new FileLoadException("Unexpected end of IRD file", path, e); } }
public static void ThrowIfNecessary( this Error error, [CanBeNull] Func <Error, string> message = null) { if (error == Error.Ok) { return; } var code = Enum.GetName(typeof(Error), error); var arg = message?.Invoke(error) ?? $"Operation failed with code: '{code}(error)'"; Exception exception; switch (error) { case Error.Unauthorized: case Error.FileNoPermission: exception = new UnauthorizedAccessException(arg); break; case Error.ParameterRangeError: exception = new ArgumentOutOfRangeException(null, arg); break; case Error.OutOfMemory: exception = new OutOfMemoryException(arg); break; case Error.FileBadDrive: case Error.FileBadPath: case Error.FileNotFound: exception = new FileNotFoundException(arg); break; case Error.FileAlreadyInUse: case Error.FileCantOpen: case Error.FileCantRead: case Error.FileCorrupt: case Error.FileMissingDependencies: case Error.FileUnrecognized: exception = new FileLoadException(arg); break; case Error.FileEof: exception = new EndOfStreamException(arg); break; case Error.FileCantWrite: case Error.CantAcquireResource: case Error.CantOpen: case Error.CantCreate: case Error.AlreadyInUse: case Error.Locked: exception = new IOException(arg); break; case Error.Timeout: exception = new TimeoutException(arg); break; case Error.InvalidData: exception = new InvalidDataException(arg); break; case Error.InvalidParameter: exception = new ArgumentException(null, arg); break; default: exception = new InvalidOperationException(arg); break; } throw exception; }