-
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't create shadow copy that already exists (#147)
In some scenarios the same unmanaged DLL is resolved multiple times (e.g. when using System.Data.SQLite.SQLiteConnection). The previous implementation would then try to create new shadow copies of the same DLL during subsequent resolves. This failed during copy of the DLL since the parameter to enable overwriting was not set to true. This fix checks if the shadow copy already exists and skips the copy step if it does. The path to the existing shadow copy is returned instead. Fixes #146
- Loading branch information
1 parent
467fc10
commit 0f397dd
Showing
6 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#if NETCOREAPP3_1 | ||
|
||
using Xunit; | ||
|
||
namespace McMaster.NETCore.Plugins.Tests | ||
{ | ||
public class ShadowCopyTests | ||
{ | ||
[Fact] | ||
public void DoesNotThrowWhenLoadingSameNativeDependecyMoreThanOnce() | ||
{ | ||
var samplePath = TestResources.GetTestProjectAssembly("NativeDependency"); | ||
|
||
using var loader = PluginLoader | ||
.CreateFromAssemblyFile(samplePath, config => config.EnableHotReload = true); | ||
|
||
var nativeDependecyLoadMethod = loader.LoadDefaultAssembly() | ||
.GetType("NativeDependency.NativeDependencyLoader") | ||
.GetMethod("Load"); | ||
|
||
var exception = Record.Exception(() => nativeDependecyLoadMethod.Invoke(null, null)); | ||
|
||
Assert.Null(exception); | ||
} | ||
} | ||
} | ||
|
||
#endif |
11 changes: 11 additions & 0 deletions
11
test/TestProjects/NativeDependency/NativeDependency.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.Data.SQLite" Version="1.0.113.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
37 changes: 37 additions & 0 deletions
37
test/TestProjects/NativeDependency/NativeDependencyLoader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.IO; | ||
using System.Data.SQLite; | ||
|
||
namespace NativeDependency | ||
{ | ||
public static class NativeDependencyLoader | ||
{ | ||
public static void Load() | ||
{ | ||
using var tempFile = new TempFile("db.sqlite"); | ||
using var dbConnection = new SQLiteConnection($"Data Source={tempFile.FilePath}"); | ||
|
||
dbConnection.Open(); | ||
} | ||
} | ||
|
||
public class TempFile : IDisposable | ||
{ | ||
public TempFile(string fileName) | ||
{ | ||
FilePath = Path.Combine(Path.GetTempPath(), fileName); | ||
} | ||
|
||
public string FilePath { get; } | ||
|
||
public void Dispose() | ||
{ | ||
if (!File.Exists(FilePath)) | ||
{ | ||
return; | ||
} | ||
|
||
File.Delete(FilePath); | ||
} | ||
} | ||
} |