CommunityToolkit/Maui.Markup

Compiler errors on attempting to build sample application in Windows

SimonORorke opened this issue · 6 comments

I get the following 4 errors and 3 warnings on attempting to build the sample application in Visual Studio 2022 (Windows):

Severity	Code	Description	Project	File	Line	Suppression State	Detail Description
Error	CS1061	'Label' does not contain a definition for 'TextCenterHorizontal' and no accessible extension method 'TextCenterHorizontal' accepting a first argument of type 'Label' could be found (are you missing a using directive or an assembly reference?)	CommunityToolkit.Maui.Markup.Sample (net6.0-android), CommunityToolkit.Maui.Markup.Sample (net6.0-ios), CommunityToolkit.Maui.Markup.Sample (net6.0-maccatalyst), CommunityToolkit.Maui.Markup.Sample (net6.0-windows10.0.19041.0)	D:\Simon\OneDrive\Documents\Visual Studio Projects\Examples\CommunityToolkit.Maui.Markup\samples\CommunityToolkit.Maui.Markup.Sample\Pages\SettingsPage.cs	23	Active
Error	CS1061	'Label' does not contain a definition for 'TextCenter' and no accessible extension method 'TextCenter' accepting a first argument of type 'Label' could be found (are you missing a using directive or an assembly reference?)	CommunityToolkit.Maui.Markup.Sample (net6.0-android), CommunityToolkit.Maui.Markup.Sample (net6.0-ios), CommunityToolkit.Maui.Markup.Sample (net6.0-maccatalyst), CommunityToolkit.Maui.Markup.Sample (net6.0-windows10.0.19041.0)	D:\Simon\OneDrive\Documents\Visual Studio Projects\Examples\CommunityToolkit.Maui.Markup\samples\CommunityToolkit.Maui.Markup.Sample\Pages\NewsDetailPage.cs	32	Active
Error	CS1061	'Entry' does not contain a definition for 'TextCenter' and no accessible extension method 'TextCenter' accepting a first argument of type 'Entry' could be found (are you missing a using directive or an assembly reference?)	CommunityToolkit.Maui.Markup.Sample (net6.0-android), CommunityToolkit.Maui.Markup.Sample (net6.0-ios), CommunityToolkit.Maui.Markup.Sample (net6.0-maccatalyst), CommunityToolkit.Maui.Markup.Sample (net6.0-windows10.0.19041.0)	D:\Simon\OneDrive\Documents\Visual Studio Projects\Examples\CommunityToolkit.Maui.Markup\samples\CommunityToolkit.Maui.Markup.Sample\Pages\SettingsPage.cs	40	Active
Error	CS1061	'Label' does not contain a definition for 'TextCenter' and no accessible extension method 'TextCenter' accepting a first argument of type 'Label' could be found (are you missing a using directive or an assembly reference?)	CommunityToolkit.Maui.Markup.Sample (net6.0-android), CommunityToolkit.Maui.Markup.Sample (net6.0-ios), CommunityToolkit.Maui.Markup.Sample (net6.0-maccatalyst), CommunityToolkit.Maui.Markup.Sample (net6.0-windows10.0.19041.0)	D:\Simon\OneDrive\Documents\Visual Studio Projects\Examples\CommunityToolkit.Maui.Markup\samples\CommunityToolkit.Maui.Markup.Sample\Pages\SettingsPage.cs	52	Active
Warning	CS8034	Unable to load Analyzer assembly D:\Simon\OneDrive\Documents\Visual Studio Projects\Examples\CommunityToolkit.Maui.Markup\src\CommunityToolkit.Maui.Markup.SourceGenerators\bin\Debug\netstandard2.0\CommunityToolkit.Maui.Markup.SourceGenerators.dll: Could not find file 'D:\Simon\OneDrive\Documents\Visual Studio Projects\Examples\CommunityToolkit.Maui.Markup\src\CommunityToolkit.Maui.Markup.SourceGenerators\bin\Debug\netstandard2.0\CommunityToolkit.Maui.Markup.SourceGenerators.dll'.	CommunityToolkit.Maui.Markup		1	Active	System.IO.FileNotFoundException: Could not find file 'D:\Simon\OneDrive\Documents\Visual Studio Projects\Examples\CommunityToolkit.Maui.Markup\src\CommunityToolkit.Maui.Markup.SourceGenerators\bin\Debug\netstandard2.0\CommunityToolkit.Maui.Markup.SourceGenerators.dll'.
File name: 'D:\Simon\OneDrive\Documents\Visual Studio Projects\Examples\CommunityToolkit.Maui.Markup\src\CommunityToolkit.Maui.Markup.SourceGenerators\bin\Debug\netstandard2.0\CommunityToolkit.Maui.Markup.SourceGenerators.dll'
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at Roslyn.Utilities.StandardFileSystem.OpenFile(String filePath, FileMode mode, FileAccess access, FileShare share)
   at Roslyn.Utilities.CommonCompilerFileSystemExtensions.OpenFileWithNormalizedException(ICommonCompilerFileSystem fileSystem, String filePath, FileMode fileMode, FileAccess fileAccess, FileShare fileShare)
   at Microsoft.CodeAnalysis.ModuleMetadata.CreateFromFile(String path)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerFileReference.GetAnalyzerTypeNameMap(String fullPath, Type attributeType, AttributeLanguagesFunc languagesFunc)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerFileReference.Extensions`1.GetExtensionTypeNameMap()
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerFileReference.Extensions`1.AddExtensions(Builder builder, String language, Func`2 shouldInclude)
-----

Warning	CS8034	Unable to load Analyzer assembly D:\Simon\OneDrive\Documents\Visual Studio Projects\Examples\CommunityToolkit.Maui.Markup\src\CommunityToolkit.Maui.Markup.SourceGenerators\bin\Debug\netstandard2.0\CommunityToolkit.Maui.Markup.SourceGenerators.dll: Could not find file 'D:\Simon\OneDrive\Documents\Visual Studio Projects\Examples\CommunityToolkit.Maui.Markup\src\CommunityToolkit.Maui.Markup.SourceGenerators\bin\Debug\netstandard2.0\CommunityToolkit.Maui.Markup.SourceGenerators.dll'.	CommunityToolkit.Maui.Markup		1	Active	System.IO.FileNotFoundException: Could not find file 'D:\Simon\OneDrive\Documents\Visual Studio Projects\Examples\CommunityToolkit.Maui.Markup\src\CommunityToolkit.Maui.Markup.SourceGenerators\bin\Debug\netstandard2.0\CommunityToolkit.Maui.Markup.SourceGenerators.dll'.
File name: 'D:\Simon\OneDrive\Documents\Visual Studio Projects\Examples\CommunityToolkit.Maui.Markup\src\CommunityToolkit.Maui.Markup.SourceGenerators\bin\Debug\netstandard2.0\CommunityToolkit.Maui.Markup.SourceGenerators.dll'
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at Roslyn.Utilities.StandardFileSystem.OpenFile(String filePath, FileMode mode, FileAccess access, FileShare share)
   at Roslyn.Utilities.CommonCompilerFileSystemExtensions.OpenFileWithNormalizedException(ICommonCompilerFileSystem fileSystem, String filePath, FileMode fileMode, FileAccess fileAccess, FileShare fileShare)
   at Microsoft.CodeAnalysis.ModuleMetadata.CreateFromFile(String path)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerFileReference.GetAnalyzerTypeNameMap(String fullPath, Type attributeType, AttributeLanguagesFunc languagesFunc)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerFileReference.Extensions`1.GetExtensionTypeNameMap()
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerFileReference.Extensions`1.AddExtensions(Builder builder, String language, Func`2 shouldInclude)
-----

Warning	WMC1006	Cannot resolve Assembly or Windows Metadata file 'D:\Simon\OneDrive\Documents\Visual Studio Projects\Examples\CommunityToolkit.Maui.Markup\src\CommunityToolkit.Maui.Markup\bin\Debug\net6.0\CommunityToolkit.Maui.Markup.dll'	CommunityToolkit.Maui.Markup.Sample	D:\Simon\OneDrive\Documents\Visual Studio Projects\Examples\CommunityToolkit.Maui.Markup\samples\CommunityToolkit.Maui.Markup.Sample\CommunityToolkit.Maui.Markup.Sample.csproj	1	

In Visual Studio, make sure you open CommunityToolkit.Maui.Markup.Sample.sln, not CommunityToolkit.Maui.Markup.Sample.csproj.

The solution is to build CommunityToolkit.Maui.Markup.SourceGenerators.csproj before building CommunityToolkit.Maui.Markup.csproj, before building CommunityToolkit.Maui.Markup.Sample.csproj. Building CommunityToolkit.Maui.Markup.Sample.sln will do this for you automatically.

Long story short, the .TextCenter() extension methods are generated using Source Generators.

@SimonORorke the path on disk looks long to me. Are you familiar with Windows path limits? This page shows how to enable long paths which may solve your issue:

https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#enable-long-paths-in-windows-10-version-1607-and-later

@bijington Thanks for the suggestion. I have enabled long path names in the registry, as instructed in the article. To be safe, I then rebooted my PC before retrying the compilation. Unfortunately, it made no difference. (By the way, as you have probably anticipated, the unit test project won't compile either: that results in 19 errors).

I have also tried compiling a copy of the solution with a much shorter path: "C:\Markup\samples\CommunityToolkit.Maui.Markup.Sample.sln". That did not help either.

Hey @SimonORorke! I finally figured this out. It's due to a regression in Microsoft.CodeAnalysis.CSharp v4.3.0: dotnet/roslyn#63780.

Downgrading to v4.2.0 fixed it.

@brminnick Ha, yes I can see it was a tricky one, as there was nothing you at the Markup team had knowingly done yourselves. Been there! The fix worked for me. Well done!