WP8:不能使用原生组件

编程入门 行业动态 更新时间:2024-10-27 16:33:55
本文介绍了WP8:不能使用原生组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

Windows Phone 8 C# 项目 (MyApp),从 WP7.1 迁移而来.我在解决方案中添加了本机 Windows 运行时组件库 (AppLib),并创建了一个参考.其中有一个公开的密封引用类 (MyClass).在 C# 代码中(在主 XAML 页面的 OnLoaded 中)有一个对它的引用.整个编译过程 - 这意味着正在生成组件的元数据.

Windows Phone 8 C# project (MyApp), migrated from WP7.1. I've added a native Windows Runtime component library (AppLib) to the solution, created a reference. There's a public sealed ref class (MyClass) in it. There's a reference to it in the C# code (in OnLoaded of the main XAML page). The whole thing compiles - meaning the metadata of the component is being generated.

当我尝试运行时,项目失败并出现异常或键入 TypeLoadException 并显示以下消息:

When I'm trying to run, the project fails with the exception or type TypeLoadException with the following message:

在元数据文件中找不到类型名或命名空间.(来自 HRESULT 的异常:0x8000000F)

Typename or Namespace was not found in metadata file. (Exception from HRESULT: 0x8000000F)

AppLib.DLL 和 AppLib.winmd 都可以在 XAP 中找到.winmd 包含有关类型的信息,也包含在正确的命名空间中.我还应该检查什么?

Both AppLib.DLL and AppLib.winmd can be found in the XAP. The winmd contains the information about the type, and in the right namespace, too. What else should I check?

在异常时,AppLib.dll 未列在调试器的模块窗口中.就好像 DLL 加载由于某种原因失败一样.

At exception time, the AppLib.dll is not listed in the modules window of the debugger. It's as if the DLL loading fails for some reason.

我尝试过在任意命名空间中使用全新的类 - 同样的问题.看起来问题出在 DLL 级别,而不是类级别.

I've tried with brand new class in an arbitrary namespace - same problem. Looks like the problem is on the DLL level, not on class level.

推荐答案

WinMD 文件的名称必须是在其中声明任何公共和可激活类型的命名空间名称的前缀.例如,如果您的 WinMD 名为 AppLib.winmd,则您的 MyClass 类型必须定义在命名空间 AppLib 或嵌套在该命名空间内的其他命名空间中,例如 AppLib::Something.

The name of the WinMD file must be a prefix of the name of the namespace in which any public and activatable types are declared. For example, if your WinMD is named AppLib.winmd, your MyClass type must be defined in namespace AppLib or some other namespace nested within that namespace, for example AppLib::Something.

它还必须在最佳匹配"WinMD 中声明,因此如果您的类型名为 ABMyClass 并且您同时拥有 A.winmdABwinmd,类型必须在 ABwinmd 中定义.

It must also be declared in the "best matching" WinMD, so if your type is named A.B.MyClass and you have both A.winmd and A.B.winmd in your package, the type must be defined in A.B.winmd.

Windows 运行时使用类型名称来确定定义类型的 WinMD 文件.另请参阅我对XAML 在本地命名空间中找不到引用"的回答.

The Windows Runtime uses the name of the type to determine which WinMD file defines the type. See also my answer to "XAML cannot find reference in local namespace."

这篇关于WP8:不能使用原生组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 14:02:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117776.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!