WP Runtime Component - Type load exception? - c#

What works > Library setup
I have a Windows Phone 8 solution with 2 projects:
"Hello", a simple library project -> generates Hello.dll.
"HelloNativeRT", a WP Runtime Component with C++ files -> generates HelloNativeRT.dll and HelloNativeRT.winmd
In this solution, the "Hello" library references the WP Runtime Component, so calls like...
HelloNativeRT.SampleNamespace test = new HelloNativeRT.SampleNamespace();
...work fine in this library project.
What doesn't work > WP8 app setup
However, I want to use these two libraries in a Windows Phone 8 app, but without adding references to the projects, since I need to ship the compiled libraries to clients.
I referenced the Hello.dll file in the project, as well as the HelloNativeRT.winmd file.
When I launch the application in debug mode, and goes to the line HelloNativeRT.SampleNamespace test = new HelloNative... it crashes and says "TypeLoadException", like it cannot load the native module.
I suppose I need to include the HelloNativeRT.dll file in a way or another, since I guess it contains the native (compiled) code, as the winmd file may only embed the C++/CX code.
How should I setup my project to include this DLL?
I tried to put it at the root of the WP8 project, to reference it, to embed it... with no luck.

The reason was quite simple in my case: the .winmd file and the .dll file generated from the WinRT Component must have THE SAME NAME (e.g: testRT.dll and testRT.winmd).
Then:
Add the .winmd medata file as a reference in your project.
Check that the .winmd / dll files are in the same folder to be correctly loaded.

You need to:
Add a reference to your managed DLL file (the wrapper),
Add a reference to your winmd metadata file (the WinPRT component),
Add your native DLL library file as a member of your project, with build action to "Content" and "Copy always" selected.
Add a section to your manifest file:
WPAppManifest:
<ActivatableClasses>
<InProcessServer>
<Path>external_component.dll</Path>
<ActivatableClass ActivatableClassId="external_component.MyComponent" ThreadingModel="both" />
</InProcessServer>
</ActivatableClasses>
This last point is the one that is auto-magically done by Visual Studio when you reference a WinPRT project from a WP8 project ;-) I suppose not a lot of people are referencing native libs manually, since the documentation on that point is very sparse. The only link where I saw the solution mentionned was here...

Related

TypeLoadException after compile unity editor script into dll

I have compiled our editor scripts into a single .dll file, and put it in /Assets/Editor directory:
These extended script menus are shown in editor correctly:
But it has this TypeLoadException when I click the menu. The type 'Util' is actually in 'UnityVS.x3dgame.CSharp.csproj' project, which is also a library project.
TypeLoadException: Could not load type 'Util' from assembly 'EditorLibrary'.
Scene2DBundleTool.GenerateSceneEffectLuaEditor ()
I have no idea how to solve this.
Here is some more information:
Solution structure:
EditorLibrary references:
Help wanted.
You get this error because you did not build the dll it properly. If you want to include Unity's API in your own dll, you must add also add Unity reference to the dll so that your dll can use those API.
You must the basic references such as, System, System.Core and System.Xml.
Now, you must add Unity's references to your dll project before build the dll project. The dll reference to add depends on where the Unity API came from.
Standalone API:
UnityEngine.dll - from C:\Program Files\Unity\Editor\Data\Managed
Editor API:
UnityEditor.dll - from C:\Program Files\Unity\Editor\Data\Managed
UI:
UnityEngine.UI.dll - from C:\Program
Files\Unity\Editor\Data\UnityExtensions\Unity\GUISystem
[Editor features]:
UnityEditor.UI.dll - from C:\Program
Files\Unity\Editor\Data\UnityExtensions\Unity\GUISystem\Editor
Finally, make sure to select the proper .NET framework in your dll project before building it. .Net Framework 2.0 should be fine.
Our Unity's path may be different but once you find the root path where it is installed, everything else is the-same.
Note:
When I said, add reference, I meant add reference to the library project you are building not to your Unity project. From Visual Studio, this can be done by going to Projects ---> Add Reference... ---> Browse...(Button) then select the appropriate dll file.

Could not load file or assembly or one of its dependencies in solution with multiple depencencies

I have a solution in Visual Studio with three projects added to it. The first project is a C# WinForms project with it's dependency set to the second project. The second project is a VC++ project which compiles to a DLL.
This VC++ project is dependent on another VC++ project which is a static library. I am able to run the executable from the debug/release folder directly on the development system.
But when I try to test on a different computer, I get an error after UI loads saying "Could not find file or assembly "mydll.dll" or one of its dependencies. The specified module could not be found."
Both the VC++ projects have their output set to a specific folder. When I right click in the references and check path, it looks fine.
What must I do?
I would try opening the csproj file in a test editor like Notepad or Notepad++ and figure out if the references are pointing to the right dll(s). Also pay attention as some of the references might include signatures, and it might not be the right signature either.
What shows up on the IDE might not be exactly the same that you have on the csproj file.
You need to unload the project from VS to be able to edit it in a text editor.
Also do this for all the projects on the solution.
Did the other computer have the Microsoft C++ Redistributable installed, of the appropriate version (year) and architecture? Also you can investigate dependencies with dumpbin.

How to build a visual studio 2010 solution into a standalone dll?

I have a visual studio 2010 project, uses static and dynamic libs (.lib and .dll), the project is compiled and built successfully as .exe both in release and debug modes, the code is c and c++.
What is the right way to compile and wrapping all the solution to one standalone .dll file.
I want to have one dll file, I'll be able to load it in other c, c++, c# project safely.
in my case I want to load it in teraterm and in other simple self developed c# application.
Visual Studio has a C++ linker option called "Link Library Dependencies": http://msdn.microsoft.com/en-us/library/024awkd1(v=vs.90).aspx
This would link the object files from all projects in the solution directly into the project output (via dependency tracking). Be careful when you use this though, if you use this in an EXE and the DLLs you're linking export symbols your EXE will also export them.
Update:
Here's more detail: What happens is that instead of linking the DLLs (this assumes you have the DLLs you'd like to link set as dependencies of your project in the solution) to produce separate binaries, the linker takes the outputs from each individual project dependency and links them into the final executable/DLL directly, thus creating a monolithic DLL.
A side effect is that (depending on the code) the overall size of the output is reduced a little, the monolithic DLL (or EXE) might be large in general, but smaller in size than the individual output files combined due to link-time optimisations. Any symbols exported by the objects linked will be exported by the final DLL, since they are marked as such in the compilation step.
There's may be a catch, but being in VS2010, you should just click on the startup project, select 'properties' ->
'configuration properties' -> 'general' -> 'configuration type' -> set it to 'dynamic library (dll)'

How can i add the canon digital camera dll files to my project?

I went to this site:
https://www.didp.canon-europa.com/developer/didp/didp_main.nsf?opendatabase&login
I have a login and i have downloaded the version 2.1 of the sdk/edsdk
On my hard disk i have some directories one is with a class: EDSDK.cs i have added it to my project no problems.
Then i went to the directory: EDSDK>Dll
I tried to add there all the dll's and each one of them can't be added.
For some reason on all of them i'm getting the erorr:
Could not be added please make sure the file is accessible and that is valid assembly or COM.
I tried to go through this instruction by someone else who did it and managed to make it work here:
http://dickchiang.blogspot.co.il/2008/01/programming-with-canon-digital-camera.html
This comment:
Dick Chiang said...
Assuming you have EDSDK 2.1 (the same version I'm using), you would do something like: 1. Create a new project under VS2005; 2. Copy/include a copy of the EDSDK.cs class file that came with the EDSDK (I appears under the SAMPLE\CSharp\COMMON on my installation) into your project; 3. Copy all the DLL's found under the EDSDK\DLL folder onto your project output folder (not sure if there's a simpler way to do this by specifying the path where to look for the DLL's); 4. write your program to access the SDK via the EDSDK.cs class file that I mentioned in item 2.
I'm using visual studio c# 2012 pro windows 8 64bit
I can't email to the site where i have downloaded the sdk/edsdk since they are not supporting this things. I tried to email them before and they are not supporting.
What else can i do ?
Those are native dlls, so you don't add them through the Add References dialog. You simply copy them into your project directory and add them to source control via windows explorer. Then in VS you right-click your project and choose "Add Existing Item" and add them that way. Finally once they're added, you need to go into their properties in VS and change the Build Action to Content, and Copy to .. to "Copy if Newer".
The dll's functions are called via P/Invoke from C#, and the EDSDK.cs class provides a wrapper around all those calls if you look at it. The above steps make sure that the EDSDK dlls are copied to your build path when you compile your app, so that the compiled EDSDK.cs code can find them for the p/invoke calls.
Read up on p/invoke to get a better understanding.

Visual Studio - Referencing third party DLL

I am using Visual Studio 10 within a C# MVC appliction.
I have a qustion on a .dll reference. I am using a third party reference called
Ionic.Zip.dll. What I am not sure about is that it currently points to a location on my C: drive.
How and what is the best practice for me to put this .dll so that when I check in the project, others can also see this .dll without it blowing up.
Thanks
I would typically put a Library folder in my application structure, place the 3rd party dll in that folder, and then reference that dll. Then ensure that the library folder is checked into your source control.
Now, anyone that pulls your source will have the required dll.
Even easier...simply add a reference to DotNetZip via NuGet, the Visual Studio Package Manager:
http://nuget.org/packages/DotNetZip
And you shouldn't have to worry about it.
The best way is to use Nuget.
But in some cases Nuget is not available or not getting compative, so as our friend says, its better put a Library folder in application structure, place the 3rd party dll in that folder, and then reference that dll. Then ensure that the library folder is checked into source control. Now, anyone that pulls source will have the required dll.

Categories