سؤال

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?

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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.

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top