dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.21k stars 1.75k forks source link

System.IO.FileNotFoundException: Could not load assembly 'Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken='. #9730

Closed roguedev1 closed 2 years ago

roguedev1 commented 2 years ago

Problem encountered on https://dotnet.microsoft.com/en-us/learn/maui/first-app-tutorial/install Operating System: Windows 10

I have installed VS 2022 and tried to migrate my project from VS 2019. However, when building the project I receive the following error message:

System.IO.FileNotFoundException: Could not load assembly 'Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken='.

Steps to Reproduce Create a new VS 2022 project Migrate classes and nuget packages from VS 2019 Build the app

Expected Behavior App runs without any issue

Actual Behavior Build failed error with this build log output:


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

Hey there @roguedev1 thanks for the report! Unfortunately it doesn't contain enough info at this point to effectively diagnose what might be going on. Could you maybe elaborate a bit more on these points:

Thanks!

cc: @Sweekriti91 for migration issues maybe?

ghost commented 2 years ago

Hi @roguedev1. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

roguedev1 commented 2 years ago

Hey there @roguedev1 thanks for the report! Unfortunately it doesn't contain enough info at this point to effectively diagnose what might be going on. Could you maybe elaborate a bit more on these points:

Hi thanks for the reply. I have added the information below.

What type of project are you trying to convert? MonoGame Android Application (MonoGame Team)

What are the steps you are taking? A bit more precise than copying classes and NuGets

What NuGets are you using?

What version of Visual Studio are you using? Microsoft Visual Studio Community 2022 (64-bit) Version 17.3.3

Did you install the .NET MAUI workload when installing Visual Studio? Yes

What does running dotnet --version tell you? 6.0.400

There is a build error in release mode that mentions the package:

Precompiling failed for C:\Users\hidden\obj\Release\net6.0-android\android-x86\linked\Plugin.MauiMtAdmob.dll. Failed to load method 0x6000095 from 'C:\Users\hidden\obj\Release\net6.0-android\android-x86\linked\Plugin.MauiMtAdmob.dll' due to Could not load file or assembly 'Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.. Mono Ahead of Time compiler - compiling assembly C:\Users\hidden\obj\Release\net6.0-android\android-x86\linked\Plugin.MauiMtAdmob.dll AOTID 030115F2-9CB1-3D92-0052-0036762132E1 Using profile data file 'C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\32.0.448\targets\dotnet.aotprofile' Run with MONO_LOG_LEVEL=debug for more information. AOT of image obj\Release\net6.0-android\android-x86\linked\Plugin.MauiMtAdmob.dll failed. hidden C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\32.0.448\targets\Microsoft.Android.Sdk.Aot.targets 91

PureWeen commented 2 years ago

https://github.com/marcojak/MauiMTAdmob/issues/6

PureWeen commented 2 years ago

Does this ring any bells @jonathanpeppers

jonathanpeppers commented 2 years ago

I think we need an MSBuild .binlog to look into this more. So @roguedev1 could you dotnet build -bl your project and share the msbuild.binlog file?

ghost commented 2 years ago

Hi @roguedev1. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

KelsamGames commented 2 years ago

@roguedev1 I had the same issue, here is how I fixed it:

Add <UseMaui>true</UseMaui> to your .csproj. The UseMauiEssentials directive is insufficient and NuGet does not handle this prerequisite for you. You may also need this: https://github.com/marcojak/MauiMTAdmob/issues/2

Delete your bin and obj folders (a simple Clean operation didn't work for me, so this was necessary). Rebuild.

MAUI also changes how you deploy to your Android Emulator/Hardware (the debug deploy menu changes from a device list to a standard "Start" button and submenus to select target for deployment).

I have been unable to get this (choosing an android deployment target) to work. At first I could build/deploy to an emulator, but upon trying to change to a hardware device target, it simply did nothing and the emulator device kept the checkmark. I then deleted my .csproj.user file in an attempt to get it regen/fix it. Now, the deploy target is stuck on my hardware device (has the checkmark in menu) and can't be changed away from it (unless I disconnect my device), and when I attempt to build I get the error "Please select a valid device before running the application."

jonathanpeppers commented 2 years ago

@roguedev1 does UseMaui=true solve anything for you?

ghost commented 2 years ago

Hi @roguedev1. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

I4-PJ commented 2 years ago

I have the same issue after updating VS from 17.3 to 17.4 prev2. Since than, it was working just fine.

Now I am getting an error error.txt

Project structure is not complex but having several MAUI / net standard libs. Only one library is affected (I4.Mobile.Droid.Controls) with that issue. I have tried to link a compiled affected library to the main project, however, other libs are affected either. Error is shown gradually one by one as each library is linked as dll instead as a project. This behavior is incl. Net standard 2.0 libs.

image image I4.Kenso.zip

jonathanpeppers commented 2 years ago

@I4-PJ I think your issue is the same as:

This is unrelated to this one, as the Could not load Microsoft.Maui.dll message is different than one of your own assemblies.

ghost commented 2 years ago

Hi @roguedev1. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

roguedev1 commented 2 years ago

I tried adding <UseMaui>true</UseMaui> to my .csproj and it did not seem to make any difference.

Here is my build log:

buildlog.txt

jonathanpeppers commented 2 years ago

Hi @roguedev1, somehow I missed checking back on this.

The build log above is minimal verbosity, so it doesn't have the info we need. If you ran dotnet build -bl, can you share the msbuild.binlog it created in the current directory?

If it is a sample project (C:\Users\abc_\source\repos\abc) are you able to share the entire project? Thanks!

roguedev1 commented 2 years ago

I've created a fresh project with the binlog: msbuild.zip

repo: https://github.com/roguedev1/Project1

jonathanpeppers commented 2 years ago

From the .binlog, Project1.csproj does not have <UseMaui>true</UseMaui>. I don't think we have a way for NuGet packages to opt your project into using MAUI.

Is the GitHub repo public? The link shows a 404, which could mean it's private.

roguedev1 commented 2 years ago

I changed it to public now

Yes sorry I made a fresh one without adding the extra line of code, although it made no difference when I tried before

jonathanpeppers commented 2 years ago

When I add UseMaui=true, the project gets past the Could not load Microsoft.Maui.dll and hits errors about missing Java packages:

javac.exe error JAVAC0000:  error: package com.google.android.ump.ConsentForm does not exist

Then I added the missing package:

<PackageReference Include="Xamarin.Google.UserMessagingPlatform" Version="2.0.0.2" />

I think that Plugin.MauiMTAdmob should make this a dependency?

Does that get things working for you? The sample app crashes, asking for an API key now:

09-30 15:54:01.034 14279 14279 I MonoDroid: ******************************************************************************
09-30 15:54:01.034 14279 14279 I MonoDroid: * The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
09-30 15:54:01.034 14279 14279 I MonoDroid: * should follow the instructions here:                                       *
09-30 15:54:01.034 14279 14279 I MonoDroid: * https://googlemobileadssdk.page.link/admob-android-update-manifest         *
09-30 15:54:01.034 14279 14279 I MonoDroid: * to add a valid App ID inside the AndroidManifest.                          *
09-30 15:54:01.034 14279 14279 I MonoDroid: * Google Ad Manager publishers should follow instructions here:              *
09-30 15:54:01.034 14279 14279 I MonoDroid: * https://googlemobileadssdk.page.link/ad-manager-android-update-manifest.   *
09-30 15:54:01.034 14279 14279 I MonoDroid: ******************************************************************************
roguedev1 commented 2 years ago

Thank you very much for the help @KelsamGames and @jonathanpeppers. I tried again and turns out I was editing the wrong file. I have a file called [projectname].csproj but this is a USER file. I was supposed to edit the [projectname] C# Project File.