Skip to content

Commit 022504a

Browse files
committed
Add path filtering back to LoadAssembliesInDir
1 parent 34d663c commit 022504a

File tree

2 files changed

+77
-5
lines changed

2 files changed

+77
-5
lines changed

src/Common/AssemblyLoadingUtils.cs

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static void LoadAndRegister(IHostEnvironment env, string[] assemblies)
7070
throw Contracts.ExceptIO(e, "Extracting extra assembly zip failed: '{0}'", path);
7171
}
7272

73-
LoadAssembliesInDir(env, dir);
73+
LoadAssembliesInDir(env, dir, false);
7474
}
7575
}
7676
}
@@ -110,7 +110,75 @@ private static string GetTempPath()
110110
return Path.GetFullPath(Path.Combine(Path.GetTempPath(), "MLNET_" + guid.ToString()));
111111
}
112112

113-
private static void LoadAssembliesInDir(IHostEnvironment env, string dir)
113+
private static readonly string[] _filePrefixesToAvoid = new string[] {
114+
"api-ms-win",
115+
"clr",
116+
"coreclr",
117+
"dbgshim",
118+
"ext-ms-win",
119+
"microsoft.bond.",
120+
"microsoft.cosmos.",
121+
"microsoft.csharp",
122+
"microsoft.data.",
123+
"microsoft.hpc.",
124+
"microsoft.live.",
125+
"microsoft.platformbuilder.",
126+
"microsoft.visualbasic",
127+
"microsoft.visualstudio.",
128+
"microsoft.win32",
129+
"microsoft.windowsapicodepack.",
130+
"microsoft.windowsazure.",
131+
"mscor",
132+
"msvc",
133+
"petzold.",
134+
"roslyn.",
135+
"sho",
136+
"sni",
137+
"sqm",
138+
"system.",
139+
"zlib",
140+
};
141+
142+
private static bool ShouldSkipPath(string path)
143+
{
144+
string name = Path.GetFileName(path).ToLowerInvariant();
145+
switch (name)
146+
{
147+
case "cqo.dll":
148+
case "fasttreenative.dll":
149+
case "libiomp5md.dll":
150+
case "libvw.dll":
151+
case "matrixinterf.dll":
152+
case "microsoft.ml.neuralnetworks.gpucuda.dll":
153+
case "mklimports.dll":
154+
case "microsoft.research.controls.decisiontrees.dll":
155+
case "microsoft.ml.neuralnetworks.sse.dll":
156+
case "neuraltreeevaluator.dll":
157+
case "optimizationbuilderdotnet.dll":
158+
case "parallelcommunicator.dll":
159+
case "microsoft.ml.runtime.runtests.dll":
160+
case "scopecompiler.dll":
161+
case "tbb.dll":
162+
case "internallearnscope.dll":
163+
case "unmanagedlib.dll":
164+
case "vcclient.dll":
165+
case "libxgboost.dll":
166+
case "zedgraph.dll":
167+
case "__scopecodegen__.dll":
168+
case "cosmosClientApi.dll":
169+
return true;
170+
}
171+
172+
foreach (var s in _filePrefixesToAvoid)
173+
{
174+
if (name.StartsWith(s))
175+
return true;
176+
}
177+
178+
return false;
179+
}
180+
181+
private static void LoadAssembliesInDir(IHostEnvironment env, string dir, bool filter)
114182
{
115183
if (!Directory.Exists(dir))
116184
return;
@@ -119,6 +187,9 @@ private static void LoadAssembliesInDir(IHostEnvironment env, string dir)
119187
var paths = Directory.EnumerateFiles(dir, "*.dll");
120188
foreach (string path in paths)
121189
{
190+
if (filter && ShouldSkipPath(path))
191+
continue;
192+
122193
LoadAssembly(env, path);
123194
}
124195
}
@@ -152,9 +223,9 @@ public AssemblyRegistrar(IHostEnvironment env, string path)
152223

153224
if (!string.IsNullOrEmpty(path))
154225
{
155-
LoadAssembliesInDir(_env, path);
226+
LoadAssembliesInDir(_env, path, true);
156227
path = Path.Combine(path, "AutoLoad");
157-
LoadAssembliesInDir(_env, path);
228+
LoadAssembliesInDir(_env, path, true);
158229
}
159230

160231
AppDomain.CurrentDomain.AssemblyLoad += CurrentDomainAssemblyLoad;

src/Microsoft.ML.Legacy/PredictionModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ public static Task<PredictionModel<TInput, TOutput>> ReadAsync<TInput, TOutput>(
126126
throw new ArgumentNullException(nameof(stream));
127127

128128
using (var environment = new ConsoleEnvironment())
129-
using (AssemblyLoadingUtils.CreateAssemblyRegistrar(environment))
130129
{
130+
AssemblyLoadingUtils.RegisterCurrentLoadedAssemblies(environment);
131+
131132
BatchPredictionEngine<TInput, TOutput> predictor =
132133
environment.CreateBatchPredictionEngine<TInput, TOutput>(stream);
133134

0 commit comments

Comments
 (0)