Autogenerated XAML.g.cs files do not compile in Xamarin Forms PCL project

I have a Xamarin form (I'm using the Xamarin Studio 5.7 project) with a common PCL containing user interface components. I just used classes (no XAML designers) to start my project, and it works well, compiles and has a ContentPage with a few sub pages. I decided to add a new file AboutPage.xaml and AboutPage.cs and use the user interface to edit my forms. So, I created my new page through New File ... Forms ContentPage XAML ..... As I mentioned above, it creates my two files.

AboutPage.cs AboutPage.xaml

The resulting files look like this:

AboutPage.cs

using System; using System.Collections.Generic; using Xamarin.Forms; namespace IPSND.Xamarin { public partial class AboutPage : ContentPage { public AboutPage () { InitializeComponent (); } } } 

AboutPage.xaml

 <?xml version="1.0" encoding="UTF-8"?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="IPSND.Xamarin.AboutPage"> <ContentPage.Content> <StackLayout> <Image Id="ImageLogo" Aspect = "AspectFit"></Image> </StackLayout> </ContentPage.Content> </ContentPage> 

Now that looks fine, and I made sure my class declaration included a namespace. However, when I compile, the resulting AboutPage.xaml.g.cs file looks like this ... Notice how using statements are included in the namespace, not at the top of the file. Unfortunately, this cannot be compiled.

What have I done wrong here?

 //------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // Runtime Version:4.0.30319.18408 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ namespace IPSND.Xamarin { using System; using Xamarin.Forms; using Xamarin.Forms.Xaml; public partial class AboutPage : ContentPage { private void InitializeComponent() { this.LoadFromXaml(typeof(AboutPage)); } } } 

This leads to the following errors

 D:\SVN\IPSND.Xamarin\obj\Debug\AboutPage.xaml.g.cs(19,19): Error CS0234: The type or namespace name 'Forms' does not exist in the namespace 'IPSND.Xamarin' (are you missing an assembly reference?) (CS0234) (IPSND.Xamarin) D:\SVN\IPSND.Xamarin\obj\Debug\AboutPage.xaml.g.cs(19,19): Error CS0234: The type or namespace name 'Forms' does not exist in the namespace 'IPSND.Xamarin' (are you missing an assembly reference?) (CS0234) (IPSND.Xamarin) D:\SVN\IPSND.Xamarin\obj\Debug\AboutPage.xaml.g.cs(38,38): Error CS0246: The type or namespace name 'ContentPage' could not be found (are you missing a using directive or an assembly reference?) (CS0246) (IPSND.Xamarin) 

So, I thought, maybe this confused the tail of my namespace (IPSND.Xamarin) with the use head for Xamarin.Forms namespaces ... So I changed my namespace on this form set (both .cs namespace and XAML class declaration ) to be IPSND.Test. Unfortunately, this led to the same errors.

Apparently, as Jason pointed out in the comments below, this configuration for using using statements is not only allowed, but according to this document here , is a project for the generated file. So, I assume that the essence of this problem may be more related to my links to Xamarin.Forms in the PCL library (it seems to be talking about an error). Using the document mentioned above, I went into my .cs and .xaml files and got them exactly (without any statements whatsoever and without inheritance from ContentPage in the Partial declaration, but that didn't help ... yet.

+8
android c # portable-class-library xamarin xamarin.forms
source share
1 answer

Well, credit to Jason ..... he was on the right track and nailed it ... My IPSND.Xamarin namespace was a problem. Just changing the namespace on this particular xaml / cs was not a problem, it was with my project namespace having "Xamarin" at the end. I made a copy of my entire project and moved everything to IPSND.X, and everything was in order.

+7
source share

All Articles