Getting XamlC error XFC0000 : Cannot resolve type "ContentView" - xaml

I am working on migrating Xamarin.forms application to .net maui and I follow steps mentioned in Microsoft site,
change .csproj to Microsoft.NET.Sdk for forms csproj, droid csproj, iOS csproj,replace Xamarin.forms namespace with maui,add mauiprogram.cs,
Delete Xamarin.Forms and Xamarin.Essentials nuget references,
set build action for xcml file to MauiXaml, replace forms xmlns in XAML file with xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
<?xml version="1.0" encoding="UTF-8"?\>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
When trying to build the forms project getting XamlC error XFC0000 : Cannot resolve type "ContentView", XamlC error XFC0000 : Cannot resolve type "ContentPage".

As Steve suggested, you can create a new project with Maui template and then create project file in Maui Project based on your Xamarin Project.

Related

Xaml Islands - Microsoft starter example not working for me

I am following the basic starter example shown here:
https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/host-custom-control-with-xaml-islands
I have followed it as closely as I can. I can get it working if I put my user control in with the UWP app (different to the example) but not as it is with the usercontrol in the class library.
Firstly, when I run the example as it is, I get:
"WindowsXamlManager and DesktopWindowXamlSource are supported for apps targeting Windows version 10.0.18226.0 and later. Please check either the application manifest or package manifest and ensure the MaxTestedVersion property is updated."
The only solution I can find to this was to add a manifest file to the wpf project containing:
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 -->
<maxversiontested Id="10.0.18362.0"/>
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
</assembly>
After that, I did not see that error, but when the wpf form loads, I see "Cannot create control of type ClassLibrary1.MyUserControl1", but no clues as to why.
Anyone know what I am doing wrong, how to find out what the problem is of know of any examples that do work?
I downloaded your project package and I found that you missed a step.
It's the forth step in Create a custom UWP control
Before the closing element, add the following XML to disable several properties and then save the project file. These properties must be enabled to host the custom UWP control in a WPF (or Windows Forms) app.
<PropertyGroup>
<EnableTypeInfoReflection>false</EnableTypeInfoReflection>
<EnableXBindDiagnostics>false</EnableXBindDiagnostics>
</PropertyGroup>
After you add this code to ClassLibrary1.csproj, clean up the class library and rebuild it, then everything will work.
Best regards.

Xamarin.Forms: Cannot resolve Assembly or Windows Metadata file 'Type universe cannot resolve assembly: MyApp.UI.Base...'

I have a Xamarin.Forms application. The project structure is somewhat more complex than in a regular Xamarin.Forms solution.
I have my platform-specific projects:
MyApp.Android
MyApp.iOS
MyApp.UWP
I have a .net standard library project for the .xaml page definitions:
MyApp.UI (this is referenced by the platform-specific projects)
I have a .net standard library project for the .xaml page base classes:
MyApp.UI.Base (this is referenced by MyApp.UI)
I have a PageBase class in MyApp.UI.Base.
Let's say I have Login.xaml like this:
<?xml version="1.0" encoding="utf-8" ?>
<base:PageBase xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:base="clr-namespace:MyApp.UI.Base;assembly=MyApp.UI.Base" ...>
...
</base:PageBase>
The type in Login.cs is also correct:
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Login : PageBase
{
// ...
}
When I compile the solution, I get the following error:
Cannot resolve Assembly or Windows Metadata file 'Type universe cannot resolve assembly: MyApp.UI.Base, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.'
This error seems totally wrong, I tried other solutions, like deleting the .vs folder or restoring nuget packages but none of them worked.
Can I not have base classes of xaml pages from different assemblies?
The problem was that the project MyApp.UI.Base was not referenced from the MyApp.UWP project. Adding a reference solved the issue. I guess the error was right, just not that exact.

Xamarin namespace issues in XAML files when changing startup project in VS

I have issues with Xamarin in Visual studio 2017 15.8.0 Preview 4 (And all previous builds)
I have a Xamarin forms project with a Android Project and a UWP project, if I change the startup project to UWP and try to compile I get this error
Error Failed to resolve assembly: 'FoosballXamarin.Android,
Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null' FoosballXamarin.UWP ...\Views\LoginPage.xaml
And the XAML itself will give me errors on these lines
xmlns:viewModels="clr-namespace:FoosballXamarin.ViewModels;assembly=FoosballXamarin.Android"
xmlns:helpers="clr-namespace:FoosballXamarin.Helpers;assembly=FoosballXamarin.Android"
And want me to change them to
xmlns:viewModels="clr-namespace:FoosballXamarin.ViewModels;assembly=FoosballXamarin.UWP"
xmlns:helpers="clr-namespace:FoosballXamarin.Helpers;assembly=FoosballXamarin.UWP"
Is there a way to write it differently so I dont get this error every time?
Based on the errors you're seeing, I'm going to guess you have this configured as a shared project (not PCL/.netstandard). If that's the case, simplify the lines in the XAML file to:
xmlns:viewModels="clr-namespace:FoosballXamarin.ViewModels"
xmlns:helpers="clr-namespace:FoosballXamarin.Helpers"
In other words, just remove the assembly= part. If you don't specify the assembly on the xmlns line, it will assume the namespace is the same assembly as the XAML file. So you only need to include it if it's in a different assembly.
Since shared projects include the XAML file in multiple assemblies (one per platform), you pretty much have to omit the assembly= on the xmlns declaration for namespaces/types in the same assembly.

CarouselView Xamarin Plugin not working

I am getting the following error:
Error CS0234: The type or namespace name 'CarouselView' does not exist
in the namespace 'Xamarin.Forms' (are you missing an assembly reference?)
(CS0234) (your project)
Using this on the XAML
xmlns:controls="clr-namespace:CarouselView.FormsPlugin.Abstractions;assembly=CarouselView.FormsPlugin.Abstractions"
Name of the package is: CarouselView.FormsPlugin.
Update......
xaml
As per the project documentation on GitHub, there are several steps you need to do to enable the plugin:
Install the package via NuGet
Initialize the plugin
On Universal Windows Platform include with Xamarin.Forms initialization:
List<Assembly> assembliesToInclude = new List<Assembly>();
assembliesToInclude.Add(typeof(CarouselViewRenderer).GetTypeInfo().Assembly);
Xamarin.Forms.Forms.Init(e, assembliesToInclude);
On iOS and Android right after Xamarin.Forms initialization:
Xamarin.Forms.Init();
CarouselViewRenderer.Init();
Use in XAML
For XAML usage, you need to include a different namespace (CarouselView.FormsPlugin.Abstractions) than you noted in the question:
xmlns:controls="clr-namespace:CarouselView.FormsPlugin.Abstractions;assembly=CarouselView.FormsPlugin.Abstractions"
And now use as:
<controls:CarouselViewControl ...>

.Net Core View: the name "Layout" does not exist in the current context

I'm using Visual Studio 2017 to build a .net core mvc project.
When I add a view in this way:
Right click folder -> Add View -> Add
Then the name "Layout" does not exist in the current context
Restart vs or build the project this error still exist.
However, If I add view in this way:
Right click folder -> Add New Items -> MVC View Page
the Layout can be recognized.
Is there any difference?
If you are using vs 2017 you have to add this code in new csproj which you created.
<PropertyGroup>
<OutputType>Library</OutputType>
</PropertyGroup>
Because When you create a new Web application, this gets set to the "Web" SDK:
<Project Sdk="Microsoft.NET.Sdk.Web">...</Project>
so the Web SDK imports additional tasks to allow design-time processing of Web resources, such as Razor views. Change the SDK in your plugin library to Web.
after you build error should be vanished.