Repro:
Log:
BEGIN EXECUTION
/Users/fanyang/Documents/work/dotnet_test/runtime/artifacts/tests/coreclr/OSX.x64.Debug/Tests/Core_Root/corerun NativeLibraryTests.dll ''
Unhandled exception System.DllNotFoundException: /Users/fanyang/Documents/work/dotnet_test/runtime/artifacts/tests/coreclr/OSX.x64.Debug/Interop/NativeLibrary/API/NativeLibraryTests/notfound
at System.String.Format(String format, Object arg0, Object arg1) in /Users/fanyang/Documents/work/dotnet_test/runtime/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs:line 475
at NativeLibraryTest.EXPECT(TestResult actualValue, TestResult expectedValue) in /Users/fanyang/Documents/work/dotnet_test/runtime/src/coreclr/tests/src/Interop/NativeLibrary/API/NativeLibraryTests.cs:line 206
at NativeLibraryTest.Main() in /Users/fanyang/Documents/work/dotnet_test/runtime/src/coreclr/tests/src/Interop/NativeLibrary/API/NativeLibraryTests.cs:line 78
Expected: 100
Actual: 156
END EXECUTION - FAILED
/cc @CoffeeFlux
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
Tagging subscribers to this area: @CoffeeFlux
Notify danmosemsft if you want to be subscribed.
@fanyang-mono Just confirming, this is failing only on the Interpreter and not JIT runs?
/cc @BrzVlad @CoffeeFlux
@fanyang-mono Just confirming, this is failing only on the Interpreter and not JIT runs?
/cc @BrzVlad @CoffeeFlux
That is correct.
This failure is somewhat interesting, and likely a true interpreter bug. I tried last week to come up with a standalone repro and failed, but for a summary of what's happening:
On the line in question (below), we call LoadLibraryAdvanced. In that, we call NativeLibrary.Load from inside another function Run that is intended to catch a variety of exceptions, including DllNotFoundException (the one thrown here). For some reason, it isn't being caught and bubbles up to the top of the stack, where we throw an exception. This does not happen on JIT, and throwing a DllNotFoundException here is the intended behavior, but I'm not familiar enough with interpreter internals to easily identify what's going on there.
The bug doesn't seem urgent, since I found it difficult to trigger isolated from the testing setup, but it would be nice to know why this is failing. Exceptions mysteriously not getting caught is less than ideal.
Tagging subscribers to this area: @brzvlad, @lewurm
Notify danmosemsft if you want to be subscribed.
@danmosemsft can you turn off notifications for Bernhard? See https://github.com/mono/mono/pull/19895
@CoffeeFlux done
Simplified repro:
```using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
string assemblyDir = Path.GetDirectoryName(assembly.Location);
string libName = Path.Combine(assemblyDir, "notfound");
IntPtr handle = IntPtr.Zero;
try
{
handle = NativeLibrary.Load(libName, assembly, null);
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
NativeLibrary.Free(handle);
}
}
}
Follow-up to my previous comment:
Expected:
System.DllNotFoundException: /Users/fanyang/Documents/work/dotnet_latest/runtime/src/mono/netcore/sample/HelloWorld/bin/notfound
at System.Runtime.InteropServices.NativeLibrary.LoadLibraryByName(String libraryName, Assembly assembly, Nullable`1 searchPath, Boolean throwOnError) in /Users/fanyang/Documents/work/dotnet_latest/runtime/src/mono/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.Mono.cs:line 13
at System.Runtime.InteropServices.NativeLibrary.Load(String libraryName, Assembly assembly, Nullable`1 searchPath) in /Users/fanyang/Documents/work/dotnet_latest/runtime/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.cs:line 94
at HelloWorld.Program.Main(String[] args) in /Users/fanyang/Documents/work/dotnet_latest/runtime/src/mono/netcore/sample/HelloWorld/Program.cs:line 18 Exception caught.
Interpreter mode without fix:
Unhandled Exception:
System.DllNotFoundException: /Users/fanyang/Documents/work/dotnet_latest/runtime/src/mono/netcore/sample/HelloWorld/bin/notfound
at System.Runtime.InteropServices.NativeLibrary.Free(IntPtr handle) in /Users/fanyang/Documents/work/dotnet_latest/runtime/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.cs:line 148
at HelloWorld.Program.Main(String[] args) in /Users/fanyang/Documents/work/dotnet_latest/runtime/src/mono/netcore/sample/HelloWorld/Program.cs:line 24
[ERROR] FATAL UNHANDLED EXCEPTION: System.DllNotFoundException: /Users/fanyang/Documents/work/dotnet_latest/runtime/src/mono/netcore/sample/HelloWorld/bin/notfound
at System.Runtime.InteropServices.NativeLibrary.Free(IntPtr handle) in /Users/fanyang/Documents/work/dotnet_latest/runtime/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.cs:line 148
at HelloWorld.Program.Main(String[] args) in /Users/fanyang/Documents/work/dotnet_latest/runtime/src/mono/netcore/sample/HelloWorld/Program.cs:line 24
Basically, the problem is that when calling System.Runtime.InteropServices.NativeLibrary.LoadLibraryByName, a pending exception was created but wasn't thrown.
Most helpful comment
@CoffeeFlux done