Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
305 views
in Technique[技术] by (71.8m points)

c# - WP Runtime Component - Type load exception?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...