How to load managed DLL in c++? - c#

I try use this tutorial to create in C# DLL and use it in C++, but example don't work.
Always getting error:
"An unhandled exception of type
'System.Runtime.InteropServices.SEHException' occurred in
CPPClient.exe Additional information: External component has thrown an
exception."
Now my question is: How to right load managed DLL in c++? (links, tutorials, advice in that field will be appreciate)

Related

Getting ModuleLoadException (C++ Modules) and TypeLoadException from WindowsBase.DLL ONLY when attempting to use the System.Windows.Clipboard class?

I am running a C# WinForms app. The goal of this small section of code is to copy the contents of a .JMP file into a .csv file for data manipulation. Easy enough right? I do not want to do this all in JMP or using a .jsl. The code for parsing and reformatting the data is already there for .csv files and has been working flawlessly.
The app that runs fine unless I have this one specific line that accesses the System.Windows.Clipboard class in my code:
Clipboard.SetDataObject(my data);
When I run the code with the line commented out all is well, but when I run them with the line included the app immediately goes into breakmode with these exceptions:
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for '<Module>' threw an exception.
Source=<Cannot evaluate the exception source>
StackTrace: Cannot evaluate the exception stack trace
Inner Exception 1:
ModuleLoadException: The C++ module failed to load during appdomain initialization.
Inner Exception 2:
TypeLoadException: Could not load type 'System.Windows.Media.DisableDpiAwarenessAttribute' from assembly 'WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
For Inner Exception 1, I am confused because this is a C# app in WinForms with no C++, don't know what the deal is here.
For Inner Exception 2, I am confused because the Assembly WindowsBase is for WPF and not WinForms. I am unable to even add a project reference to this WindowsBase assembly. Again, these errors only happen when I try to do anything with the System.Windows.Clipboard class.
I have downloaded, installed, and ensured the proper location of the following DLLs:
1. PresentationCore.dll
2. System.Windows.Forms.dll
Am I still missing some DLLs? Any help is appreciated.
You should use System.Windows.Forms.Clipboard instead of System.Windows.Clipboard, for the latter one is from WPF. You should remove the reference to PresentationCore.dll, because it's from WPF and not needed in WinForm.

UnityContainer.Resolve crashes when .NET Native tool chain is enabled

We have a Windows 10 UWP app that runs fine under Debug builds and crashes under Release builds. What it is about release builds that makes it crash is that .NET Native tools chain is enabled - disabling that allows the app to run. But that's not a real fix as it needs to run with .NET Native tool chain if you intend to publish to the store.
We use Microsoft.Practices.Unity for DI. Here's an example of how we register some classes:
container.RegisterType<IBoardView, BoardView>();
And then, in our app we resolve it as follows:
container.Resolve<IBoardView>();
It works fine unless I run it with .NET Native, in which case I get the following exception:
An exception of type 'Microsoft.Practices.Unity.ResolutionFailedException' occurred in Microsoft.Practices.Unity.dll but was not handled in user code
Additional information: Resolution of the dependency failed, type = "WindowsUniversal.ViewModels.Interfaces.IBoardViewModel", name = "(none)".
Exception occurred while: while resolving.
And in the output window I get:
Exception thrown: 'System.NullReferenceException' in System.Linq.Expressions.dll
Exception thrown: 'System.NullReferenceException' in Microsoft.Practices.Unity.dll
Exception thrown: 'Microsoft.Practices.Unity.ResolutionFailedException' in Microsoft.Practices.Unity.dll
An exception of type 'Microsoft.Practices.Unity.ResolutionFailedException' occurred in Microsoft.Practices.Unity.dll but was not handled in user code
Additional information: Resolution of the dependency failed, type = "WindowsUniversal.ViewModels.Interfaces.IBoardViewModel", name = "(none)".
Exception occurred while: while resolving.
Exception is: NullReferenceException - Object reference not set to an instance of an object.
At the time of the exception, the container was:
Resolving WindowsUniversal.ViewModels.Interfaces.IBoardViewModel,(none)
All this works under Debug or Release when .NET Native is disabled. Now I know .NET Native has it's limitations, reflection being one of them. I guess I'm asking how to get around this?
Any insights would be greatly appreciated, thanks.

C# - Using external CLR DLL

I'm trying to use an external library with my code. I have added it as a reference from within Visual Studio and things like auto-complete works fine, I can see all the available methods while typing code. It also compiles without any warning or errors.
The DLL is within the same directory as the executable.
However, I get this error:
"Unhandled Exception: System.TypeInitializationException: The type initializer fo
r '<Module>' threw an exception. ---> System.DllNotFoundException: Unable to loa
d DLL 'yeppp': The specified module could not be found. (Exception from HRESULT:
0x8007007E)
at Yeppp.Library.yepLibrary_Init()
at Yeppp.Library.Init()
at .cctor()
--- End of inner exception stack trace ---"
What am I doing wrong?
http://docs.yeppp.info/cs/index.html#GettingStarted
You also need to deploy yeppp.dll as the article says.

C# Compile Issue

An unhandled exception of type 'System.TypeInitializationException' occurred in Microsoft.VisualStudio.HostingProcess.Utilities.dll
Additional information: The type initializer for 'BobTyler.Program' threw an exception.
'BobTyler.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'
Any advice? Thanks.
My guess is that you´ve got a configuration setting in your BobTyler.exe.config (/app.config in the solution project) that isn't of a proper type. Check all entries under and make sure that they´re mapped to proper types.

C# opengl texture

I want to use textures in opengl on my C# application.
I'm using the Tao Framework and I used this code
http://www.gamedev.net/community/for...opic_id=405453 (post #2)
But I got this runtime error:
An unhandled exception of type 'System.DllNotFoundException' occurred in WindowsFormsApplication1.exe
Additional information: Unable to load DLL 'DevIL.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Could someone help me?
Is there any other way to do this?
I had this problem with GLU.FreeGLUT.dll but when I installed Tao Framework solved my problem .
before that i copy dll to win32 and there was in dotnet Directory and add to references in project but I recieved this message : "An unhandled exception of type 'System.DllNotFoundException' "
It looks like the problem is the loading of the dll. You should make sure the dll is properly importer in your project through the references. Also make sure that you haven't moved or deleted the dll after you have added it to your project.
It suggests you are missing DevIL. Try getting it and installing it before proceeding.

Categories

Resources