在 Windows Phone 中更改 C++ 组件的命名空间名称导致异常

编程入门 行业动态 更新时间:2024-10-23 14:33:53
本文介绍了在 Windows Phone 中更改 C++ 组件的命名空间名称导致异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我在 WP8 应用程序中有一个 C++ 运行时组件,如果我更改命名空间名称,每当我尝试实例化该命名空间中的类时,都会抛出TargetInvocation"异常.

I have a C++ runtime component in a WP8 application, and if I change the namespace name, I get a "TargetInvocation" exception thrown whenever I try to instantiate a class in that namespace.

举个例子,如果我创建默认的 C++ Windows 运行时组件,标题看起来像这样:

As an example, if I create the default C++ Windows Runtime Component, the header looks like this:

#pragma once

namespace CppComponent1
{
    public ref class WindowsPhoneRuntimeComponent sealed
    {
    public:
        WindowsPhoneRuntimeComponent();
    };
}

如果我将 .h 和 .cpp 中的 CppComponent1 更改为 CppComponent2,然后尝试在我的 C# 中实例化 WindowsPhoneRuntimeComponent 对象代码,我收到以下错误:

If I change CppComponent1 to CppComponent2 in the .h and the .cpp, and then try to instantiate a WindowsPhoneRuntimeComponent object in my C# code, I get the following error:

A first chance exception of type 'System.TypeLoadException' occurred in Unknown Module.
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.ni.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in Microsoft.Phone.ni.dll

如何更改 WP8 应用程序中本机模块的命名空间?谢谢!

How can I change the namespace of a native module in a WP8 app? Thanks!

推荐答案

声明组件的 Windows 元数据 (WinMD) 文件的名称必须是声明公共类型的命名空间的前缀.(我在在回答另一个问题.)

The name of the Windows Metadata (WinMD) file that declares the component must be a prefix of the namespace in which the public types are declared. (I provided a slightly more detailed explanation of the namespace rules in an answer to another question.)

如果将命名空间从 CppComponent1 重命名为 CppComponent2,则还需要将构建生成的 WinMD 文件重命名为 CppComponent1.winmdCppComponent2.winmd.

If you rename the namespace from CppComponent1 to CppComponent2, you also need to rename the WinMD file produced by the build from CppComponent1.winmd to CppComponent2.winmd.

这篇关于在 Windows Phone 中更改 C++ 组件的命名空间名称导致异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

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

发布评论

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

>www.elefans.com

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