Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[xamlc] stop using pack:// with System.Uri in .NET 7 (#7859)
This reverts the XamlC changes in b8646cb. Originally we were hitting: XamlApp.xaml Invalid URI: The hostname could not be parsed. [D:\a\_work\1\s\src\Controls\samples\Controls.Sample\Maui.Controls.Sample.csproj] at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions) at System.Uri..ctor(String uriString, UriKind uriKind) at Microsoft.Maui.Controls.ResourceDictionary.RDSourceTypeConverter.GetResourcePath(Uri uri, String rootTargetPath) at Microsoft.Maui.Controls.XamlC.RDSourceTypeConverter.ConvertFromString(String value, ILContext context, BaseNode node)+MoveNext() at Microsoft.Maui.Controls.Build.Tasks.NodeILExtensions.PushConvertedValue(ValueNode node, ILContext context, TypeReference targetTypeRef, TypeReference typeConverter, IEnumerable`1 pushServiceProvider, Boolean boxValueTypes, Boolean unboxValueTypes)+MoveNext() at Microsoft.Maui.Controls.Build.Tasks.SetPropertiesVisitor.Set(VariableDefinition parent, String localName, INode node, IXmlLineInfo iXmlLineInfo, ILContext context)+MoveNext() at Microsoft.Maui.Controls.Build.Tasks.ILProcessorExtensions.Append(ILProcessor processor, IEnumerable`1 instructions) at Microsoft.Maui.Controls.Build.Tasks.SetPropertiesVisitor.Visit(ValueNode node, INode parentNode) at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode) at Microsoft.Maui.Controls.Build.Tasks.SetResourcesVisitor.Visit(ElementNode node, INode parentNode) at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode) at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode) at Microsoft.Maui.Controls.Xaml.RootNode.Accept(IXamlNodeVisitor visitor, INode parentNode) at Microsoft.Maui.Controls.Build.Tasks.XamlCTask.TryCoreCompile(MethodDefinition initComp, ILRootNode rootnode, String xamlFilePath, Exception& exception) I added some logging around this location, and the PR build was green... So we merged, but then the build on the `net7.0` branch failed with: XamlApp.xaml(11,37): error XFC0128: GetResourcePath failed: uri=AppResources.xaml, rootTargetPath=XamlApp.xaml What is weird is a test like this works fine! [Test] public void GetResourcePath() { var result = ResourceDictionary.RDSourceTypeConverter.GetResourcePath(new Uri("AppResources.xaml", UriKind.Relative), "XamlApp.xaml"); Assert.IsNotNull(result); Assert.IsNotEmpty(result); } So this must be something that doesn't fail every time. I was able to reproduce it locally *once*, but then not again... After some discussion in: dotnet/runtime#70443 (comment) It appears that usage of `pack://` is *sometimes* picking up a custom `UriParser`, such as: https://github.com/dotnet/runtime/blob/eef6c7f6cb7f73163313d349fbb796f37b4c3996/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.PackUriScheme.cs#L226-L229 If we just use something else, like `maui://`, I believe it will work around this issue. I'll leave it up to the MAUI team if they want to rewrite this method using `System.IO.Path` in the future.
- Loading branch information