Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

FixedFileLoadException when tryingclr.AddReference('/full/path.dll')#1573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
lostmsu merged 1 commit intopythonnet:masterfromlosttech:add-ref-fullpath
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletionssrc/embed_tests/pyimport.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
using System;
using System.IO;
using System.Runtime.InteropServices;

using NUnit.Framework;
using Python.Runtime;

Expand DownExpand Up@@ -83,10 +85,18 @@ public void TestCastGlobalVar()
public void BadAssembly()
{
string path;
if (Python.Runtime.Runtime.IsWindows)
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
path = @"C:\Windows\System32\kernel32.dll";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
path = "/usr/lib/libc.dylib";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
path = "/usr/lib/locale/locale-archive";
}
else
{
Assert.Pass("TODO: add bad assembly location for other platforms");
Expand All@@ -98,7 +108,7 @@ import clr
clr.AddReference('{path}')
";

Assert.Throws<FileLoadException>(() => PythonEngine.Exec(code));
Assert.Throws<BadImageFormatException>(() => PythonEngine.Exec(code));
}
}
}
25 changes: 15 additions & 10 deletionssrc/runtime/assemblymanager.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -121,6 +121,18 @@ private static Assembly ResolveHandler(object ob, ResolveEventArgs args)
return LoadAssemblyPath(name.Name);
}

internal static AssemblyName? TryParseAssemblyName(string name)
{
try
{
return new AssemblyName(name);
}
catch (FileLoadException)
{
return null;
}
}


/// <summary>
/// We __really__ want to avoid using Python objects or APIs when
Expand DownExpand Up@@ -208,18 +220,11 @@ static IEnumerable<string> FindAssemblyCandidates(string name)

/// <summary>
/// Loads an assembly from the application directory or the GAC
/// givena simple assembly name. Returns the assembly if loaded.
/// givenits name. Returns the assembly if loaded.
/// </summary>
public static Assembly LoadAssembly(string name)
public static Assembly LoadAssembly(AssemblyName name)
{
try
{
return Assembly.Load(name);
}
catch (FileNotFoundException)
{
return null;
}
return Assembly.Load(name);
}


Expand Down
4 changes: 2 additions & 2 deletionssrc/runtime/moduleobject.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -516,9 +516,9 @@ public static Assembly AddReference(string name)
{
assembly = AssemblyManager.LoadAssemblyPath(name);
}
if (assembly == null)
if (assembly == null && AssemblyManager.TryParseAssemblyName(name) is { } parsedName)
{
assembly = AssemblyManager.LoadAssembly(name);
assembly = AssemblyManager.LoadAssembly(parsedName);
}
if (assembly == null)
{
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp