[Mono-dev] File not found error when using Activator.CreateInstanceFrom()
mike
mguman at knology.net
Thu Dec 23 12:33:53 EST 2010
Ok, rewrote to use p/Invoke with a true native DLL (extern C, no name
mangling here, Jon) and it appears that I am back to *square one* with the
'File not found exception'.
If I p/Invoke to a single native dll, all is fine. However if that dll
depends on a secondary native dll, I get an "unhandled exception:
System.DLLNotFoundException". Again, this scenario works fine under .NET,
fails under 2.8
The issue seems to be related to p/Invoking a dynamic link library which
depends on a second native dll.
Here is a tiny example of all codes involved which may help highlight the
issue. Note the native dlls are in a sub-folder 'native' to the driver's
executing app path.
--------------------------------------------------------------------------
First DLL (Test_Native.dll) source :
//------------
// MyLib.h
//------------
#pragma once
extern "C" {
_declspec(dllexport) void Test();
}
//----------
//MyLib.cpp
//----------
#include <iostream>
#include <stdio.h>
#include <exception>
#include "MyLib.h"
#include "MyEnviron.h"
using namespace std;
void Test()
{
foo();
printf("ok.");
}
Second DLL (Environ.dll) Source:
//-------------------
//MyEnviron.h
//-------------------
extern "C" { __declspec(dllexport) void foo(); }
//-------------------
//MyEnviron.cpp
//-------------------
#include <iostream>
#include <stdio.h>
#include <exception>
#include "MyEnviron.h"
using namespace std;
void foo()
{
printf("dyn ok.");
}
// Test C# driver
//
//------------------
using System;
using System.Runtime.InteropServices;
using System.IO;
namespace PInvoke_Test
{
class MainClass
{
public static void Main (string[] args)
{
_Test();
}
// Test Method
[DllImport("Native\\Test_Native.dll",
EntryPoint = "Test",
ExactSpelling = false,
CallingConvention = CallingConvention.StdCall)]
static extern void _Test();
}
}
--
View this message in context: http://mono.1490590.n4.nabble.com/File-not-found-error-when-using-Activator-CreateInstanceFrom-tp3064104p3162360.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
More information about the Mono-devel-list
mailing list