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

.NET 8.0.10 breaks MAUI builds #21170

Closed
timjamwoo opened this issue Mar 13, 2024 · 25 comments · Fixed by #21192
Closed

.NET 8.0.10 breaks MAUI builds #21170

timjamwoo opened this issue Mar 13, 2024 · 25 comments · Fixed by #21192

Comments

@timjamwoo
Copy link

timjamwoo commented Mar 13, 2024

Description

I've updated our MAUI project to 8.0.10 today and cannot build for Android or iOS. I updated by changing the <MauiVersion> tag in our .csproj to <MauiVersion>8.0.10</MauiVersion>.

I see this warning in the build log:

1>CSC: Warning CS8785 : Generator 'CodeBehindGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentNullException' with message 'Value cannot be null. (Parameter 'second')'.

This is followed by many errors related to XAML files not correctly linking to their corresponding codebehind (e.g. Error CS0103 : The name 'InitializeComponent' does not exist in the current context).

I have tried this on the latest versions of VS 2022 for Windows, and Rider for Mac, targeting Android and iOS respectively.

Steps to Reproduce

  1. Ensure you have latest Visual Studio/.NET installed
  2. Run dotnet workload update
  3. In an existing MAUI project, add/update the MauiVersion tag to the csproj: 8.0.10
  4. Try to build your project

Link to public reproduction project repository

No response

Version with bug

8.0.10

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.7

Affected platforms

iOS, Android

Affected platform versions

Android 10, iOS 17.3.1

Did you find any workaround?

Rollback to .NET 8.0.7.

Relevant log output

1>CSC: Warning CS8785 : Generator 'CodeBehindGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentNullException' with message 'Value cannot be null. (Parameter 'second')'.

@timjamwoo timjamwoo added the t/bug Something isn't working label Mar 13, 2024
@developer9969
Copy link

Just to say that I have run our azure devops pipeline against 8.0.10 and all worked building both iOS and android

@Domik234
Copy link

Is this happening on application or library?

I am asking because many ppl use MSBuild.Sdk.Extras to release Maui/Xamarin library but there is propably not support for newer .NET versions so MauiXaml and similar may be problematic.


Btw: There is also possible to emit generated files (purposely) by using @ .csproj:
<EmitCompilerGeneratedFiles>false</EmitCompilerGeneratedFiles>

@timjamwoo
Copy link
Author

@Domik234 this is a MAUI application.

@MAUIoxo
Copy link

MAUIoxo commented Mar 13, 2024

I am not sure, is there an official8.0.10 version or did you want to take a nightly build which would be something like 8.0.20-nightly.10311?

@timjamwoo
Copy link
Author

I am not sure, is there an official8.0.10 version or did you want to take a nightly build which would be something like 8.0.20-nightly.10311?

@MAUIoxo there is an official 8.0.10 release.

@Domik234
Copy link

@Domik234 this is a MAUI application.

Yeah, this is "maui" repo. But I've asked the question because many people tries to support both using one nuget (I am also using this method and works for me) and I know that there is this specific problem. 😁


Try this https://github.com/Domik234/IssueMaui-21170 (MauiApp2/MauiApp2.sln)
It contains only clear project + library with one Xaml ContentView.
Maui Version: 8.0.10
Platfoms: Android, iOS

This works for me as it should so cannot repro the problem.

Also don't forget to remove "bin" and "obj" folder after the version change at your project.


I am not sure, is there an official8.0.10 version or did you want to take a nightly build which would be something like 8.0.20-nightly.10311?

There was released Maui Version 8.0.10 yesterday. (SR3?) 😀

@timjamwoo
Copy link
Author

Try this https://github.com/Domik234/IssueMaui-21170 (MauiApp2/MauiApp2.sln) It contains only clear project + library with one Xaml ContentView. Maui Version: 8.0.10 Platfoms: Android, iOS

This works for me as it should so cannot repro the problem.

Thanks @Domik234 - I see that your test project doesn't include the <MauiVersion>8.0.10</MauiVersion> tag in the csproj - I was under the impression that for our 8.0.7 migration this was necessary to specify which release we're targeting. Am I mistaken?

@Domik234
Copy link

Domik234 commented Mar 13, 2024

Try this https://github.com/Domik234/IssueMaui-21170 (MauiApp2/MauiApp2.sln) It contains only clear project + library with one Xaml ContentView. Maui Version: 8.0.10 Platfoms: Android, iOS
This works for me as it should so cannot repro the problem.

Thanks @Domik234 - I see that your test project doesn't include the <MauiVersion>8.0.10</MauiVersion> tag in the csproj - I was under the impression that for our 8.0.7 migration this was necessary to specify which release we're targeting. Am I mistaken?

I am sorry about that. 😅

I believe that specifying the <MauiVersion> should only override variable $(MauiVersion) so I am just directly placing the version of MAUI to PackageReferences. You can check this by decompiling the DLL or you can see that nuget package is added to your "C:\Users\$User\.nuget\" folder. 😅

Just switched it to use the <MauiVersion> and works for me. Uploading as commit to the repo's main branch. ;)
image

Do not forget to remove
MauiApp2/bin
MauiApp2/obj
MauiLib1/bin
MauiLib1/obj

and restart VS before testing build & run. 😁

@Axemasta
Copy link
Contributor

I'm seeing the same issue for a maui app thats been in development for some time, the build is fine on 8.0.7 and if I only change that version to 8.0.10, I see the following error in the build output:

7>CSC: Warning CS8785 : Generator 'CodeBehindGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentNullException' with message 'Value cannot be null. (Parameter 'second')'.

And suddenly I'm greeted with hundreds of errors, all related to InitializeComponent not being found, this would make sense is the code behind generator fell over.

I've confirmed I'm using the latest 8.0.10 package, I've cleared my bin/obj folder and restored the solution and the result is the same.

I've tested this some of my demo maui apps that don't use any codebehind features (except InitializeComponent) and they do build. I see in the release notes for 8.0.10 that there are changes to the codebehind generator (#20524), could this be the cause of these new failures?

This looks like quite a serious issue that will brick 8.0.10 for any existing maui users, I'm happy to provide more verbose logs for investigation from my failing project.

@Axemasta
Copy link
Contributor

Axemasta commented Mar 13, 2024

I turned on detailed logging and have a stack trace for the argument null exception thrown by the code gen:

3>CSC: Warning CS8785 : Generator 'CodeBehindGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentNullException' with message 'Value cannot be null. (Parameter 'second')'.
System.ArgumentNullException: Value cannot be null. (Parameter 'second')
at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Linq.Enumerable.SequenceEqual[TSource](IEnumerable`1 first, IEnumerable`1 second, IEqualityComparer`1 comparer)
at System.Collections.Generic.Dictionary`2.FindValue(TKey key)
at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
at Microsoft.Maui.Controls.SourceGen.CodeBehindGenerator.GetTypeName(XmlType xmlType, Compilation compilation, AssemblyCaches xmlnsCache, IDictionary`2 typeCache)
at Microsoft.Maui.Controls.SourceGen.CodeBehindGenerator.TryParseXaml(XamlProjectItem parseResult, String uid, Compilation compilation, AssemblyCaches xmlnsCache, IDictionary`2 typeCache, CancellationToken cancellationToken, String& accessModifier, String& rootType, String& rootClrNamespace, Boolean& generateDefaultCtor, Boolean& addXamlCompilationAttribute, Boolean& hideFromIntellisense, Boolean& xamlResourceIdOnly, String& baseType, IEnumerable`1& namedFields)
at Microsoft.Maui.Controls.SourceGen.CodeBehindGenerator.GenerateXamlCodeBehind(XamlProjectItem xamlItem, Compilation compilation, SourceProductionContext context, AssemblyCaches xmlnsCache, IDictionary`2 typeCache)
at Microsoft.CodeAnalysis.UserFunctionExtensions.<>c__DisplayClass3_0`2.<WrapUserAction>b__0(TInput1 input1, TInput2 input2, CancellationToken token)

@jonathanpeppers
Copy link
Member

jonathanpeppers commented Mar 13, 2024

Probably some null check is needed here:

$(Nullable)=enable is set in this project, but I guess it didn't catch this.

/cc @mgoertz-msft

@mgoertz-msft
Copy link
Contributor

I'll take a look...

@PureWeen PureWeen added this to the Backlog milestone Mar 13, 2024
@mrwcjoughinaaf
Copy link

I am getting the same error on a big Xamarin to Maui conversion project I am working on. Have had to move the packages back to 8.0.7 as none of the workarounds mentioned work.

@mgoertz-msft
Copy link
Contributor

I have a fix. See associated PR #21192

@ryanalford-suzy
Copy link

Hopefully a fix can be pushed out quickly. 8.0.10 fixes a number of issues we are running into, but now causes hundreds of build errors.

@mrwcjoughinaaf
Copy link

mrwcjoughinaaf commented Mar 14, 2024

I have a fix. See associated PR #21192

Thanks @mgoertz-msft . I see there are tests failing that are preventing the PR from being allowed to be approved - please can you resolve those asap as we really need the fix - I have to explain to the client today that I wasted a day on this issue and would like to be able to say that the new version of the maui packages will be released very soon.

@kevinxufei kevinxufei added the s/triaged Issue has been reviewed label Mar 14, 2024
@Dave-Quick
Copy link

I too have run into this.

@Redth Redth moved this from Todo to In Progress in MAUI SDK Ongoing Mar 18, 2024
@Redth Redth modified the milestones: Backlog, .NET 8 SR3 Mar 18, 2024
@ryanalford-suzy
Copy link

@mgoertz-msft Do you happen to have an idea of when this fix will be released? Looks like it was merged into the "SR3" branch. Just wondering if there was a timeline on it's release.

@PureWeen
Copy link
Member

Can you test with the latest nightly build?
https://github.com/dotnet/maui/wiki/Nightly-Builds

@PureWeen
Copy link
Member

We're prepping a patch release to SR3 now
It'd be helpful if you could test nightly to validate it fixes your issue

@ryanalford-suzy
Copy link

Using 8.0.20-nightly.10336, I do not get build errors anymore. Looks like it's fixed!!! @PureWeen

@danardelean
Copy link

I also tested with 8.0.14 (from the nightly stream) and the build works

@jasho
Copy link

jasho commented Mar 20, 2024

We also ran into this issue and it's currently blocking our release. Tested the 8.0.20-nightly.10336 and can confirm that the build works fine.

@Redth
Copy link
Member

Redth commented Mar 21, 2024

8.0.14 was released to NuGet which should fix this.

You can see more information about updating to the latest NuGet here: #20159

@Axemasta
Copy link
Contributor

Thanks for the quick fix, confirmed working on my app using 8.0.14 ❤️

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.