Could not load Windows.winmd

2020-07-29 23:20发布

问题:

I am following the following example from here to use WinRT API's in a Win32 Application.

I added references to System.Runtime and System.Runtime.InteropServices.WindowsRunTime but when I add the reference to Windows.winmd

I get the following error:

Error 1 Problem generating manifest. Could not load file or assembly 'C:\Program Files (x86)\Windows Kits\8.1\References\CommonConfiguration\Neutral\Windows.winmd' or one of its dependencies. Attempt to load a program with an incorrect format.

I tried various configurations using different .NET frameworks and versions of Visual Studio. What can I try?

回答1:

It seems that the setting

<GenerateManifests>true</GenerateManifests>

in the project file (e.g. .csproj) is not compatible with winmd references.

This setting is added when enabling the ClickOnce security settings (Project Properties => Security => Enabling ClickOnce security settings checkbox).

So far I could not find a way to fix the concrete problem, but I found a workaround, which works for my case: I just created a separate Class Library project in my solution, which the main project references. In the class library project file I added the line

<TargetPlatformVersion>8.0</TargetPlatformVersion>

as described in the referenced article.

The library project compiles and also the main project can use the dll without problems.



回答2:

I solved a very similar problem following this stackoverflow solution which basically makes u publish excluding the winmd.