Skip to content

Commit aa776e4

Browse files
assembly resolvation fix
1 parent 056a373 commit aa776e4

File tree

4 files changed

+46
-25
lines changed

4 files changed

+46
-25
lines changed

Reinforced.Typings.Cli/Bootstrapper.cs

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public static class Bootstrapper
4646
{
4747
private static ExporterConsoleParameters _parameters;
4848
private static readonly Dictionary<string, string> _referencesCache = new Dictionary<string, string>();
49-
private static string _lastAssemblyLocalDir;
49+
private static readonly HashSet<string> _allAssembliesDirs = new HashSet<string>();
50+
private static readonly Dictionary<string, Assembly> _alreadyLoaded = new Dictionary<string, Assembly>();
5051
private static int _totalLoadedAssemblies;
5152
private static TextReader _profileReader;
5253
private static string _profilePath;
@@ -76,7 +77,7 @@ public static void Main(string[] args)
7677
{
7778
if (!File.Exists(args[1]))
7879
{
79-
Console.WriteLine("Cannot find profile {0}, exiting",args[1]);
80+
Console.WriteLine("Cannot find profile {0}, exiting", args[1]);
8081
return;
8182
}
8283
_parameters = ExtractParametersFromFile(args[1]);
@@ -133,7 +134,7 @@ private static void ReleaseReferencesTempFile()
133134
{
134135
if (_profileReader != null) _profileReader.Dispose();
135136
if (!string.IsNullOrEmpty(_profilePath)) File.Delete(_profilePath);
136-
if(_parameters==null) return;
137+
if (_parameters == null) return;
137138
if (!string.IsNullOrEmpty(_parameters.ReferencesTmpFilePath)) File.Delete(_parameters.ReferencesTmpFilePath);
138139
}
139140

@@ -218,11 +219,12 @@ private static string LookupAssemblyPathInternal(string assemblyNameOrFullPath,
218219
Console.WriteLine("Looking up for assembly {0}", assemblyNameOrFullPath);
219220
#endif
220221

221-
if (Path.IsPathRooted(assemblyNameOrFullPath))
222+
if (Path.IsPathRooted(assemblyNameOrFullPath) && File.Exists(assemblyNameOrFullPath))
222223
{
223224
if (storeIfFullName)
224225
{
225-
_lastAssemblyLocalDir = Path.GetDirectoryName(assemblyNameOrFullPath) + "\\";
226+
var lastAssemblyLocalDir = Path.GetDirectoryName(assemblyNameOrFullPath) + "\\";
227+
if (!_allAssembliesDirs.Contains(lastAssemblyLocalDir)) _allAssembliesDirs.Add(lastAssemblyLocalDir);
226228
}
227229
#if DEBUG
228230
Console.WriteLine("Already have full path to assembly {0}", assemblyNameOrFullPath);
@@ -238,15 +240,20 @@ private static string LookupAssemblyPathInternal(string assemblyNameOrFullPath,
238240
#endif
239241
return rf;
240242
}
241-
var p = Path.Combine(_lastAssemblyLocalDir, assemblyNameOrFullPath);
242-
if (File.Exists(p))
243+
244+
foreach (var dir in _allAssembliesDirs)
243245
{
246+
var p = Path.Combine(dir, assemblyNameOrFullPath);
247+
if (File.Exists(p))
248+
{
244249
#if DEBUG
245-
Console.WriteLine("Assembly {0} found at {1}", assemblyNameOrFullPath, p);
250+
Console.WriteLine("Assembly {0} found at {1}", assemblyNameOrFullPath, p);
246251
#endif
247-
return p;
252+
return p;
253+
}
248254
}
249255

256+
250257
return null;
251258
}
252259

@@ -270,13 +277,7 @@ public static string LookupAssemblyPath(string assemblyNameOrFullPath, bool stor
270277
checkResult = LookupAssemblyPathInternal(p, storeIfFullName);
271278
if (!string.IsNullOrEmpty(checkResult)) return checkResult;
272279

273-
if (!string.IsNullOrEmpty(_lastAssemblyLocalDir) && !string.IsNullOrEmpty(assemblyNameOrFullPath))
274-
{
275-
p = Path.Combine(_lastAssemblyLocalDir, assemblyNameOrFullPath);
276-
checkResult = LookupAssemblyPathInternal(p, storeIfFullName);
277-
if (!string.IsNullOrEmpty(checkResult)) return checkResult;
278-
}
279-
BuildWarn("Assembly {0} may be resolved incorrectly", assemblyNameOrFullPath, p);
280+
280281
return assemblyNameOrFullPath;
281282
}
282283

@@ -295,6 +296,10 @@ public static Assembly[] GetAssembliesFromArgs()
295296
{
296297
var assemblyPath = _parameters.SourceAssemblies[i];
297298
var path = LookupAssemblyPath(assemblyPath);
299+
if (path == assemblyPath)
300+
{
301+
BuildWarn("Assembly {0} may be resolved incorrectly", assemblyPath);
302+
}
298303
#if NETCORE1
299304
var a = AssemblyLoadContext.Default.LoadFromAssemblyPath(path);
300305
#else
@@ -312,26 +317,42 @@ public static Assembly[] GetAssembliesFromArgs()
312317
#if NETCORE1
313318
private static Assembly CurrentDomainOnAssemblyResolve(AssemblyLoadContext context, AssemblyName assemblyName)
314319
{
315-
AssemblyLoadContext.Default.Resolving -= CurrentDomainOnAssemblyResolve;
320+
//AssemblyLoadContext.Default.Resolving -= CurrentDomainOnAssemblyResolve;
316321
if (assemblyName.Name.StartsWith("Reinforced.Typings.XmlSerializers")) return Assembly.GetEntryAssembly();
322+
if (_alreadyLoaded.ContainsKey(assemblyName.FullName)) return _alreadyLoaded[assemblyName.FullName];
317323
AssemblyName nm = new AssemblyName(assemblyName.Name);
318324
string path = LookupAssemblyPath(nm.Name, false);
319-
var a = context.LoadFromAssemblyPath(path);
325+
Assembly a = null;
326+
if (path != nm.Name) //else - lookup failed, return null
327+
{
328+
a = context.LoadFromAssemblyPath(path);
329+
}
330+
else
331+
{
332+
BuildWarn("Assembly {0} may be resolved incorrectly", assemblyName.FullName);
333+
}
334+
335+
if (a != null) _alreadyLoaded[nm.FullName] = a;
320336
_totalLoadedAssemblies++;
321337
#if DEBUG
322338
Console.WriteLine("{0} additionally resolved", nm);
323339
#endif
324340

325-
AssemblyLoadContext.Default.Resolving += CurrentDomainOnAssemblyResolve;
341+
//AssemblyLoadContext.Default.Resolving += CurrentDomainOnAssemblyResolve;
326342
return a;
327343
}
328344
#else
329345
public static Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs args)
330346
{
331347
if (args.Name.StartsWith("Reinforced.Typings.XmlSerializers")) return Assembly.GetExecutingAssembly();
348+
if (_alreadyLoaded.ContainsKey(args.Name)) return _alreadyLoaded[args.Name];
332349
AssemblyName nm = new AssemblyName(args.Name);
333350
string path = LookupAssemblyPath(nm.Name, false);
334-
Assembly a = Assembly.LoadFrom(path);
351+
Assembly a = null;
352+
if (path != nm.Name) a = Assembly.LoadFrom(path);
353+
else BuildWarn("Assembly {0} may be resolved incorrectly", nm.Name);
354+
355+
if (a != null) _alreadyLoaded[args.Name] = a;
335356
_totalLoadedAssemblies++;
336357
#if DEBUG
337358
Console.WriteLine("{0} additionally resolved", nm);

Reinforced.Typings.Cli/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"profiles": {
33
"Reinforced.Typings.Cli.NETCore": {
44
"commandName": "Project",
5-
"commandLineArgs": "profile \"C:\\Users\\Murcielago\\AppData\\Local\\Temp\\tmpD16F.tmp\""
5+
"commandLineArgs": "profile \"C:\\Users\\Murcielago\\AppData\\Local\\Temp\\tmp8C46.tmp\""
66
}
77
}
88
}

package/Reinforced.Typings.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
33
<metadata>
44
<id>Reinforced.Typings</id>
5-
<version>1.4.1</version>
5+
<version>1.4.2</version>
66
<title>Reinforced.Typings</title>
77
<authors>Pavel B. Novikov</authors>
88
<owners>Pavel B. Novikov</owners>
@@ -16,7 +16,7 @@
1616
<tags>mvc, web, typescript</tags>
1717
<licenseUrl>https://github.com/reinforced/Reinforced.Typings/blob/master/LICENSE.md</licenseUrl>
1818
<releaseNotes>
19-
- Fix conflict between attributes and fluent configuration
19+
- Additional assemblies resolvation fix
2020
</releaseNotes>
2121
<dependencies>
2222
<group targetFramework=".NETFramework4.5" />

version.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22
<PropertyGroup>
3-
<AssemblyVersion>1.4.0.0</AssemblyVersion>
4-
<FileVersion>1.4.0.0</FileVersion>
3+
<AssemblyVersion>1.4.2.0</AssemblyVersion>
4+
<FileVersion>1.4.2.0</FileVersion>
55
</PropertyGroup>
66
</Project>

0 commit comments

Comments
 (0)