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

Can't add Material or Cupertino #10869

Closed
fsol11 opened this issue Jan 2, 2023 · 16 comments · Fixed by unoplatform/uno.toolkit.ui#445
Closed

Can't add Material or Cupertino #10869

fsol11 opened this issue Jan 2, 2023 · 16 comments · Fixed by unoplatform/uno.toolkit.ui#445
Labels
kind/bug Something isn't working triage/needs-information Indicates an issue needs more information in order to work on it.

Comments

@fsol11
Copy link

fsol11 commented Jan 2, 2023

Current behavior

After adding Material or Cupertino packages, a lot of errors happen at compile time similar to this:

Error CS0433 The type 'Application' exists in both 'Microsoft.WinUI, Version=3.0.0.0, Culture=neutral, PublicKeyToken=de31ebe4ad15742b' and 'Uno.UI, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null' \

File: App.xaml.cs (Line: 15)


Basically, all classes that exist in Microsoft.UI and exist in Uno.UI as well will generate this error throughout the program.

Expected behavior

It should compile without any error.

How to reproduce it (as minimally and precisely as possible)

Create a new Uno Platform solution. Then add Uno.Toolkit.UI.Material to all the projects as per instructions. At this step project will not compile.

Workaround

There is no workaround. Material or Cupertino packages should be removed.

Works on UWP/WinUI

No

Environment

Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia

NuGet package version(s)

No response

Affected platforms

Windows

IDE

Visual Studio 2022

IDE version

Visual Studio 17.4.3

Relevant plugins

No response

Anything else we need to know?

No response

@fsol11 fsol11 added difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification labels Jan 2, 2023
@fsol11
Copy link
Author

fsol11 commented Jan 3, 2023

To help you with debugging here are some more info:

  • The screenshot shows Visual Studio screen RIGHT after adding Uno.Toolkit.UI.Material. Note that I made sure it compiles and runs without issues before adding this library.

  • Also I have attached the list of errors Visual Studio produces during build, and also the binlogs of errors.

2023-01-03 - highlighted
Build Errors.txt
binlogs.zip

@kazo0
Copy link
Contributor

kazo0 commented Jan 12, 2023

Hi @lotrasoft !

I'm not able to reproduce this in my sample apps. Would you be able to zip up your test app and post it here so I can take a look?

@fsol11
Copy link
Author

fsol11 commented Jan 13, 2023

I just created a new project and added Material. Here is the URL:

https://github.com/lotrasoft/UnoPlatformTest2

I have upgraded to Visual Studio 17.4.4, but it was the same in 17.4.3.

Here is the screen shot of the errors I get. Notice all the Visual Studio internal crashes as well:

image

And here is the stack trace for Visual Studio's internal error:

StreamJsonRpc.RemoteInvocationException: An element with the same key but a different value already exists. Key: '(DocumentId, #486ec8f4-23ad-6cf2-ef30-6366c2f102db - App_2fda9225a7cb01641cbcc865f21e8188.cs)'
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__143`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__19.MoveNext()
RPC server exception:
System.ArgumentException: An element with the same key but a different value already exists. Key: '(DocumentId, #486ec8f4-23ad-6cf2-ef30-6366c2f102db - App_2fda9225a7cb01641cbcc865f21e8188.cs)'
      at System.Collections.Immutable.ImmutableSortedDictionary`2.FillFromEmpty(IEnumerable`1 items, Boolean overwriteOnCollision)
      at System.Collections.Immutable.ImmutableSortedDictionary`2.AddRange(IEnumerable`1 items, Boolean overwriteOnCollision, Boolean avoidToSortedMap)
      at System.Collections.Immutable.ImmutableSortedDictionary.ToImmutableSortedDictionary[TSource,TKey,TValue](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IComparer`1 keyComparer)
      at Microsoft.CodeAnalysis.TextDocumentStates`1..ctor(IEnumerable`1 states)
      at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.<FinalizeCompilationAsync>d__40.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.<BuildFinalStateFromInProgressStateAsync>d__37.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.<BuildCompilationInfoAsync>d__33.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.<GetOrBuildCompilationInfoAsync>d__32.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.<GetCompilationSlowAsync>d__30.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at Microsoft.CodeAnalysis.Remote.RemoteCompilationAvailableService.<>c__DisplayClass2_0.<<ComputeCompilationAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.<>c__DisplayClass16_0.<<RunServiceAsync>b__1>d.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass7_0`1.<<RunWithSolutionAsync>g__ProcessSolutionAsync|1>d.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<RunWithSolutionAsync>d__7`1.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<RunWithSolutionAsync>d__7`1.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.<RunWithSolutionAsync>d__11`1.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.<>c__DisplayClass16_0.<<RunServiceAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.<RunServiceImplAsync>d__17.MoveNext()
GitHub
Uno Platform Test. Contribute to lotrasoft/UnoPlatformTest2 development by creating an account on GitHub.

@kazo0
Copy link
Contributor

kazo0 commented Jan 13, 2023

@lotrasoft so I see a few things in the project,

  1. You should be using the Uno.Toolkit.WinUI.Material package instead of the Uno.Toolkit.UI.Material package since you are targeting the WinUI APIs. So you should replace this line with <PackageReference Include="Uno.Toolkit.WinUI.Material" Version="2.4.2" />
  2. This line should be <MaterialColors xmlns="using:Uno.Material" OverrideSource="ms-appx:///ColorPaletteOverride.xaml" /> instead.

Even with these changes, I am now seeing the issue you are experiencing. A quick workaround should be to include a later version of Uno.WinUI in the Windows head. So if you were to add <PackageReference Include="Uno.WinUI" Version="4.6.41" /> to your Windows csproj, you should avoid the build errors.

I believe either we will need to bump the version of Uno that comes within Toolkit or we are missing a backport somewhere.

cc: @jeromelaban, @MartinZikmund I think this is related to those other failures we had looked at before

@Youssef1313
Copy link
Member

Regarding VS crashes, it looks like it was reported for Roslyn in dotnet/roslyn#57660.

It looks like the fix from Roslyn (dotnet/roslyn#65039) targets 17.5.

kazo0 added a commit to unoplatform/uno.toolkit.ui that referenced this issue Jan 13, 2023
closes unoplatform/uno#10869

Newer version of Uno is needed to avoid build issues when Uno isn't already directly referenced with a newer version
@fsol11
Copy link
Author

fsol11 commented Jan 16, 2023

Oh boy! after some tweaking and applying changes suggested by you, and updating Windows SDK, then searching on the errors and manually updating the Windows project file I could get the program to compile. But it still does not run. I have updated the repository with the changes if you wanted to check it out:

https://github.com/lotrasoft/UnoPlatformTest2

It stops with this error:

Cannot create instance of type 'Microsoft.UI.Xaml.Controls.XamlControlsResources' [Line: 10 Position: 40]

GitHub
Uno Platform Test. Contribute to lotrasoft/UnoPlatformTest2 development by creating an account on GitHub.

@jeromelaban jeromelaban reopened this Jan 16, 2023
@MartinZikmund
Copy link
Member

@lotrasoft can you please try to update to latest Uno 4.7 to see what happens then?

@fsol11
Copy link
Author

fsol11 commented Feb 8, 2023

@MartinZikmund This is the process I went through: 1) Created a new blank Uno/Xamarin/UWP project 2) Added the nuget: "Uno.Toolkit.UI.Material" to all the projects. 3) Compile

I got 5 errors:
image

If you guys go through the same process and don't get these errors, we should examine our Visual Studio installation and see what is different.

@MartinZikmund
Copy link
Member

The errors in the screenshot are different than the one in the original post - have you tried following the error there - eg. Installing the package mentioned?

But the odd thing is that Toolkit requires this reference 🤔 - @kazo0 should you need to install Skottie for Toolkit to work?

@jeromelaban
Copy link
Member

@lotrasoft you also have to update the global.json file to match your current installation.

@fsol11
Copy link
Author

fsol11 commented Feb 9, 2023

@jeromelaban & @MartinZikmund I started from scratch. Created a new project using the new Uno template, and added Material toolkit library - as I mentioned in my post.

I first created the project from scratch using Uno/Xamarin/UWP template, and it was compiling and running just fine. These issues started appearing right after adding Material Toolkit nuget. So for fixing this, I guess the Material/Cupertino nuget and their toolkits should be adjusted to install the required libraries and make necessary changes.

For testing, I added SkiaSharp.Skottie 2.88.1 to the Skia.Tizen, Wasm, Skia.Wpf, Skia.Wpf,Host, Skia.Gtk projects, and then I changed global.json file SDK from "5.0.0" to "6.0.0" and it started compiling.

As another test I created a new Uno project, and SDK in global.json is "5.0.0" and it compiles and runs fine. But after adding Material, it starts giving an error about the SDK. So how was it working before adding Material? Might it be that Uno's core is referencing .NET 5, and Material/Cupertino are referencing 6?

@jeromelaban
Copy link
Member

Can you provide a binlog of the failed build?

@Youssef1313 Youssef1313 added the triage/needs-information Indicates an issue needs more information in order to work on it. label May 7, 2023
@Youssef1313
Copy link
Member

@fsol11 Are you still having issues here? If so, can you provide more information?

@MartinZikmund
Copy link
Member

@fsol11 is this still relevant?

@MartinZikmund MartinZikmund removed triage/untriaged Indicates an issue requires triaging or verification difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. labels Aug 23, 2023
@fsol11
Copy link
Author

fsol11 commented Aug 27, 2023

thanks for following up. I actually don’t know if it’s still relevant or not. I abandoned my project at that time.

@MartinZikmund
Copy link
Member

Thank you for the information, closing this for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working triage/needs-information Indicates an issue needs more information in order to work on it.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants