How to resolve an entry point path error? - xaml

Issue:
I've moved the views in my application to a new folder named, 'Views'. But after moving the views I noticed I'm getting a navigation_failed event.
Debugging Steps:
In order to debug this I set a breakpoint on the exception message within the event. This then lead me to cause of the error, the compiler can't find the location of the moved view.
I tried to resolve this by updating the entry point and NavigationPage paths in the AppManifest.xml. To the new path of the view and the exception points that this path isn't correct.
Error: "No XAML was found at the location '/ParkingTagPicker.Views.MainPage'."
I updated the entry point here in the manifest file:
EntryPoint="ParkingTagPicker.Views.MainPage"
Question:
Can anyone advise on the correct path string in this case?
My MainPage.xaml location is as follow in the solution:
<phone:PhoneApplicationPage x:Class="ParkingTagPicker.Views.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
Orientation="Portrait"
SupportedOrientations="Portrait"
d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}"
shell:SystemTray.IsVisible="True"
mc:Ignorable="d">

When a page is in a subfolder, you must specify the full path for it, for example "Views/MainPage.xaml"
Same is valid when navigating between pages in the app, for example:
NavigationService.Navigate(new Uri("/Pages/ChartComparePage.xaml", UriKind.Relative));

Related

Type module:Header not found in xmlns clr-namespace:MyModule

I am trying to dynamically load an MAUI class library using Assembly.Load and open a page from it. This page references another ContentView. It works perfectly fine when running in debug mode, but when just starting the app manually (still compiled using the Debug configuration) it crashes with the following exception:
android.runtime.JavaProxyThrowable: Microsoft.Maui.Controls.Xaml.XamlParseException: Position 11:14. Type module:Header not found in xmlns clr-namespace:MyModule
at Microsoft.Maui.Controls.Xaml.CreateValuesVisitor.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.Xaml.XamlLoader.Visit(RootNode rootnode, HydrationContext visitorContext, Boolean useDesignProperties)
at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Assembly rootAssembly, Boolean useDesignProperties)
at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Boolean useDesignProperties)
at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, Type callingType)
at Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml[Home](Home view, Type callingType)
at MyModule.Home.InitializeComponent()
Here is the Home page:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:module="clr-namespace:MyModule"
x:Class="MyModule.Home"
BackgroundColor="White"
NavigationPage.HasNavigationBar="False">
<ContentPage.Content>
<StackLayout>
<module:Header />
</StackLayout>
</ContentPage.Content>
</ContentPage>
And here is the ContentView that is being referenced:
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyModule.Header">
<StackLayout Orientation="Horizontal" HeightRequest="100" >
<Image Source="mylogo.png" HorizontalOptions="Start" Margin="10"></Image>
</StackLayout>
</ContentView>
I also have the same error when running for windows, but on windows the error occurs whether I am debugging or not:
Type module:Header not found in xmlns clr-namespace:MyModule
I have tried adding [assembly: XamlCompilation(XamlCompilationOptions.Compile)] but it also didn't change anything.
I specifically do not want to reference the module project directly and would like to load and register everything dynamically.

UWP styles and themes in a nuget cannot find resource file

I have a UWP project and a class library for theme dictionary and some control default styles all merged into 1 file called "Themes.xaml" and I reference to that project and simply import it in "app.xaml" like so :
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="GI.UI/Themes.xaml" />
<ResourceDictionary Source="/Styles/_FontSizes.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
and it works as expected but when I create a nuget with the same styles project and use that instead, then project throws an exception it is unable to locate Themes.xaml at this path.
Update 1
I also tried adding an empty code behind file with "InitializeComponent()" for the ResourceDictionary "Themes.xaml" and it works perfectly when I import in the way showed below, but again it only works when I reference the project and doesn't work with nuget.
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<theme:Themes />
<ResourceDictionary Source="/Styles/_FontSizes.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
(Themes.xaml.cs) Resource Dictionary code behind.
using Windows.UI.Xaml;
namespace GI.UI
{
public sealed partial class Themes : ResourceDictionary
{
public Themes() => InitializeComponent();
}
}
Themes.xaml
<ResourceDictionary
x:Class="GI.UI.Themes"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:BelowWindows10version1809="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractNotPresent(Windows.Foundation.UniversalApiContract, 7)"
xmlns:Windows10version1809="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 7)"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<!-- some styles and themes here -->
</ResourceDictionary>
Update 2
Noticed this warning of an exception by xaml compiler .
So Now I have the code of that nuget project along with almost empty sample app, feel free to reference from project and then try referencing from nuget package as well.
project url : https://github.com/touseefbsb/UWP_Styles_Nuget
nuget package : https://www.nuget.org/packages/GI.UI/0.0.16
I have also given the nusepc file in the project which I used to create the package.
Note
When I create the nuget file I get following warning
I was able to solve the issue by following the folder structure as shown below :
and then editing nuspec file the following way :
You can try using like this:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///GI.Standards.Theme/Theme.xaml" />
<ResourceDictionary Source="/Styles/_FontSizes.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Using the ms-appx to refer to a file that comes from your app's package.
Source="ms-appx:///LibraryName/Folder/File.xaml"

Error finding the resource dictionary [Fluent.Ribbon]

I have added fluent.dll as reference. After that add a folder on my project called "Themes" and pasted the all theme folder on "Themes" directory. On my application.xaml i have added the below code i.e
<Application x:Class="Application"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<!--Attach Default Fluent Control's Theme-->
<ResourceDictionary Source="pack://application:,,,/Fluent; Component/Themes/Office2013/Generic.xaml" />
</Application.Resources>
</Application>
But when run it show a error that
an error occurred while finding the resource dictionary
I am using Vs2013 .net ver4.5.
Your spacing is wrong
<ResourceDictionary Source="pack://application:,,,/Fluent; Component/Themes/Office2013/Generic.xaml" />
should be
<ResourceDictionary Source="pack://application:,,,/Fluent;Component/Themes/Office2013/Generic.xaml" />

Using Staticresouce in Visual State causes Blend Designer to break: "Invalid attribute value Unknow for property Background"

I'm trying to change the Background of a Grid by using a Visual State and a Staticresouce as the value in the Setter of the Visual State. It works just fine at Runtime but the designer shows the following error (which doesn't help me a lot):
Exception: Der Text zu diesem Fehlercode wurde nicht gefunden. (unknown error)
Stacktrace:
at Windows.UI.Xaml.Hosting.XamlUIPresenter.Render()
at Microsoft.VisualStudio.DesignTools.WindowsXamlDesigner.Views.WindowsUIXamlImageHost.RenderWorker()
at Microsoft.VisualStudio.DesignTools.WindowsXamlDesigner.Views.WindowsUIXamlImageHost.RenderScheduler.OnRender(Object object)
at Microsoft.VisualStudio.DesignTools.WindowsXamlDesigner.Views.WindowsUIXamlImageHost.RenderScheduler.b__26_0(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
Invalid attribute value Unknown for property Background.
InnerException: None
This is what I tried:
<Grid x:Name="grid">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="TestGroup">
<VisualState x:Name="TestState">
<VisualState.Setters>
<Setter Target="grid.(Panel.Background)" Value="{StaticResource BackgroundBrush}" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="BackgroundBrush" Color="Black"/>
</ResourceDictionary>
<App>
...
<App.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Test.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</App.Resources>
</App>
The current Blend is really buggy so I am not surprised if you see errors like this.
One workaround is, reopen your page that contains this resource in Blend. You should see a dialog popping up (see below image). Then select your Test.xaml file from the Available dictionaries dropdown and hit OK.
By doing so blend will generate a DesignTimeResources.xaml file under your project Properties and it should eliminate the error on the designer.
However, I also noticed that your <ResourceDictionary.MergedDictionaries> isn't wrapped within a <ResourceDictionary>. Shouldn't it be something like this instread?
<App.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Test.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</App.Resources>
Update
This is indeed a Blend bug which even happens with built-in resources. To replicate, try building the project and then go to the States tab and select a VisualState, right after you will see the Blend Designer crashed. Note that I have Run project code in XAML Designer (if supported) turned off.
Currently the only way to remove the crash is to reopen the xaml file.

ResourceDictionary in MergedDictionaries Source causing VS 2012 Designer not to load

the line ResourceDictionary Source="..." ist underlined and the VS designer throws an Exception. Everything was working in VS 2008
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MySolution.MyProject;component/Styles/MyStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Exception:
Exception:Value cannot be null. Parameter name: item (Same for the InnerException)
at Microsoft.Expression.Platform.InstanceBuilders.ClrObjectInstanceBuilder.InstantiateChildren(IInstanceBuilderContext context, ViewNode viewNode, DocumentCompositeNode compositeNode, Boolean isNewInstance)
what is the "build Action" set for your MyStyles.xaml?
try setting this to "page" if it is not already set-up like this.
see this other answer for details: (it seems to me that this could be related in a way)
Style TargetType causes XamlParseException when not attached to debugger