问题描述
限时送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.winmd
CppComponent2.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:关键词]
发布评论