Re: [Mono-dev] File not found error when using Activator.CreateInstanceFrom()

2011-01-19 Thread Jonathan Pryor
On Jan 18, 2011, at 4:52 PM, mike wrote:
 Hey Jonathan P,  I noticed that u wrote the 'Interop with Native Libraries'
 article on the mono web site. Very good stuff. I have a question, can mono
 link or inter op to a Linux static library instead of a shared object? (i.e
 mylib.a)

_Maybe_. :-)

This won't work:

[DllImport (mylib.a)]
static extern void Foo();

That won't work because dlopen(3) is used to load the specified library, and 
dlopen(mylib.a) will fail.

HOWEVER, if you're using the Mono embedding API, write a native app, and link 
your native app to mylib.a:

gcc -o yourapp yourapp.c mylib.a `pkg-config --cflags mono-2` ...

Then you can do:

[DllImport (__Internal)
static extern void Foo();

See also:

http://www.mono-project.com/DllImport#Linux_Shared_Library_Search_Path

http://www.mono-project.com/Embedding_Mono#Exposing_C_code_to_the_CIL_universe

 - Jon

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] File not found error when using Activator.CreateInstanceFrom()

2011-01-18 Thread mike

Hey Jonathan P,  I noticed that u wrote the 'Interop with Native Libraries'
article on the mono web site. Very good stuff. I have a question, can mono
link or inter op to a Linux static library instead of a shared object? (i.e
mylib.a)
-- 
View this message in context: 
http://mono.1490590.n4.nabble.com/File-not-found-error-when-using-Activator-CreateInstanceFrom-tp3064104p3224082.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] File not found error when using Activator.CreateInstanceFrom()

2011-01-17 Thread mike


Hey John, thanks for the reply. I was compiling the c# test app and test
dlls above from within Visual Studio 2005, taking default options. Options
listed below, although seems this is OBE for you now

The PATH variable was one of the first things that I checked when I first
ran into this issue. Setting this does indeed work for my small sample
application yet does *not* work for my 'real' application, which is more
complex. It performs the PInvokefrom a plug-in assembly which was loaded via
@Assembly.LoadFrom(). Maybe this is confusing win mono. Unfortunately, I
cannot post detailed code of the real application. I'll have to gin up
another 'test' example. I'll try to post a zip with new sample (see below).
I ran into issues posting attachments to this board. 

I had also hoped that the path specified by the DllImport() call would
suffice for the dependent dll to be found. Seems to work this way running
under .NET so why is this not working under mono 2.8? Wonder what exactly
the difference is between the two??

---
The MSVS 2005 command line compile options for the C++ dlls are:  

Environ.dll:
/O2 /D _WINDLL /GF /FD /EHsc /MD /Gy /Fo.\Release/ /Fd.\Release/
/nologo /c /TP /errorReport:prompt

Test_Native.dll:
/O2 /Ob1 /I ..\Environ /D WIN32 /D NDEBUG /D _WINDOWS /D _USRDLL
/D 

ENVIRONMENT_EXPORTS /D _CRT_SECURE_NO_DEPRECATE /D _WINDLL /D _MBCS 

/GF /FD /MD /Gy /FoDebug\\ /FdDebug\vc80.pdb /W3 /nologo /c /TP 

/errorReport:prompt

The MSVS linker command line options are: 

Test_Native.dll:
/OUT:..\Release/Test_Native.dll /INCREMENTAL:NO /NOLOGO /LIBPATH:..

\release /DLL /MANIFEST /MANIFESTFILE:Debug

\Test_Native.dll.intermediate.manifest /ERRORREPORT:PROMPT Environ.lib  

kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib 

shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

environ.dll:
/OUT:..\Release/Environ.dll /NOLOGO /DLL /MANIFEST
/MANIFESTFILE:.\Release\Environ.dll.intermediate.manifest
/ERRORREPORT:PROMPT kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib
odbc32.lib odbccp32.lib



-- 
View this message in context: 
http://mono.1490590.n4.nabble.com/File-not-found-error-when-using-Activator-CreateInstanceFrom-tp3064104p3221233.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] File not found error when using Activator.CreateInstanceFrom()

2011-01-17 Thread mike

Update:  In putting together the sample code for the above, I was able to
finally get past this error by setting the PATH variable for *every* sub
directory path required in the search path. For some reason, this was not
required while running under .NET. 

example:  set PATH=%PATH%;c:\!test\plug;c:\!test\plug\native
-- 
View this message in context: 
http://mono.1490590.n4.nabble.com/File-not-found-error-when-using-Activator-CreateInstanceFrom-tp3064104p3221251.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] File not found error when using Activator.CreateInstanceFrom()

2011-01-07 Thread Jonathan Pryor
On Jan 6, 2011, at 5:13 PM, mike wrote:
 Thanks for the reply. Not sure what you mean as I'm not doing a
 LoadLibrary().

Yes, you are: it's implicit to P/Invoke.  (OK, so .NET is doing it on your 
behalf under the covers, but a LoadLibrary() is still occurring.)

Since you're on Windows, LD_LIBRARY_PATH has no effect (that's a Unix 
environment variable).  Setting PATH might help; see:

http://mono-project.com/DllImport#Windows_DLL_Search_Path

 Compile the sample code(s) above in this post for an example
 of how to produce the error.

The fundamental problem is that your example is still incomplete.  Providing a 
.zip may be more appropriate, but the fundamental question is this:  how 
_exactly_ you're compiling your native libraries?

For example, when I extract your source files from the relevant email and 
compile like this:

CL /c MyEnviron.cpp
LINK /DLL /OUT:Native\Environ.dll MyEnviron.obj

CL /c MyLib.cpp
LINK /DLL /OUT:Native\Test_Native.dll MyLib.obj Native\Environ.lib

CSC app.cs /platform:x86

The above allows your code to work, but it took me an hour to re-learn enough 
CL+LINK to make it work.  (My first effort at `CL /LD /FoNative\Test_Native.dll 
MyLib.cpp` failed horribly, for reasons I can't fathom.  Thanks, Microsoft!)  
I'm not sure why this would be failing under Mono, so that does appear to be a 
bug.

However, a workaround for mono is to place the .DLL files into the same 
directory as your .EXE, instead of into a Native sub-directory.  (At least, 
this works for me.)

Furthermore, your C# code appears wrong (or you're doing something different 
when compiling your native libraries).  Specifically:

// Test Method
[DllImport(Native\\Test_Native.dll,
EntryPoint = Test,
ExactSpelling = false,
CallingConvention = CallingConvention.StdCall)]
static extern void _Test(); 

Test_Native.dll!Test() will default to Cdecl calling convention, not StdCall, 
so your calling convention is wrong.  This often won't immediately break things 
(as .NET will occasionally detect the stack mismatch and fix it), but it can 
break things, and thus should be fixed.  I'm also not sure why you're setting 
ExactSpelling at all.

 - Jon

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] File not found error when using Activator.CreateInstanceFrom()

2011-01-06 Thread nekresh
On Wed, Jan 5, 2011 at 8:04 PM, mike mgu...@knology.net wrote:

 Not sure what you mean.  Actually, I was just refreshing the thread.  ;-)

 See previous post and example code, 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 (under win mono)

 The issue seems to be related to p/Invoking a dynamic link library which
 depends on a second native dll.


Have you checked your LD_LIBRARY_PATH environment variable ?
In order to find a native library in the current folder, the
LD_LIBRARY_PATH must contain . or the full path to your application's
folder.
This vary from windows which is searching in the application's base
folder first (see Remarks in
http://msdn.microsoft.com/en-us/library/ms684175(v=vs.85).aspx)
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] File not found error when using Activator.CreateInstanceFrom()

2011-01-06 Thread mike

Thanks for the reply. Not sure what you mean as I'm not doing a
LoadLibrary(). Compile the sample code(s) above in this post for an example
of how to produce the error. Note that the sample runs fine under the  .NET
2.0 CLR on Windows and fails under mono 2.9 under Windows. 

I tried setting the LD_LIBRARY_PATH as you suggested anyway and that did not
work. 
-- 
View this message in context: 
http://mono.1490590.n4.nabble.com/File-not-found-error-when-using-Activator-CreateInstanceFrom-tp3064104p3178277.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] File not found error when using Activator.CreateInstanceFrom()

2011-01-05 Thread mike

Anybody else see this while using P/Invoke under mono?
-- 
View this message in context: 
http://mono.1490590.n4.nabble.com/File-not-found-error-when-using-Activator-CreateInstanceFrom-tp3064104p3175616.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] File not found error when using Activator.CreateInstanceFrom()

2011-01-05 Thread Robert Jordan
On 05.01.2011 15:25, mike wrote:

 Anybody else see this while using P/Invoke under mono?

They do not even relate, so no one else will see this ;)

Please explain what you're trying to do.

Robert

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] File not found error when using Activator.CreateInstanceFrom()

2011-01-05 Thread Tom Spink
Are you still talking about Windows-only here?

-- Spink

On 5 January 2011 14:25, mike mgu...@knology.net wrote:

 Anybody else see this while using P/Invoke under mono?
 --
 View this message in context: 
 http://mono.1490590.n4.nabble.com/File-not-found-error-when-using-Activator-CreateInstanceFrom-tp3064104p3175616.html
 Sent from the Mono - Dev mailing list archive at Nabble.com.
 ___
 Mono-devel-list mailing list
 Mono-devel-list@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-devel-list




-- 
Tom Spink
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] File not found error when using Activator.CreateInstanceFrom()

2011-01-05 Thread mike

Not sure what you mean.  Actually, I was just refreshing the thread.  ;-)

See previous post and example code, 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 (under win mono) 

The issue seems to be related to p/Invoking a dynamic link library which
depends on a second native dll. 

-- 
View this message in context: 
http://mono.1490590.n4.nabble.com/File-not-found-error-when-using-Activator-CreateInstanceFrom-tp3064104p3176193.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] File not found error when using Activator.CreateInstanceFrom()

2010-12-24 Thread mike

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.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] File not found error when using Activator.CreateInstanceFrom()

2010-12-21 Thread mike

Very interesting Jon, I will look into this. Thanks again for your
assistance.
-- 
View this message in context: 
http://mono.1490590.n4.nabble.com/File-not-found-error-when-using-Activator-CreateInstanceFrom-tp3064104p3153343.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] File not found error when using Activator.CreateInstanceFrom()

2010-12-21 Thread mike

For readers of this thread, a good link on mixed (native and managed code)
assemblies can be found here) 
http://msdn.microsoft.com/en-us/library/x0w2664k%28v=vs.80%29.aspx

-- 
View this message in context: 
http://mono.1490590.n4.nabble.com/File-not-found-error-when-using-Activator-CreateInstanceFrom-tp3064104p3155361.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] File not found error when using Activator.CreateInstanceFrom()

2010-12-20 Thread mike

Right Jon, it is a mixed mode C++/CLI assembly and I am trying to create an
instance of a managed C++ object within, which in turn, accesses the legacy
'native' C++ code (which is also within this assembly).

Original problem on this thread was the 'file not found error'.  Since
another dll was referenced to this one, I simply thought the 'file not found
error' was due to a path problem, so I statically linked it into the main
assembly. Thats when I got this 'type not implemented..' error.

Thanks for the help, good suggestion on the clr pure option, I will review
the code 2morrow to see if I can try that...hope this works...if not, guess
I'll be redesigning a few thingies to use P/Invoke.  For some reason, I
thought we chose this CreateInstance() approach over the P/Invoke for
performance reasons.  The P/Invoke does work fine as I currently use it in
another part of the application to interface to some FORTRAN dlls.
-- 
View this message in context: 
http://mono.1490590.n4.nabble.com/File-not-found-error-when-using-Activator-CreateInstanceFrom-tp3064104p3094875.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] File not found error when using Activator.CreateInstanceFrom()

2010-12-20 Thread Jonathan Pryor
On Dec 19, 2010, at 4:57 PM, mike wrote:
 For some reason, I
 thought we chose this CreateInstance() approach over the P/Invoke for
 performance reasons.

If you have concerns about P/Invoke performance, you might consider looking 
into the System.Security.SuppressUnmanagedCodeSecurityAttribute attribute:


http://msdn.microsoft.com/en-us/library/system.security.suppressunmanagedcodesecurityattribute.aspx

This can help speed up P/Invoke performance by disabling security-related stack 
walks on .NET.  On Mono I *believe* this won't have an effect, as CAS is 
disabled by default (as it isn't supported).

 - Jon

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] File not found error when using Activator.CreateInstanceFrom()

2010-12-17 Thread Jonathan Pryor
On Dec 16, 2010, at 3:24 PM, mike wrote:
 Thanks for the reply. Here is an example attached driver (test.cs) which
 calls the Activator.CreateInstanceFrom(). Runs fine under NET 2.0 but bombs
 under mono 2.8 with the 'implement type compare for 1b!' error message. You
 will need to construct asmall native C++ dll with a matching class name and
 constructor to call. 

On .NET, you're _not_ invoking a native C++ DLL, you're invoking a C++/CLI 
DLL. (It must be this way, as a normal native C++ DLL will use tons of 
compiler-specific name mangling for the types and namespaces, so 
mycplusplusnamespace.mycplusplusclass has no chance of working, ever, on any 
platform, unless the runtime directly supports native C++ code, which would 
likely make it specific to a particular C++ compiler, thus somewhat defeating 
the point of the CLR...)

Mono does NOT support C++/CLI assemblies, hence the error you see.

In short, Don't Do That, avoid C++/CLI and use P/Invoke instead if you want to 
run on Mono under any platform other than Windows.

(Or, compile your C++/CLI assembly with /clr:pure so that it isn't a mixed-mode 
assembly and instead consists solely of IL.  How practical this is depends upon 
your code.)

 - Jon

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] File not found error when using Activator.CreateInstanceFrom()

2010-12-16 Thread mike

Thanks for the reply. Here is an example attached driver (test.cs) which
calls the Activator.CreateInstanceFrom(). Runs fine under NET 2.0 but bombs
under mono 2.8 with the 'implement type compare for 1b!' error message. You
will need to construct asmall native C++ dll with a matching class name and
constructor to call. 
http://mono.1490590.n4.nabble.com/file/n3091579/test.cs test.cs  





-- 
View this message in context: 
http://mono.1490590.n4.nabble.com/File-not-found-error-when-using-Activator-CreateInstanceFrom-tp3064104p3091579.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] File not found error when using Activator.CreateInstanceFrom()

2010-12-08 Thread mike

Update: Code runs fine under .NET 2.0.  

Also tried statically linking the second .dll to the first which alleviated
the 'file not found' exception, however I am now getting a implement type
compare for 1b! message and mono crashes!

Has anyone seen this!??
-- 
View this message in context: 
http://mono.1490590.n4.nabble.com/File-not-found-error-when-using-Activator-CreateInstanceFrom-tp3064104p3078315.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] File not found error when using Activator.CreateInstanceFrom()

2010-12-08 Thread Rodrigo Kumpera
On Wed, Dec 8, 2010 at 12:39 PM, mike mgu...@knology.net wrote:


 Update: Code runs fine under .NET 2.0.

 Also tried statically linking the second .dll to the first which alleviated
 the 'file not found' exception, however I am now getting a implement type
 compare for 1b! message and mono crashes!

 Has anyone seen this!??


This is a bug on mono, can you provide a test case that shows this problem
and
file a bug report?

Thanks,
Rodrigo
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list