diff --git a/src/Microsoft.ML.Core/ComponentModel/AssemblyLoadingUtils.cs b/src/Microsoft.ML.Core/ComponentModel/AssemblyLoadingUtils.cs index 493c0d2998..249ee23f73 100644 --- a/src/Microsoft.ML.Core/ComponentModel/AssemblyLoadingUtils.cs +++ b/src/Microsoft.ML.Core/ComponentModel/AssemblyLoadingUtils.cs @@ -31,6 +31,10 @@ public static void LoadAndRegister(IHostEnvironment env, string[] assemblies) { // REVIEW: Will LoadFrom ever return null? Contracts.CheckNonEmpty(path, nameof(path)); + if (!File.Exists(path)) + { + throw Contracts.ExceptParam(nameof(path), "File does not exist at path: {0}", path); + } var assem = LoadAssembly(env, path); if (assem != null) continue; diff --git a/src/Microsoft.ML.Data/DataLoadSave/Binary/BinaryLoaderSaverCatalog.cs b/src/Microsoft.ML.Data/DataLoadSave/Binary/BinaryLoaderSaverCatalog.cs index b4a48bd45a..fd15ab42d3 100644 --- a/src/Microsoft.ML.Data/DataLoadSave/Binary/BinaryLoaderSaverCatalog.cs +++ b/src/Microsoft.ML.Data/DataLoadSave/Binary/BinaryLoaderSaverCatalog.cs @@ -47,6 +47,10 @@ public static IDataView LoadFromBinary(this DataOperationsCatalog catalog, IMult public static IDataView LoadFromBinary(this DataOperationsCatalog catalog, string path) { Contracts.CheckNonEmpty(path, nameof(path)); + if (!File.Exists(path)) + { + throw Contracts.ExceptParam(nameof(path), "File does not exist at path: {0}", path); + } var env = catalog.GetEnvironment(); diff --git a/src/Microsoft.ML.Transforms/SvmLight/SvmLightLoaderSaverCatalog.cs b/src/Microsoft.ML.Transforms/SvmLight/SvmLightLoaderSaverCatalog.cs index e07665b43c..1a1afe0128 100644 --- a/src/Microsoft.ML.Transforms/SvmLight/SvmLightLoaderSaverCatalog.cs +++ b/src/Microsoft.ML.Transforms/SvmLight/SvmLightLoaderSaverCatalog.cs @@ -65,6 +65,10 @@ public static IDataView LoadFromSvmLightFile(this DataOperationsCatalog catalog, bool zeroBased = false) { Contracts.CheckNonEmpty(path, nameof(path)); + if (!File.Exists(path)) + { + throw Contracts.ExceptParam(nameof(path), "File does not exist at path: {0}", path); + } var file = new MultiFileSource(path); var loader = catalog.CreateSvmLightLoader(numberOfRows, inputSize, zeroBased, file); @@ -83,6 +87,10 @@ public static IDataView LoadFromSvmLightFileWithFeatureNames(this DataOperations long? numberOfRows = null) { Contracts.CheckNonEmpty(path, nameof(path)); + if (!File.Exists(path)) + { + throw Contracts.ExceptParam(nameof(path), "File does not exist at path: {0}", path); + } var file = new MultiFileSource(path); var loader = catalog.CreateSvmLightLoaderWithFeatureNames(numberOfRows, file);