Skip to content

Commit 97bb90b

Browse files
committed
Add cross platform path improvements for C#.
1 parent 3ea56ce commit 97bb90b

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

source/loaders/cs_loader/netcore/source/Providers/LoaderBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public bool LoadFromSourceFunctions(string[] source)
4747

4848
MetadataReference[] references;
4949

50-
var mainPath = Path.GetDirectoryName(typeof(object).GetTypeInfo().Assembly.Location) + "/";
50+
var mainPath = Path.GetDirectoryName(typeof(object).GetTypeInfo().Assembly.Location) + Path.DirectorySeparatorChar;
5151
var assemblyFiles = System.IO.Directory.GetFiles(mainPath, "*.dll");
5252

5353
assemblyFiles = assemblyFiles.Concat(this.AdditionalLibs()).Distinct().ToArray();

source/loaders/cs_loader/netcore/source/Providers/LoaderV1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ private Assembly Context_Resolving(AssemblyLoadContext context, AssemblyName nam
2424

2525
try
2626
{
27-
asm = context.LoadFromAssemblyPath(path + "\\" + name.Name + ".dll");
27+
asm = context.LoadFromAssemblyPath(Path.Combine(path, args.Name + ".dll"));
2828

2929
if (asm != null)
3030
{

source/loaders/cs_loader/netcore/source/Providers/LoaderV2.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,19 @@ public LoaderV2(ILog log) : base(log)
1919
private Assembly AssemblyResolveEventHandler(object sender, ResolveEventArgs args)
2020
{
2121
Assembly asm = null;
22-
23-
this.log.Info("CSLoader resolving assembly " + args.Name);
22+
AssemblyName assemName = args.RequestingAssembly.GetName();
2423

2524
foreach (var path in paths)
2625
{
27-
this.log.Info("CSLoader resolving path " + path);
28-
2926
try
3027
{
31-
var fullPath = path + "\\" + args.Name + ".dll";
32-
33-
this.log.Info(fullPath);
28+
var fullPath = Path.Combine(path, assemName.Name + ".dll");
3429

3530
asm = Assembly.LoadFile(fullPath);
3631

3732
if (asm != null)
3833
{
34+
log.Info("Assembly loaded: " + fullPath);
3935
return asm;
4036
}
4137
else
@@ -45,7 +41,7 @@ private Assembly AssemblyResolveEventHandler(object sender, ResolveEventArgs arg
4541
}
4642
catch (Exception ex)
4743
{
48-
log.Error(string.Format("Exception when loading the Assembly {0}: {1}", args.Name, ex.Message), ex);
44+
log.Error(string.Format("Exception when loading the Assembly {0}: {1}", assemName.Name, ex.Message), ex);
4945
}
5046
}
5147

@@ -54,6 +50,16 @@ private Assembly AssemblyResolveEventHandler(object sender, ResolveEventArgs arg
5450

5551
protected override IEnumerable<string> AdditionalLibs()
5652
{
53+
/*
54+
IEnumerable<string> libs = System.IO.Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll");
55+
56+
foreach (var path in paths)
57+
{
58+
libs = libs.Concat(System.IO.Directory.GetFiles(path, "*.dll"));
59+
}
60+
61+
return libs; // TODO: Unique
62+
*/
5763
return System.IO.Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll");
5864
}
5965

0 commit comments

Comments
 (0)