WP 运行时组件 - 类型加载异常? [英] WP Runtime Component - Type load exception?

查看:16
本文介绍了WP 运行时组件 - 类型加载异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么有效> 库设置

我有一个包含 2 个项目的 Windows Phone 8 解决方案:

  • Hello",一个简单的库项目 -> 生成 Hello.dll.
  • HelloNativeRT",一个带有 C++ 文件的 WP 运行时组件 -> 生成 HelloNativeRT.dllHelloNativeRT.winmd

在这个解决方案中,Hello"库引用了 WP 运行时组件,所以调用像...

HelloNativeRT.SampleNamespace test = new HelloNativeRT.SampleNamespace();

...在这个库项目中工作正常.

什么不起作用 > WP8 应用设置

但是,我想在 Windows Phone 8 应用程序中使用这两个库,但不添加对项目的引用,因为我需要将编译后的库发送到客户.

  • 我引用了项目中的 Hello.dll 文件,以及 HelloNativeRT.winmd 文件.
  • 当我在调试模式下启动应用程序并转到 HelloNativeRT.SampleNamespace test = new HelloNative... 行时,它崩溃并显示TypeLoadException",就像它无法加载本机模块一样.

我想我需要以某种方式包含 HelloNativeRT.dll 文件,因为我猜它包含本机(编译)代码,因为 winmd 文件可能只嵌入 C++/CX代码.

<块引用><块引用>

我应该如何设置我的项目以包含此 DLL?

我试图把它放在 WP8 项目的根目录下,引用它,嵌入它......但没有运气.

解决方案

就我而言,原因很简单:从 WinRT 组件生成的 .winmd 文件和 .dll 文件必须具有 THE SAME NAME(例如:testRT.dll 和 testRT.winmd).

那么:

  • 在您的项目中添加 .winmd 元数据文件作为参考.
  • 检查 .winmd/dll 文件是否在同一文件夹中以正确加载.

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.

这篇关于WP 运行时组件 - 类型加载异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆