attempting to implement an inaccessible interface
BackT0TheFuture opened this issue · 2 comments
BackT0TheFuture commented
Please provide a minimal compilable example of
just a simple native code
typedef void(*ActionCallback)();
__declspec(dllexport) void RunCallback(ActionCallback callback)
{
callback();
}
using System;
namespace Invoker
{
using AdvancedDLSupport;
class Program
{
public delegate void ActionCallback();
public interface ITest
{
void RunCallback(ActionCallback callback);
}
static void Main(string[] args)
{
const string MyLibraryName = "native.dll";
var library = NativeLibraryBuilder.Default.ActivateInterface<ITest>(MyLibraryName);
library.RunCallback(() => Console.WriteLine("Callback ran!"));
}
}
}
dotnet Invoker.dll
Unhandled Exception: System.TypeLoadException: Type 'Generated_NativeLibraryBase
_a6553129_a2dc_4c8c_a872_7c2dc3c740bd' from assembly 'DLSupportDynamicAssembly,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is attempting to implemen
t an inaccessible interface.
at System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule module, I
nt32 tk, ObjectHandleOnStack type)
at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
at System.Reflection.Emit.TypeBuilder.CreateTypeInfo()
at AdvancedDLSupport.NativeLibraryBuilder.ActivateClass(String libraryPath, T
ype baseClassType, Type[] interfaceTypes)
at AdvancedDLSupport.NativeLibraryBuilder.ActivateClass[TClass,TInterface](St
ring libraryPath)
at AdvancedDLSupport.NativeLibraryBuilder.ActivateInterface[TInterface](Strin
g libraryPath)
at Invoker.Program.Main(String[] args) in d:\Invoker\Program.cs:line 26
Desktop (please complete the following information):
- OS: windows 8.1 64bit
- Runtime .NET Core
- Version 2.2
Additional context
Add any other context about the problem here.
Nihlus commented
Your interface is nested inside a private class. It is not accessible to ADL. Move it outside of the class, or make the class public.
BackT0TheFuture commented
my bad, thanks!