Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Can't run published WinUI app. #1557

Closed
mgamache opened this issue Jul 6, 2021 · 15 comments
Closed

[Bug] Can't run published WinUI app. #1557

mgamache opened this issue Jul 6, 2021 · 15 comments
Labels
area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint platform/windows 🪟 s/needs-info Issue needs more info from the author t/bug Something isn't working

Comments

@mgamache
Copy link

mgamache commented Jul 6, 2021

How to reproduce:

Create a new MAUI project (VS 16.11.0 preview 2)

Debug => Runs fine
Publish => Running the published app Starts then exits with following error (from event viewer)

Application: MauiApp2.WinUI.exe
CoreCLR Version: 6.0.21.30105
.NET Version: 6.0.0-preview.5.21301.5
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.Runtime.InteropServices.COMException (0x80040154): Class not registered (0x80040154 (REGDB_E_CLASSNOTREG))
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode) in System.Private.CoreLib.dll:token 0x600467f+0x4
at WinRT.BaseActivationFactory..ctor(String typeNamespace, String typeFullName) in Microsoft.WinUI.dll:token 0x6000023+0x6e
at Microsoft.UI.Xaml.Application._IApplicationStatics..ctor() in Microsoft.WinUI.dll:token 0x6014cbd+0x1c
at System.RuntimeType.CreateInstanceOfT() in System.Private.CoreLib.dll:token 0x6000645+0x3e
--- End of inner exception stack trace ---
at System.RuntimeType.CreateInstanceOfT() in System.Private.CoreLib.dll:token 0x6000645+0x4e
at System.Activator.CreateInstanceT in System.Private.CoreLib.dll:token 0x6000963+0x0
at WinRT.WeakLazy`1.get_Value() in Microsoft.WinUI.dll:token 0x6000019+0x20
at Microsoft.UI.Xaml.Application.Start(ApplicationInitializationCallback callback) in Microsoft.WinUI.dll:token 0x6009b84+0x0
at MauiApp2.WinUI.Program.Main(String[] args) in C:\Users\mark\source\repos\MauiApp2\MauiApp2\MauiApp2.WinUI\obj\Release\net6.0-windows10.0.19041\win10-x64\Windows\App.g.i.cs:line 26

@Steinliiippp
Copy link

Same Problem here. I can run the project in Visual Studio 2019 Preview without any problems. But as soon as i build the executable and launch it, i get the same crash report in the windows event viewer.

.NET SDK
Version: 6.0.100-preview.5.21302.13
Commit: d6380bcae7

Runtime:
OS Name: Windows
OS Version: 10.0.19042
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\6.0.100-preview.5.21302.13\

Host (useful for support):
Version: 6.0.0-preview.5.21301.5
Commit: ec3e0b276b

.NET SDKs installed:
2.2.203 [C:\Program Files\dotnet\sdk]
3.1.410 [C:\Program Files\dotnet\sdk]
5.0.400-preview.21277.10 [C:\Program Files\dotnet\sdk]
6.0.100-preview.5.21302.13 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.All 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.0-preview.5.21301.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0-preview.5.21301.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.0-preview.5.21301.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@TheCakeMonster
Copy link

TheCakeMonster commented Jul 23, 2021

There appear to be a few limitations to MAUI on Windows, caused by the use of WinUI 3 as the host. Publishing is definitely one of those.

I think the answer to your problem might be that you have limited publishing options available because of the host being WinUI 3.

I've created a test application from the maui-blazor template and tried to publish it using Visual Studio. Here is the outcome of the ways I have tried:

  1. ClickOnce doesn't complete, as there is a problem with finding a value for a variable, more completely detailed in issue 31832 (ClickOnce fails for BlazorWinFormsApp and BlazorWpfApp aspnetcore#31832)
  2. Publishing to a folder as a portable executable fails, stating that a target runtime must be specified
  3. Specifying a particular runtime as the target succeeds and created a folder of only 42MB, which is theoretically reasonable for WinUI 3. However, when you start the application, it brings up a dialog asking you to install .NET, despite the runtimes already being available on my machine.

Publishing is definitely going to need some work for MAUI before launch, because the state of play at the moment isn't workable. However, we're in preview, and I completely understand that we should expect these bumps in the road at the moment, as making MAUI function at all has to come first!

Sidenote: the reason I was trying this is because I have found a permissions issue with running an application built with the experimental Mobile Blazor Bindings framework (a forerunner to MAUI using Blazor) when installed in the "Program Files" or "Program Files (x86)" folders. This is caused by the way the WebView2 component is initialised; by default WebView2 uses the application folder to store temporary files and this won't work in the folders mentioned, as they are read-only to the application - they are not suitable locations for temporary files. As soon as we have a way to publish, we need to test whether we can install an application and have it work using WebView2.

@TheCakeMonster
Copy link

In the previous iteration using Xamarin Forms, WPF was used as the host for Windows. That was much simpler; it's more comfortable for .NET developers, as it more completely falls within the .NET space that we are used to working in. WinUI 3 is not, and I think it will be a lot more painful for developers not used to WinUI (or UWP before it perhaps.)

I wonder if it's worth making WPF available as a host type in MAUI as well as WinUI. I think the use of WinUI 3 is going to cause a lot of friction. That might have a very negative impact on what otherwise promises to be a great technology - possibly to the point where a generation of developers are put off using it because of bad experiences that are nothing to do with MAUI itself.

@jsuarezruiz
Copy link
Contributor

Could you try with the latest Preview and Visual Studio 2022?

@jsuarezruiz jsuarezruiz added the s/needs-info Issue needs more info from the author label Nov 5, 2021
@mattleibow mattleibow added the area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) label Nov 5, 2021
@TheCakeMonster
Copy link

Could you try with the latest Preview and Visual Studio 2022?

Yes, absolutely. Were you wanting us to test with .NET MAUI Preview 9 (out now) or Preview 10? Preview 10 is due in a few days, I believe.

@TheCakeMonster
Copy link

Preview 9 ClickOnce deployment does the same thing I detailed above - I run setup.exe and it installs, but when I try to run it it shows a dialog asking if I want to install the runtime, despite the runtime already being installed.

Setup: Framework-dependent, target runtime: portable, x64 .NET 6 RC2 set as a prerequisite

@TheCakeMonster
Copy link

Same thing if I change the target runtime to win-x64; a dialog shows saying "To run this application, you must install missing frameworks for .NET".

Same machine being used for the build, publish and installation.

I can confirm I do have the x64 RC2 runtime already installed, so this prompt doesn't make any sense as far as I am concerned.

I've not tried clicking Yes because I don't know what it's going to try to do, and I don't want anything else installed on this machine.

@alexleo123456
Copy link

i have the same problem for a long time.

@TheCakeMonster
Copy link

Visual Studio 2022 17.1.0 Preview 1 with .NET 6 and .NET MAUI Preview 10 doesn't work either. ClickOnce has been removed, so I have attempted to publish to a folder for Windows, and that fails with the error:

RuntimeIdentifier 'win-x64' is invalid.

Publish Settings:
Configuration: Release | x64 (I added this configuration as it was missing from the solution; NB: Any CPU doesn't work either)
Target framework: net6.0-windows10.0.19041
Deployment mode: Framework-dependent
Target runtime: win-x64

I've tried win-x86 as well, that also fails.

@Saatvik-Aggarwal
Copy link

Running into a similar error. Debugging in VS works fine, but when attempting to run a generated build from outside of VS, the application fails to open. Crash message in Event Log says:

Windows x64, Debug:

CoreCLR Version: 6.0.21.52210 .NET Version: 6.0.0 Description: The process was 
terminated due to an unhandled exception. Exception Info: 
System.DllNotFoundException: Unable to load DLL 'Microsoft.ui.xaml.dll' or one 
of its dependencies: The specified module could not be found.

Here are my project settings:

<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<PublishReadyToRun>false</PublishReadyToRun>
<PublishSingleFile>false</PublishSingleFile>
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>

I tried both normally and single file; neither work. Tried x64 and any cpu; neither work. Doesn't run on my machine or a virtual machine running Windows Server.

@lharmsen
Copy link

I ran into the same issue. Is there any fix yet?

@pieter-j
Copy link

I found a workaround with a lot of trouble and testing. (for running in windows, I tried to publish see settings and results below)
So first I am running VS2022 Preview Version 17.1.0 Preview 1.1

There is some confusion on what to install because it is different for different versions of VS and MAUI.
I installed all the workloads in vs suggested earlier, but not sure if it is required in the latest previews (.net desktop, c++ desktop, .net mobile and universal apps)

I installed optional components:
under desktop development with c++:
msvc v143 (I also have 142 installed but that is supposed to be for non preview vs2022)
windows app sdk c++ templates
(needed but mine was already installed) windows 10 sdk (10.0.19041.0)
under .net desktop development:
windows app sdk c# templates
Under Mobile development with .net:
.net MAUI (preview)

Then after i created my app i opened the project file (fist tried in properties but without knowing what framework to use it is not helpful)
In the project file in targets there is a comment which includes the correct windows sdk target. (net6.0-windows10.0.19041)
which i added to the tag
If you read through the project file you will see everything else is there, but by default it misses the windows target. (not sure why, my guess is to make it not crash in mac)

Then on the debug dropdown you need to change the framework to the windows one and select windows machine as the debug device.

On trying to publish, i selected a folder to publish to as this is the simplest option.
When going through the wizard creating a publish profile it doesn't show the targeting options and default to ios.

So after creating the profile, i clicked on show all setting and set the target framework to the windows option, if the deployment mode is framework dependent (correct version of .net is installed on machine) i can select portable for target runtime and the publish succeeds. When i tried to run it i get a warning that i need .net runtime, since it is my dev machine it is already installed, but maybe not for running outside of vs / dotnet run, but i did not want to install additional .net runtimes when most things is working how i like it
(the win64 and win x86 options did not work

If i change the deployment mode to self contained the portable option is not available (it includes a specific version of .net) and the win64 and win x86 still did not work

This is my experience so far and i hope it helps someone.

@YataoFeng
Copy link

YataoFeng commented Dec 29, 2021

环境
Microsoft Visual Studio Enterprise 2022 (64 位) - Preview 版本 17.1.0 Preview 1.1
MAUI Perview11

调试 Blazor MAUI 在 VS2022 中运行正常。

发布单文件时,我遇到了问题,怎么解决?

—————————————————————————————————————————————
FolderProfile.pubxml

<Project>
  <PropertyGroup>
    <Configuration>Debug</Configuration>
    <Platform>Any CPU</Platform>
    <PublishDir>bin\Release\net6.0-windows\publish\</PublishDir>
    <PublishProtocol>FileSystem</PublishProtocol>
    <TargetFramework>net6.0-windows10.0.19041</TargetFramework>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <SelfContained>true</SelfContained>
    <PublishSingleFile>True</PublishSingleFile>
    <PublishReadyToRun>False</PublishReadyToRun>
    <PublishTrimmed>True</PublishTrimmed>
  </PropertyGroup>
</Project>

—————————————————————————————————————————————
输出

已启动生成…
1>------ 已启动生成: 项目: MauiApp1, 配置: Debug Any CPU ------
1>MauiApp1 -> C:\Users\Yatao Feng\source\repos\MauiApp1\MauiApp1\bin\Debug\net6.0-windows10.0.19041\win10-x64\MauiApp1.dll
2>------ 发布已启动: 项目: MauiApp1, 配置: Debug Any CPU ------
2>正在确定要还原的项目…
2>The RuntimeIdentifier 'win-x64' is invalid.
========== 生成: 成功 1 个,失败 0 个,最新 0 个,跳过 0 个 ==========
========== 发布: 成功 0 个,失败 1 个,跳过 0 个 ==========

—————————————————————————————————————————————
弹窗

发布遇到错误。
发布时遇到错误。我们无法确定错误的原因。有关详细信息,请查看输出日志。

已将诊断日志写入以下位置:
“C:\Users\Yatao Feng\AppData\Local\Temp\tmp36FD.tmp”。 

—————————————————————————————————————————————
tmp36FD.tmp

2021/12/29 10:46:28
System.AggregateException: 发生一个或多个错误。 ---> Microsoft.WebTools.Shared.Exceptions.WebToolsException: 发布时遇到错误。我们无法确定错误的原因。有关详细信息,请查看输出日志。
   --- 内部异常堆栈跟踪的结尾 ---
---> (内部异常 #0) Microsoft.WebTools.Shared.Exceptions.WebToolsException: 发布时遇到错误。我们无法确定错误的原因。有关详细信息,请查看输出日志。<---

Microsoft.WebTools.Shared.Exceptions.WebToolsException: 发布时遇到错误。我们无法确定错误的原因。有关详细信息,请查看输出日志。

===================

—————————————————————————————————————————————

@pdinbkk
Copy link

pdinbkk commented Dec 31, 2021

Issue is still there in Maui Preview 11 (with Microsoft Visual Studio Professional 2022 (64-bit) - Preview
Version 17.1.0 Preview 1.1). Publish fails both in VS and on cmdline with:

dotnet publish -c:Release -f:net6.0-windows10.0.19041 -o d:\tmp.

Error Message is:

C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(267,5): error NETSDK1005: Assets file 'C:\Users\me\source\myapp\myapp\obj\project.assets.json' doesn't have a target for 'net6.0-windows10.0.19041'. Ensure that restore has run and that you have included 'net6.0-windows10.0.19041' in the TargetFrameworks for your project.

@jfversluis
Copy link
Member

Hey everyone! I've been trying to look into this and wrote up all my findings in #4329. In an attempt to not be all over the place with this I'm closing this one, let's centralise the discussion in the aforementioned issue, thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Feb 25, 2022
@samhouts samhouts added the p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint label Jul 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint platform/windows 🪟 s/needs-info Issue needs more info from the author t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests