Search code examples
c#dependenciesmaui

.NET - Migrating solution with two apps from WinForms to MAUI


I try to migrate an old WinForms app to the new MAUI base. That app is referencing an old console app which contains all the logic (the first app is only the UI hull).

But when I try to build that solution, I get the following errors:

  1. error NETSDK1151: проект "..\<ProjectName>\<ProjectName>.csproj", на который указывает ссылка, является автономным исполняемым файлом. Неавтономный исполняемый файл не может ссылаться на автономный исполняемый файл. Дополнительные сведения см. на странице https://aka.ms/netsdk1151 (not exact translation to English: error NETSDK1151: the project "..\<ProjectName>\<ProjectName>.csproj", which the link points to, is a standalone executable file. A non-standalone executable file cannot reference an offline executable file. For more information, see the page https://aka.ms/netsdk1151) - despite that I had exactly pointed <SelfContained>false</SelfContained> in the .csproj file.
  2. error : Empty ResolveFrameworkReference.RuntimePackPath while trying to read runtime components manifest. ResolvedFrameworkReference available: { Microsoft.NETCore.App, RuntimePackPath: } Who knows how to fix the solution? Maybe there is a template for multi-platform app, but without UI, or something similar?

EDIT: I have converted that console app to the .NET MAUI class library, as it is proposed in the comments, the first error has disappeared, but the second remains, and also I am now receiving the following errors stack:

2>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.26\tools\Xamarin.Android.Common.targets(1426,3): error XALNS7028: System.IO.FileNotFoundException: Could not load assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile? 2>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.26\tools\Xamarin.Android.Common.targets(1426,3): error XALNS7028: File name: 'System.Runtime.dll' 2>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.26\tools\Xamarin.Android.Common.targets(1426,3): error XALNS7028: at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters) at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs:line 245 2>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.26\tools\Xamarin.Android.Common.targets(1426,3): error XALNS7028: at Mono.Cecil.MetadataResolver.Resolve(TypeReference type) at /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/cecil/Mono.Cecil/MetadataResolver.cs:line 111 2>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.26\tools\Xamarin.Android.Common.targets(1426,3): error XALNS7028: at Mono.Cecil.TypeReference.Resolve() at /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/cecil/Mono.Cecil/TypeReference.cs:line 278 2>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.26\tools\Xamarin.Android.Common.targets(1426,3): error XALNS7028: at Java.Interop.Tools.Cecil.TypeDefinitionCache.Resolve(TypeReference typeReference) at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionCache.cs:line 20 2>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.26\tools\Xamarin.Android.Common.targets(1426,3): error XALNS7028: at Java.Interop.Tools.Cecil.TypeDefinitionRocks.d__5.MoveNext() at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs:line 40 2>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.26\tools\Xamarin.Android.Common.targets(1426,3): error XALNS7028: at Java.Interop.Tools.Cecil.TypeDefinitionRocks.IsSubclassOf(TypeDefinition type, String typeName, IMetadataResolver resolver) at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs:line 94 2>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.26\tools\Xamarin.Android.Common.targets(1426,3): error XALNS7028: at MonoDroid.Tuner.FixAbstractMethodsStep.FixAbstractMethods(AssemblyDefinition assembly) 2>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.26\tools\Xamarin.Android.Common.targets(1426,3): error XALNS7028: at Xamarin.Android.Tasks.LinkAssembliesNoShrink.RunTask() 2>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.26\tools\Xamarin.Android.Common.targets(1426,3): error XALNS7028: at Microsoft.Android.Build.Tasks.AndroidTask.Execute() at /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17

And when I disabled building for Android (which is, of course, temporary), the app had been compiled, but during launch I had received this error message. Who knows how to fix both situations?


Solution

  • After a lot of "digging", I figured out that the app doesn't work when the ContentPage constructor contains parameters. For everyone who creates one's app on MAUI: unlike the old UIs, in the MAUI the main form cannot be constructed with parameters! (EDIT: it looks like it can but in much more complex way.) Also, MAUI app cannot refer to the old EXE apps! (You must create the new app and move the logic to it.) Maybe these conclusions are dull for somebody, but for me it was difficult to found this problem. The solution isn't still working fine, but by another reason, which is not subject of this question.