Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
182 views
in Technique[技术] by (71.8m points)

c# - 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 Kits8.1ReferencesCommonConfigurationNeutralWindows.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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

enter image description here


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 binRelease 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...