InitializeComponent not defined in current context- Xamarin Form - xamarin.forms

We are developing Shared Code based Xamarin Forms app to be deployed across Android and iOS platforms. We are facing this strange issue number of times. There is compile time error on InitializeComponent which didn't let code to compile. We have gone through almost all the stackoverflow questions and xamarin discussions on this topic. None to them helped.
Following is code-
DocumentSearchPage.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace FinderApp.Views
{
public partial class DocumentSearchPage : ContentPage
{
public DocumentSearchPage ()
{
InitializeComponent ();- This line show compilation issue- InitializeComponent doesn't exist in current context
}
}
}
DocumentSearchPage.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="FinderApp.Views.DocumentSearchPage">
<ContentPage.Content>
</ContentPage.Content>
</ContentPage>
Till now we have tried-
Changing property custom tool to different values
Checking if Namespace names are matching in xaml and cs file
Updated xaml forms to v2.3.0.38 pre2. Obiviously we have tried with stable version first.
Clean Rebuild solution
Enviroment
iMac OS X 10.11.2
Xamarin Studio 5.10.3
Xamarin Forms 2.3.038 pre2
We are facing issue on windows8, visual studio 2015 also.\
We have this issue with PCL approach too.
Expert help needed!

If you are using VS 2015, seems naive but this is the state even as of today, no reasons to explain, but as of Aug 2016 and latest xamarin this is the status
Close and repoen solution
Clean Solution
Rebuild Solution

Related

Prism Navigation is not working correctly

I just created a sample Android-XAMRIN project using Prism Template Pack. My base project in dot net standard 2.0 and I am using Prism.Unity.Forms 7.2.0.1367. While launching application it is showing blank page. I am attaching all images of project pages. AndroidProjProp.png
App_xaml App_xaml_cs
App_Proj_Prop MainActivity_cs MainPageViewModel Nuget_Installed ViewModelBase
You can follow Brian Lagunas's tutorial to create your app.
I followed his tutorial to createa a sample project, and run on my device, the result is showing a text Welcome to Xamarin Forms and Prism! .
The code of MainPage.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="BlankApp2.Views.MainPage"
Title="{Binding Title}">
<StackLayout HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand">
<Label Text="Welcome to Xamarin Forms and Prism!" />
</StackLayout>
</ContentPage>
Note
1.The difference is that we choose the value of container is Unity,just as follows:
Since it is a Xamarin Forms app,so we create user interfaces in XAML with code-behind in C#. and these interfaces are rendered as performant native controls on each platform. So the project pages is coded with format of XAML,not Activity(MainActivity) just as you mentioned.
For more information about Xamarin Forms, you can check: https://learn.microsoft.com/en-us/xamarin/get-started/what-is-xamarin-forms
Actually this was happening due to the current version of VS2017. I was using. I updated visual studio and it is working fine. Thanks

Can't Resolve Platform Effect in Xamarin Forms component

I am having issues with Platform Effects in Xamarin Forms. These effects worked in a shared library format, and we are now migrating to .NET Standard 2.0 for reasons outside of the scope of this post.
Project Setup
VS 2017 15.8.0
Xamarin Forms 3.1.0.697729
Two .Net Standard 2.0 projects (one is for components, the other for the main UI)
Two Android projects (one that runs, the other is an Android .dll)
Two iOS projects (same deal)
Main Issue
None of my platform effects in the Android .dll work. They all resolve as null effect.
According to the documentation, my setup is correct. (Documentation here)
I found two different issues and have hit a brick wall.
When I follow the instructions exactly and place [assembly: ResolutionGroupName("MyGroupName")] on the platform renderer itself, I get exceptions with Xamarin's dependency resolver. There is no message, just an exception and stack trace that leads back to the constructor of the RoutingEffect.
When I use a slightly different pattern and register that on the namespace of an empty file in my .NET Standard 2.0 project, all effects return as null effect.
I've been Googling and digging through forums to no avail. Does anyone have an idea what could be the problem?
Side notes: All of the custom renderers work after using the static Init() trick, but not the effects. I have also tried making the typeof() statement reference both the Android version of the class and the .NET Standard 2.0 version of the class.
For the sake of completeness, here's what I have going.
NET Standard 2.0:
namespace MyBaseNamespace.Components.Effects
{
public class SearchBarStylingEffect : RoutingEffect
{
public SearchBarStylingEffect() : base("MyGroupName.SearchBarStylingEffect")
{
}
}
}
Android:
[assembly: ResolutionGroupName("MyGroupName")]
[assembly: ExportEffect(typeof(SearchBarStylingEffect), "SearchBarStylingEffect")]
namespace MyBaseNamespace.Components.Android.Renderers.Effects
{
public class SearchBarStylingEffect : PlatformEffect
{
…
}
}
(iOS is the same as Android, only the namespace is different)
I also posted this on Xamarin's forums, and Billy Liu from Xamarin asked a question that ultimately led me down the right path. I'll link to that here and also post what fixed it.
link: Xamarin Forms Post
Here's the resolution from that post:
In short, I had to do the following things to get this functional
(which it now is):
Ensure that the GroupNameResolution tag was on the first Effect ever initialized in the app.
Remove the empty file initializer from my .Net 2.0 project.
???
Profit.

Xamarin Forms Prism Can't access PCL classes from android project

I'm using Xamarin Forms Prism and I can't use my PCL classes in android project.
common example :
here is the Interface in PCL
namespace BlankApp.Helpers
{
public interface IToast
{
void MakeLongToast(string msg);
}
}
and here is the class in android project
namespace BlankApp2.Droid.DependencyService
{
public class ToastImp : IToast
{
}
}
it can not find IToast Interface reference !
there is a suggest from IDE with this msg : "Reference 'projectname-WebAppMAinModule' and use 'projectname.Helpers.IToast' "
screenshot
which does nothing actually !
I don't have these kind of problems in XamarinForms I face theme while using Prism . Do I forget something in referencing my PCL ?
I'm using
Prism.Forms (7.0.0.396)
Xamarin.Forms (2.5.0.122203)
also there are my project dependencies
here
You should be able to implement PCL interfaces and use its classes, etc. in your platform specific code (Android included).
Use the following steps:
Make sure your Android project is referencing your PCL.
Delete your Android obj & bin folders.
Recompile your PCL
After recompiling your PCL, recompile your Android project
See if it recognizes your interface now.
If the above doesn't work, then as one last option is:
Close the solution
Re-open the solution
Both of these typically work when your project won't recognize a newly created Interface.

MVVM Cross iOS Sqlite issue: Plugin not registered for type Cirrious.MvvmCross.Community.Plugins.Sqlite (Community Sqlite Plugin version 3.1.1)

I am using Xamarin Studio with MVVM Cross 3.5.1 and recently upgraded SQLite to the Community Plugin (version 3.1.1) and although it works fine in Android and Windows Phone 8.1 the iOS project can't use SQLite anymore.
The bootstraper code looks like this out-of-the-box:
using Cirrious.CrossCore.Plugins;
namespace Compass.Mobile.iOS.Bootstrap {
public class SqlitePluginBootstrap
: MvxPluginBootstrapAction<Cirrious.MvvmCross.Community.Plugins.Sqlite.PluginLoader>
{
}
}
I looked at Question 20143457 but the code it refers to is no longer applicable.
Has anybody figured out how to resolve this yet?
I would recommend using the SQLite-PCL for MvvmCross plugin: https://github.com/MvvmCross/MvvmCross-Plugins/tree/master/SQLite-PCL
It is much more up to date. The bootstrap to use for it is:
public class SqlitePluginBootstrap
: MvxPluginBootstrapAction<MvvmCross.Plugins.Sqlite.PluginLoader>
{}
This error can occur if you do not bootstrap a PCL+platform-specific
plugin in the iOS-specific way.
According to the docs
Note: on AoT platforms (i.e. MonoTouch/Xamarin.iOS) the bootstrap
class used is slightly different - to assist the AoT process, it
references classes from both the PCL and the platform specific
Assemblies for the plugin like:
public class ColorPluginBootstrap
: MvxLoaderPluginBootstrapAction<Color.PluginLoader, Color.Touch.Plugin>
{
}
instead of the standard
public class ColorPluginBootstrap
: MvxPluginBootstrapAction<Color.PluginLoader>
{
}

Need to request the extended permission at the time of authentication only in facebook app development in .net

I am developing a facebook application in asp.net using the facebook developkit downloaded from codeplex.com website.
I am practicing a sample application in SDK 3.02\samples\IFrame.
They have give an attribute called RequiredAttribute = true in IFrameMaster.Master.cs, which will access the basic information.
But I want to request for extended permission in the same screen itself.
For that i have used this.
RequiredPermissions = new List<Facebook.Schema.Enums.ExtendedPermissions>() {
Facebook.Schema.Enums.ExtendedPermissions.publish_stream,
Facebook.Schema.Enums.ExtendedPermissions.offline_access };
But there is no use.
Is there any way to do it.
Thanks Guys,
Rakhy_Rakey.
Make sure you're setting your required permissions in the page class's constructor. Otherwise, I see no issue with your code.
Keep in mind that this Toolkit SDK has not been updated since April of 2010. And Facebook has made MANY changes since then. So I'd consider this project all but abandoned, perhaps resulting in things you expect to work not working.
However, you may want to look into this Facebook C# SDK, which looks very promising (with the last stable build coming at the end of October 2010).
I set the required permissions in the page class constructor. This is code:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Facebook;
using Facebook.Web;
using System.Collections.Generic;
using Facebook.Schema;
namespace IFrameSample
{
public partial class IFrameMaster : Facebook.Web.CanvasIFrameMasterPage
{
public IFrameMaster()
{
this.RequiredPermissions = new List<Facebook.Schema.Enums.ExtendedPermissions>() { Facebook.Schema.Enums.ExtendedPermissions.publish_stream, Facebook.Schema.Enums.ExtendedPermissions.offline_access };
this.RequireLogin = true;
}
}
}
The above code is in IFrameMaster.Master.cs. When I run the code, it is asking for only basic permissions, but it is not asking for extended permi

Resources