Skip to content

Commit 80fae44

Browse files
authored
Remove dynamic loading of Garnet.resources.dll + Update version to 1.0.33 (#723)
* fix * format + update version * small fixes * format
1 parent 274d36e commit 80fae44

File tree

5 files changed

+24
-47
lines changed

5 files changed

+24
-47
lines changed

.azure/pipelines/azure-pipelines-external-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# 1) update the name: string below (line 6) -- this is the version for the nuget package (e.g. 1.0.0)
44
# 2) update \libs\host\GarnetServer.cs readonly string version (~line 32) -- NOTE - these two values need to be the same
55
######################################
6-
name: 1.0.32
6+
name: 1.0.33
77
trigger:
88
branches:
99
include:

libs/host/GarnetServer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace Garnet
2929
public class GarnetServer : IDisposable
3030
{
3131
// IMPORTANT: Keep the version in sync with .azure\pipelines\azure-pipelines-external-release.yml line ~6.
32-
readonly string version = "1.0.32";
32+
readonly string version = "1.0.33";
3333

3434
internal GarnetProvider Provider;
3535

libs/resources/Garnet.resources.csproj

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
5-
<ImplicitUsings>enable</ImplicitUsings>
6-
<Nullable>enable</Nullable>
4+
<SignAssembly>true</SignAssembly>
5+
<AssemblyOriginatorKeyFile>../../Garnet.snk</AssemblyOriginatorKeyFile>
6+
<DelaySign>false</DelaySign>
7+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
78
</PropertyGroup>
89

9-
<ItemGroup>
10-
<None Remove="RespCommandsDocs.json" />
11-
<None Remove="RespCommandsInfo.json" />
12-
</ItemGroup>
13-
1410
<ItemGroup>
1511
<EmbeddedResource Include="RespCommandsDocs.json" />
1612
<EmbeddedResource Include="RespCommandsInfo.json" />

libs/resources/ResourceUtils.cs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Garnet.resources
2+
{
3+
/// <summary>
4+
/// Dummy class for externally referencing this assembly
5+
/// </summary>
6+
public class ResourceUtils
7+
{
8+
}
9+
}
+9-37
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4-
using System;
54
using System.Collections.Generic;
6-
using System.IO;
7-
using System.Runtime.Loader;
5+
using System.Reflection;
86
using Garnet.common;
7+
using Garnet.resources;
98
using Microsoft.Extensions.Logging;
109

1110
namespace Garnet.server.Resp
1211
{
1312
internal class RespCommandDataCommon
1413
{
15-
/// <summary>
16-
/// Path to Garnet.resources.dll, where command data is found
17-
/// </summary>
18-
private static readonly string ResourcesAssemblyPath = Path.Combine(AppContext.BaseDirectory, @"Garnet.resources.dll");
19-
20-
/// <summary>
21-
/// Synchronize loading and unloading of resources assembly
22-
/// </summary>
23-
private static readonly object ResourcesAssemblyLock = new object();
24-
2514
/// <summary>
2615
/// Safely imports commands data from embedded resource in dynamically loaded/unloaded assembly
2716
/// </summary>
@@ -33,32 +22,15 @@ internal class RespCommandDataCommon
3322
internal static bool TryImportRespCommandsData<TData>(string path,
3423
out IReadOnlyDictionary<string, TData> commandsData, ILogger logger = null) where TData : class, IRespCommandData<TData>
3524
{
36-
lock (ResourcesAssemblyLock)
37-
{
38-
// Create a new unloadable assembly load context
39-
var assemblyLoadContext = new AssemblyLoadContext(null, true);
40-
41-
try
42-
{
43-
// Load the assembly within the context and import the data
44-
var assembly = assemblyLoadContext.LoadFromAssemblyPath(ResourcesAssemblyPath);
45-
46-
var streamProvider = StreamProviderFactory.GetStreamProvider(FileLocationType.EmbeddedResource, null, assembly);
47-
var commandsDocsProvider = RespCommandsDataProviderFactory.GetRespCommandsDataProvider<TData>();
25+
// Garnet.resources assembly, where command data is found
26+
var resourcesAssembly = Assembly.GetAssembly(typeof(ResourceUtils));
4827

49-
return commandsDocsProvider.TryImportRespCommandsData(path,
50-
streamProvider, out commandsData, logger);
51-
}
52-
finally
53-
{
54-
// Unload the context
55-
assemblyLoadContext.Unload();
28+
var streamProvider =
29+
StreamProviderFactory.GetStreamProvider(FileLocationType.EmbeddedResource, null, resourcesAssembly);
30+
var commandsDocsProvider = RespCommandsDataProviderFactory.GetRespCommandsDataProvider<TData>();
5631

57-
// Force GC to release the loaded assembly
58-
GC.Collect();
59-
GC.WaitForPendingFinalizers();
60-
}
61-
}
32+
return commandsDocsProvider.TryImportRespCommandsData(path,
33+
streamProvider, out commandsData, logger);
6234
}
6335
}
6436
}

0 commit comments

Comments
 (0)