3
votes

I need to implement a wrapper to expose some native C++ code to C#, and have followed this tutorial:

http://www.silverlightshow.net/items/Windows-Phone-8-Native-Code-Support.aspx

So far in my C# test project, I don't have problems instantiating a class written in C++/CX from the Runtime Component project and using methods from that class, so long as I reference the entire project (.sln).

Visual Studio doesn't allow me to reference the Runtime Component DLL alone, but does allow me to reference the .winmd file in the project. C# then recognizes the namespace correctly, however at runtime I get a TypeLoadException when trying to create the same object.

This doesn't appear to be a namespace problem (as mentioned here: Changing namespace name of C++ component in Windows Phone causes exception), since everything is alright so long as I create a project reference (or does referencing a project vs a .winmd affect the namespace somehow?).

Is it possible to bundle the Runtime Component in some form that an end user can reference it without needing to provide the entire project?

3
Hi there. Having the same problem. Did you find a solution ? - hico
@hico, no I haven't, unfortunately :/ - easuter
Arf :( I tried to include the .dll of my winRT component, but it says "invalid assembly" or some like that. Makes me crazy, and the worst is that there is no documentation about that. The only doc. you have is about creating a WinRT INSIDE a windows phone app project, thats all. Such a shame - hico
Yep, at the time I also searched up and down for some documentation of this behaviour without success...really frustrating. In my case this was just a pet project I was working on, and have put it on the back-burner for now. Have you tried at the MSDN forums as well? - easuter
Nop, going to I think. Or direct contact Microsoft support. Right now, I'm trying to put my .dll generated everywhere, trying to reference them, but well... - hico

3 Answers

1
votes

You need to add following the to WMAppManifest.xml

<ActivatableClasses>
    <InProcessServer>
        <Path>YourComponent.dll</Path>
        <ActivatableClass ThreadingModel="both" ActivatableClassId="YourComponentNamespace.YourComponent"/>
    </InProcessServer>
</ActivatableClasses>

With YourComponent being the name of your WinMD.

1
votes

I think what you are seeing is a manifestation of the problem described here.

In short, when creating a WinRT component using C++, just referencing the output DLL or the output winmd is not sufficient. You need both.

1
votes

I had this same problem, and (eventually) figured out that the .dll and .winmd file needed to have the same name (which was the same as the namespace they defined) and be in the same directory.

For example, if your classes are in the X::Y namespace, the files must be X.Y.dll and X.Y.winmd.

Then all I needed to do was add a reference to the .winmd file in my project (by right-clicking on the References folder for that project in the Solution Explorer, choosing "Add Reference...", then choosing "Browse" from the dialog that comes up). I didn't need to add anything to the manifest file.