Skip to content

Commit bf8f57e

Browse files
DigitalDiggerSnipx
authored andcommitted
Handle exceptions of Assembly.Location property
Assembly.CodeBase might contain UNC-compliant path starting with "file:///?/" that cause ArgumentException from Assembly.Location. The issue reproduces with edge_nativeclr.node in AppDomain which is a common problem DEVSIX-1390
1 parent a6146b4 commit bf8f57e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

itext/itext.io/itext/io/util/ResourceUtil.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,21 @@ private static Stream SearchResourceInAssembly(string key, Object obj) {
203203
private static void LoadITextResourceAssemblies() {
204204
#if !NETSTANDARD1_6
205205
var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().Where( a=> !a.IsDynamic).ToList();
206-
var loadedPaths = loadedAssemblies.Select(a => a.Location).ToArray();
207-
206+
List<string> loadedPaths = new List<string>();
207+
foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
208+
{
209+
try
210+
{
211+
var path = a.Location;
212+
loadedPaths.Add(path);
213+
}
214+
catch
215+
{
216+
// to skip exceptions for dynamically loaded assemblies without location
217+
// such as anonymously hosted dynamicmethods assembly for example
218+
}
219+
}
220+
208221
var referencedPaths = Directory.GetFiles(FileUtil.GetBaseDirectory(), "*.dll");
209222
var toLoad = referencedPaths.Where(referencePath => !loadedPaths.Any(loadedPath => loadedPath.Equals(referencePath, StringComparison.OrdinalIgnoreCase))).ToList();
210223
foreach (String path in toLoad)

0 commit comments

Comments
 (0)