简体   繁体   中英

Could not load file or assembly Windows.winmd'

My WPF Desktop app is using WinRT classes as well.

In order to do that I follow this tutorial https://software.intel.com/en-us/articles/using-winrt-apis-from-desktop-applications .

Fine, it works.

Now when I try to generate the msi file (I tried both with using Microsoft Installer and ClickOnce), I am getting this error:

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 already tried with disabling the ClickOnce as suggested here , with cleaning the project and with deleting ASP.NET temporary of the different NET framework.

This is my startup tag in my app.config

I am using VS2015 and C# How can I fix it and generate my msi?

PS: I have no problem in generating another msi with a simple WPF desktop app.

Yes, the Windows.winmd file you added as a reference is an obstacle to getting the project deployed. The tools you use get confused about its content, it looks just like a .NET assembly. But it is not, the .winmd file format is an extension of the COM type library format of old. For WinRT, they used the metadata format of .NET to get past the restrictions of the TLB file format.

That was a pretty good idea, many .NET tools can use the metadata as-is. Like compilers and disassemblers, they didn't have to put all that infrastructure into place. But it strictly plays the role of a reference assembly , only the compiler uses its content and it should never be deployed. Right now you don't like that good idea too much :)

It is however very easy to fix for a ClickOnce deployment. Use Project > Properties > Publish tab > Application Files button. Change the "Publish Status" selection for Windows.winmd to "Exclude". Sample project screen-shot:

在此输入图像描述


It isn't very clear what you mean by "Microsoft Installer", I'll assume you talk about a Setup Project. Although removed from Visual Studio due to chronic problems, it is still available in the gallery.

That's a harder nut to crack, you'd normally use the Add > Project Output context menu entry to let it figure out the dependencies. That doesn't work anymore, it dies with miserable non-descript error message:

ERROR: An error occurred while validating. HRESULT = '80070057'

The error code means "Invalid parameter", that doesn't help narrow down the problem. But you can safely assume that it dies on trying to resolve the Windows.winmd reference in the .exe assembly.

The workaround is to not let it auto-detect the dependencies but pick them yourself. From the editor screen titled "File System on Target machine", select the Application Folder. Right-click "Primary output from ..." and select Delete.

Right-click Application Folder > Add > File and pick the project's .exe file from the bin\\Release folder. Repeat for other files, you can use the file listing you got in the ClickOnce application files listing as a guide.

Build the project, you now get:

WARNING: Unable to find dependency 'WINDOWS' (Signature='(null)' Version='255.255.255.255') of assembly 'WindowsFormsApplication144.exe'

Which is entirely benign, we don't want it to find it, the Setup.exe program works fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM