diff --git a/STX.SPAL.Core.Tests.Unit/Services/Foundations/Assemblies/AssemblyServiceTests.cs b/STX.SPAL.Core.Tests.Unit/Services/Foundations/Assemblies/AssemblyServiceTests.cs index 6af69a5..1c135c1 100644 --- a/STX.SPAL.Core.Tests.Unit/Services/Foundations/Assemblies/AssemblyServiceTests.cs +++ b/STX.SPAL.Core.Tests.Unit/Services/Foundations/Assemblies/AssemblyServiceTests.cs @@ -82,9 +82,7 @@ public static TheoryData AssemblyLoadValidationDependencyExceptions() { return new TheoryData { - new ArgumentException(), - new ArgumentNullException(), - new PathTooLongException(), + new ArgumentException() }; } } diff --git a/STX.SPAL.Core/Services/Foundations/Assemblies/AssemblyService.Exceptions.cs b/STX.SPAL.Core/Services/Foundations/Assemblies/AssemblyService.Exceptions.cs index adc5f51..a1cb38e 100644 --- a/STX.SPAL.Core/Services/Foundations/Assemblies/AssemblyService.Exceptions.cs +++ b/STX.SPAL.Core/Services/Foundations/Assemblies/AssemblyService.Exceptions.cs @@ -2,9 +2,13 @@ // Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers // ---------------------------------------------------------------------------------- +using System.IO; +using System; using System.Reflection; +using System.Security; using STX.SPAL.Core.Models.Services.Foundations.Assemblies.Exceptions; using Xeptions; +using System.Runtime.InteropServices; namespace STX.SPAL.Core.Services.Foundations.Assemblies { @@ -24,6 +28,59 @@ private static Assembly TryCatch(ReturningAssemblyFunction returningAssemblyFunc throw CreateAssemblyValidationException( invalidAssemblyPathException); } + + catch (SecurityException securityException) + { + throw CreateAssemblyDependencyException( + securityException); + } + + catch (FileLoadException fileLoadException) + { + throw CreateAssemblyDependencyException( + fileLoadException); + } + + catch (FileNotFoundException fileNotFoundException) + { + throw CreateAssemblyDependencyException( + fileNotFoundException); + } + + catch (BadImageFormatException badImageFormatException) + { + throw CreateAssemblyDependencyException( + badImageFormatException); + } + + catch (InvalidOperationException invalidOperationException) + { + throw CreateAssemblyDependencyException( + invalidOperationException); + } + + catch (NotSupportedException notSupportedException) + { + throw CreateAssemblyDependencyException( + notSupportedException); + } + + catch (IOException iOException) + { + throw CreateAssemblyDependencyException(iOException); + } + + catch (UnauthorizedAccessException unauthorizedAccessException) + { + throw CreateAssemblyDependencyException( + unauthorizedAccessException); + } + + catch (ArgumentException argumentException) + { + throw CreateAssemblyDependencyException( + argumentException); + } } private static AssemblyValidationException CreateAssemblyValidationException(Xeption exception) @@ -32,5 +89,29 @@ private static AssemblyValidationException CreateAssemblyValidationException(Xep message: "Assembly validation error occurred, fix errors and try again.", innerException: exception); } + + private static AssemblyDependencyException CreateAssemblyDependencyException(Exception exception) + { + var assemblyLoadException = + new AssemblyLoadException( + message: "Assembly load error occurred, contact support.", + innerException: exception); + + return new AssemblyDependencyException( + message: "Assembly dependency error occurred, contact support.", + innerException: assemblyLoadException); + } + + private static AssemblyValidationDependencyException CreateAssemblyValidationDependencyException(Exception exception) + { + var assemblyLoadException = + new AssemblyLoadException( + message: "Assembly load error occurred, contact support.", + innerException: exception); + + return new AssemblyValidationDependencyException( + message: "Assembly validation dependency error occurred, contact support.", + innerException: assemblyLoadException); + } } }