I have embedded my C# DLL into my C++ application according to the documentation on http://www.mono-project.com/docs/advanced/embedding/.
On my build machine I run a different mono version than on the machine were the application is running.
I am wondering if the whole runtime is compiled into the executable or if this is just a wrapper to the installed runtime.
Is it save to use different versions of mono on the compile machine and on the runtime machine?
Related
I have an 64-bit application that uses a .NET DLL, and is returning an error from CoCreateInstance() saying "class not registered". (0x80040154)
Now, this has been running fine as a 32-bit application for a long time, and has no problem calling the .NET DLL, which gets registered as part of the installation, or on my development machine, gets registered as part of the build process. The recent conversion to 64-bit application has started causing this error (the rest of the application is now running fine as 64-bit, so no other issues there).
The application is non-managed C++. The DLL is managed C#, .NET 2.0, and is set to "Any CPU". Both are built in VS2010. My install package uses Regasm to register the DLL, and I wondered if maybe I needed a 64-bit version of regasm, however, I believe I am already using that. Visual Studio is also set up to register the DLL as part of the build process, but even running the 64-bit program in the debugger still cannot find the class.
What do I need to do to register the DLL so that the 64-bit version of the program can find the DLL through CoCreateInstance()?
Probably your installer uses 32 bit regasm from:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe
But it should use 64 bit regasm:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe
I have a few questions about Mono:
1) Is there a way to compile application for Linux without installation of Xamarin Studio?
For example i have my helloworld.cs, i use dmcs to compile it into exe. Is there another compiler or flag to compile app for linux?
2) I need to statically link Mono runtime to run on the computer without Mono installed.
There is mkbundle command but it is a very difficult process to make it work on Windows. And static linking does not work on Windows.
And besides, I need to automate these processes =/
P.S. As I said, I'm working on Windows.
1) It doesn't matter if you compile your code with the Microsoft or Mono compiler, the resulting assembly should work on all platforms (as long as you don't use any platform-specific code of course).
You can take an assembly compiled with the MS compiler and run it on Linux/Mac with Mono, or compile on Mono and run it on Windows/.NET.
2) Problems with mkbundle should probably be filed as a bug on https://bugzilla.xamarin.com
I'm attempting to use a CAN device over USB that comes with a native DLL that needs to be wrapped by a .NET C# class (source code provided by the vendor) that gets included in one's project. Their sample applications target .NET 2.0 where my application targets .NET 4.0. I'm able to use the code in their sample apps and debug everything just fine, however, when I try to debug my application, I get a BadImageFormatException:
System.TypeInitializationException: The type initializer for 'TotalPhase.KomodoApi' threw an exception. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
The only differences between their code and mine appears to be that their code is an application built for .NET 2.0 and (currently) my code is running as an MSTest unit test in .NET 4.0. Both solutions target AnyCPU. I'm running on a Windows 7 Ultimate 64-bit install. Even changing from AnyCPU to x86 didn't make any difference. How can I get this native DLL to load in an AnyCPU project?
If you get a BadImageFormatException when interfacing with a native DLL, it almost always means that you are trying to interface with a 32-bit DLL while running in the 64-bit CLR, or vice versa.
When you run the sample applications, do the processes have *32 in the "Image Name" column of Task Manager's "Processes" tab? That indicates the applications are running in the 32-bit CLR. Check your own application as well. It is possible that the machine you are testing on only has a 32-bit .NET 2.0 runtime, but both 32-bit and 64-bit .NET 4.0 runtimes, or the other way around.
If you are distributing a native DLL with your .NET application, then you should set your startup project to target x86 or x64 (as opposed to AnyCPU), depending on whether the native libraries are 32-bit or 64-bit. You can always ship both 32-bit and 64-bit versions, and let the installer choose which binaries to install based on the client architecture.
Alternatively, you can ship both 32-bit and 64-bit DLLs with different file names, define separate P/Invoke stubs for each version, and decide which one to call at runtime. The easiest way to do this would probably be to wrap your native calls in an interface (e.g., INativeMethods) and choose which implementation to instantiate at runtime based on IntPtr.Size. With this method, you could still target AnyCPU.
I've written a C++/CLI DLL to be used with my GUI .NET application. On my local development machine, everything works as expected. My GUI application says that it cannot load my C++/CLI DLL on any other machine, though. It always says that it cannot load my DLL or one of its' dependencies. So I was thinking maybe it's some missing C runtime or something?
Are there any prerequisites that need to be installed prior to using my C++/CLI DLL on another machine? Strictly from a .NET perspective, or C++ run-time, or whatever.
Edit: Sorry. It's VS2012, .NET 4.0, Platform Toolset v110.
In addition to the dependencies that other .Net languages have (e.g., the .Net framework), C++/CLI requires the C++ runtime.
You can download the C++ runtime redistributable for VS 2012 from Microsoft. Select the x86 or x64 version based on the compilation setting of your C++/CLI assembly, not the version of Windows the target machine is running.
Note that this is the runtime for Release compiles only. Debug compiles use a different runtime, which does not have a redistributable, and is only installed with Visual Studio.
I wrote windows application with C# and SQLite. When Microsoft Visual C++ 2010 Redistributable Package x86 was installed on a PC application runs correctly but if Microsoft Visual C++ 2010 Redistributable Package x86 not install, application doesn't run. Why?
Is SQLite depend on Microsoft Visual C++ 2010 Redistributable Package x86 ?
The version of SQLite is compiled by VS2010, and it depends on the C runtime libaries, thus it needs Visual C++ 2010 Redistributable Package x86.
Yes. SQLite is probably written in C++. It's compiled with /MD option which means it needs the msvcrt#.dlls at runtime. The Restributable Package installs this without which it cannot run
Because SQLite obviously developed the SQLite.Interop.dll in C++, and because they say so:
(11) Why do I get a DllNotFoundException (for "sqlite3.dll" or "SQLite.Interop.dll") when trying to run my application?
Either the named dynamic link library (DLL) cannot be located or it cannot be loaded due to missing dependencies. Make sure the named dynamic link library is located in the application directory or a directory along the system PATH and try again. Also, be sure the necessary Visual C++ runtime redistributable has been installed unless you are using a dynamic link library that was built statically linked to it.
Emphasis mine on that last part. You need the static binaries from the system.data.sqlite download page in order to NOT need the C++ runtime. On that same page, where the binaries are provided, those that do require it will tell you it is - for example, the Visual C++ 2010 SP1 runtime for x64 is required for 4.0, and Update 4 of that is needed for .NET 4.5, according to the page. I've used the 2015 version, Update 3, with the .NET 4.0 versions with no issues.
Note - you might not be aware, but if you try hosting an application that uses the SQLite DLLs on a file share and connect to that application across the network from a workstation, that workstation will still need the C++ runtime because it is running the application in its memory.
Reference: http://system.data.sqlite.org/index.html/doc/trunk/www/faq.wiki#q11
Link to Microsoft Visual C++ 2015 Redistributable Update 3, which I know works with the 64-bit, .NET 4.0 versions of the SQLite binaries:
https://www.microsoft.com/en-us/download/details.aspx?id=53840
SQLite depends on the Visual C++ runtime, but you don't need to install it on the client machine. The system.data.sqlite download page contains several "static" packages that already contain the runtime.
All the "static" packages contain either native or mixed-mode assembly binaries linked statically to the appropriate version of the Visual C++ runtime. Typically, these packages are used in cases where customer machines may not have the necessary version of the Visual C++ runtime installed and it cannot be installed due to limited privileges.
For example, on my machine I am running Windows 8.1 x64 so I went under Precompiled Statically-Linked Binaries for 64-bit Windows (.NET Framework 4.0) and downloaded sqlite-netFx40-static-binary-x64-2010-1.0.90.0.zip.
This binary package contains all the binaries for the x64 version of the System.Data.SQLite 1.0.90.0 (3.8.2) package. The Visual C++ 2010 SP1 runtime for x64 is statically linked. The .NET Framework 4.0 is required.
I then unzipped the package and ran test.exe to make sure everything works. Zero installation required.