Adding a winmd link and adding a project link

I have a Windows Phone 8 project and another project written in C ++; both are in the same solution. The C ++ project is the dynamic library used in the WP8 project, and it is configured to create a Windows Metada ( .winmd ) file on top of the .dll file.

When adding a C ++ project as a reference to a project in a WP8 project, everything works fine.

However, I would like to refer directly to the binaries instead of the project, so I tried to access the .dll itself, but VS2012 did not allow me (which I fully understand, since the library is unmanaged from what I understand). Adding a .winmd file instead works, I mean that it compiles without warning / errors; but it crashes at runtime (I get a TargetInvocationException that occurs because the "actual" C ++ library code was not found).

When adding the .winmd file .winmd I made sure that the .dll file is next to it. Including both files in the bin directory of the WP8 project does not work either.

I cannot find any clues on the Internet, and I would appreciate it if you could give me some clues!

Here is a diagram of the trivial architecture that I am trying to configure:

architecture

And here is the stop code of the exception raised:

 at System.StubHelpers.StubHelpers.GetWinRTFactoryObject(IntPtr pCPCMD) at Sqlite.Sqlite3.sqlite3_open_v2(String filename, Database& db, Int32 flags, String zVfs) at SQLite.SQLite3.Open(String filename, Database& db, Int32 flags, IntPtr zVfs) at SQLite.SQLiteConnection..ctor(String databasePath, SQLiteOpenFlags openFlags, Boolean storeDateTimeAsTicks) at SQLite.SQLiteConnection..ctor(String databasePath, Boolean storeDateTimeAsTicks) at WP8ClassLibrary.SomeManager..ctor(String databasePath) at WP8App.SomeViewModel..ctor() at WP8App.MainPage..ctor() 
+7
c # visual-studio visual-studio-2012 windows-phone-8
source share
3 answers

Well, I managed to get it to work. As stacktrace in the original post can suggest, I am using SQLite in my application. If I add the winmd file as a link instead of a C ++ project, it looks like some dependencies are not running.

So I had to add a link to SQLite for Windows Phone in the WP8ClassLibrary project. This was kind of a stupid mistake, because this C ++ project probably carried this dependency with itself (it has several winmd links, but I could not assume that they would be part of SQLite for Windows Phone based on their obscure names )

0
source share

Tools + Options, projects and solutions, assembly and launch. Change the "Output Size of the MSBuild Project Assembly" to "Normal."

Pay attention to the output of the assembly, the messages that you see after the "XapPackager". What is the mapping of files that are added to the Xap package. Your DLL should be on this list. If this is not the case, your program will fail as described. In this case, you will need to find out why it is skipped. Start by checking that the Copy Local property for the .winmd link is True.

+1
source share

I just wanted to add my experience to the answer.

If you are trying to add the C ++ library directly to C # code (for the Windows Phone 8.1 application in my case), then including the .winmd file enables compilation, but the application crashes at startup. The stack trace says it failed to load the C ++ dll.

I also had to add a link to the Visual Studio C ++ runtime library in a C # application. I found out about the missing link by distinguishing between a working .xap (created from a solution that includes both C # and C ++ projects) and a broken .xap (created from a solution that includes only a C # project along with a link to a file C ++. Winmd)

0
source share

All Articles