编译 Windows 运行时组件时 Windows 元数据导出器崩溃 [英] Windows Metadata Exporter Crashes when Compiling Windows Runtime Component

查看:19
本文介绍了编译 Windows 运行时组件时 Windows 元数据导出器崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建用于 Windows 8 应用的 Windows 运行时组件.

I'm attempting to create a Windows Runtime Component for use in a Windows 8 app.

这本质上是一个 helloworld 级别的应用程序,因此没有什么复杂的.要复制该问题,我唯一需要做的就是包含一对方法,例如以下内容:

This is essentially a helloworld level application and so has nothing complex. The only thing that I need to do to replicate the issue is to include a pair of methods such as the following:

public IAsyncOperation<string[]> GetThings()
{
    return GetThingsAsync().AsAsyncOperation();
}
    private async Task<string[]> GetThingsAsync()
{
    return new List<string>().ToArray();
}

每当我编译项目时,Windows 元数据导出器就会崩溃.

Whenever I compile the project, the Windows Metadata Exporter crashes.

我通过增加构建详细程度深入研究了输出窗口中生成的错误,我发现错误发生在导出 'obj\Debug\HelloWorld.Logic.winmdobj'"之后.

I've dug into the errors generated in the output window by increasing the build verbosity and I've found that the error occurs after "Exporting 'obj\Debug\HelloWorld.Logic.winmdobj'."

通过尝试使用相同的参数从命令行运行 winmdexp.exe,它似乎无法找到 System.Xml 文件的元数据.(警告 WME0004:找不到引用的元数据C:\Program Files(x86)\ReferenceAssemblies\Microoft\Framework.NETCore\v4.5.1\System.Xml.Serialization.dll".)

By attempting to run winmdexp.exe from command line with the same parameters, it seems that it's having trouble finding metadata for the System.Xml files. (warning WME0004 : Could not find referenced metadata 'C:\Program Files(x86)\ReferenceAssemblies\Microoft\Framework.NETCore\v4.5.1\System.Xml.Serialization.dll'.)

错误的完整堆栈跟踪是:

The full stack trace of the error is:

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Tools.WinMDExp.AssemblyReferenceExtensionMethods.IsWindowsRuntimeMetadata(IAssemblyReference assembly)
at Microsoft.Tools.WinMDExp.ExportVisitor.IsWindowsRuntimeType(ITypeReference type, Boolean allowGenericParam)
at Microsoft.Tools.WinMDExp.ExportValidator.<>c__DisplayClasse.<GetAlternativeTypes>b__8(<>f__AnonymousType0`2 <>h__TransparentIdentifier5)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)
at Microsoft.Tools.WinMDExp.ExportValidator.GetAlternativeTypes(ITypeReference parameterType, IMethodDefinition containingMethod, Boolean& isTask, Boolean allowGenericTypeParam)
at Microsoft.Tools.WinMDExp.ExportValidator.GetAlternativesTypesForGenericTypes(IGenericTypeInstanceReference parameterType, IMethodDefinition containingMethod, String& errorMsg)
at Microsoft.Tools.WinMDExp.ExportValidator.CheckAlternateTypes(ITypeReference parameterType, IMethodDefinition containingMethod, Boolean& reportedError)
at Microsoft.Tools.WinMDExp.ExportValidator.ValidateExportParameterType(IMethodDefinition containingMethod, ITypeReference parameterType, Boolean& reportedError)
at Microsoft.Tools.WinMDExp.ExportValidator.ValidateExportMethod(IMethodDefinition method)
at Microsoft.Tools.WinMDExp.ExportValidator.TraverseChildren(IMethodDefinition method)
at Microsoft.Cci.MetadataTraverser.Traverse(IMethodDefinition method)
at Microsoft.Cci.MetadataTraverser.Traverse(IEnumerable`1 methods)
at Microsoft.Cci.MetadataTraverser.TraverseChildren(ITypeDefinition typeDefinition)
at Microsoft.Tools.WinMDExp.ExportValidator.TraverseChildren(ITypeDefinition typeDefinition)
at Microsoft.Cci.MetadataTraverser.TraverseChildren(INamedTypeDefinition namedTypeDefinition)
at Microsoft.Tools.WinMDExp.ExportValidator.TraverseChildren(INamespaceTypeDefinition namespaceTypeDefinition)
at Microsoft.Cci.MetadataTraverser.Traverse(INamespaceTypeDefinition namespaceTypeDefinition)
at Microsoft.Cci.MetadataTraverser.Dispatcher.Visit(INamespaceTypeDefinition namespaceTypeDefinition)
at Microsoft.Cci.MetadataReader.ObjectModelImplementation.NamespaceType.Dispatch(IMetadataVisitor visitor)
at Microsoft.Tools.WinMDExp.ExportValidator.Validate(ITypeDefinition type)
at Microsoft.Tools.WinMDExp.ExportValidator.TraverseChildren(IModule module)
at Microsoft.Cci.MetadataTraverser.TraverseChildren(IAssembly assembly)
at Microsoft.Tools.WinMDExp.ExportValidator.TraverseChildren(IAssembly assembly)
at Microsoft.Cci.MetadataTraverser.Traverse(IAssembly assembly)
at Microsoft.Tools.WinMDExp.ExportVisitor.Export(IAssembly assembly)
at Microsoft.Tools.WinMDExp.Exporter.Export()
at Microsoft.Tools.WinMDExp.Program.Main(String[] args)

如果有人知道发生了什么以及我如何编译我的组件,我将不胜感激.

If anyone has any idea what's going on and how I can get my component compiling I'd be grateful.

詹姆斯

附言我将项目转移到同事的 PC 上,他们遇到了同样的问题,所以我怀疑这是否与我的设置(Windows 8.1 x64、Visual Studio 2013 Ultimate)有关.

P.S. I transferred the project to a colleague's PC and they had the same issue so I doubt if it's anything to do with my setup (Windows 8.1 x64, Visual Studio 2013 Ultimate).

推荐答案

我自己设法解决了这个问题.

I've managed to figure this out myself.

使用 string[](或其他数组)作为 IAsyncOperation 的泛型类型时似乎存在错误.

It seems as though there is a bug when using string[] (or other arrays) as the generic type for IAsyncOperation.

我设法解决了这个问题,因为实际上我想返回 IDictionary 对象和 ILists,它们工作正常:

I have managed to work around this because actually I will want to return IDictionary objects and ILists, which work fine:

/* //Won't Work - crashes Windows Metadata Exporter
public IAsyncOperation<string[]> GetThings()
{
    return GetThingsAsync().AsAsyncOperation();
}
private async Task<string[]> GetThingsAsync()
{
    return new [] {"I am a string"};
}
*/

//This Works
public IAsyncOperation<IList<string>> GetThingsList()
{
    return GetThingsListAsync().AsAsyncOperation();
}
private async Task<IList<string>> GetThingsListAsync()
{
    return new[] { "I am a string" };
}

希望这对遇到这种奇怪行为的其他人有用.

Hopefully this will be of use to anyone else who comes across this weird behaviour.

这篇关于编译 Windows 运行时组件时 Windows 元数据导出器崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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