Create a new default project and getting erros from MainActivity.cs
Error CS0234 ...namespace "Content" not exist in namespace "Xamarin.Android"
Missing somethings ?
My fault I think, now are ok
...OnRequestPermissionsResult(... [GeneratedEnum] Permission[] grantResults)
Related
I've been following this guide in order to integrate Microsoft AppCenter in my xamarin.Forms App but it kept throwing error saying:
The type or namespace name 'Start' does not exist in the namespace 'AppCenter' (are you missing an assembly reference?)
on calling AppCenter.Start().
Here is my code in App.xaml.cs:
protected override void OnStart()
{
AppCenter.Start(
"ios={Your App Secret};macos={Your App Secret};android={Your App Secret};uwp={Your App Secret};windowsdesktop={Your App Secret}",
typeof(Analytics),
typeof(Crashes));
}
I am trying to make my Xamarin Project use MVVM with Prism and DryIoc.
I mostly want to use AutoRegistration like below:
[AutoRegisterForNavigation]
...
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
//Pages
containerRegistry.RegisterForNavigation<NavigationPage>();
//Services
containerRegistry.RegisterSingleton<ILocalDatabase, LocalDatabase>();
containerRegistry.RegisterSingleton<IUserProfileDataStore, UserProfileDataStore>();
containerRegistry.RegisterSingleton<IApplicationSettings, ApplicationSettings>();
containerRegistry.RegisterSingleton<ILogger, Logger>();
containerRegistry.RegisterSingleton<IApiService, ApiService>();
containerRegistry.RegisterSingleton<IUserSession, UserSession>();
containerRegistry.Register<IBrowser, BrowserImplementation>();
containerRegistry.Register<IConnectivity, ConnectivityImplementation();
containerRegistry.Register<IFileSystem, FileSystemImplementation>();
containerRegistry.Register<ICoreServices, CoreServices>();
}
I have also tried Manual Registration:
containerRegistry.RegisterForNavigation<LoginPage, LoginPageViewModel>();
Neither works, It hits the Login Page code behind then breaks with the following error:
Exception - High: Prism.Ioc.ContainerResolutionException:
An unexpected error occurred while resolving 'AppetiteApp.ViewModels.LoginPageViewModel' --->
DryIoc.ContainerException: code: UnableToResolveUnknownService; message: Unable to resolve
Resolution root AppetiteApp.ViewModels.LoginPageViewModel
with passed arguments [value(Prism.Navigation.ErrorReportingNavigationService)]
**System.NullReferenceException:** 'Object reference not set to an instance of an object.'
I've also tried using a Linker file setting it's build action to "linkdescription"
As for my Login Page here is the declaration
public LoginPageViewModel(ICoreServices coreServices)
: base(coreServices)
The constructor of LoginPageViewModel requires the ICoreServices argument which is registered.
The error message says that the LoginPageViewModel itself is unknown to the IoC - it means the type LoginPageViewModel is not directly registered and not found through dynamic registrations or unknown service resolvers.
I am not a user of the Xamarin Prism so I am not sure about its mechanism for registering the view models.
Btw, this part of error
Resolution root AppetiteApp.ViewModels.LoginPageViewModel
with passed arguments [value(Prism.Navigation.ErrorReportingNavigationService)]
basically means the view-model was resolved via the foollowing call resolver.Resolve(typeof(LoginPageViewModel), args: new[] { errorReportingNavigationService })
Hope it will help you or someone knowledgeable in Xamarin to track the error cause.
So Once I investigated Inside of ICoreServices I commented out each of the dependencies then discovered that IUserSession was the once causing problems then I dug into that and discovered that the dependences for IAppInfo and IVersionTracking were missing in the App.Xaml.cs registr tyepes so I added that and then it worked!
containerRegistry.Register<IAppInfo, AppInfoImplementation>();
containerRegistry.Register<IVersionTracking, VersionTrackingImplementation>();
I'm getting an exception on a Xamarin Forms content page with Xaml, on the initializecomponent method. The exception occurs on the generated xaml.gs page. I haven't changed any code form a working version. Maybe something upstream has changed. The exception message is ""
Value cannot be null.
Parameter name: binding
stack trace:
at Xamarin.Forms.BindableObject.SetBinding (Xamarin.Forms.BindableProperty targetProperty, Xamarin.Forms.BindingBase binding, System.Boolean fromStyle) [0x00011] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:293
at Xamarin.Forms.BindableObject.SetBinding (Xamarin.Forms.BindableProperty targetProperty, Xamarin.Forms.BindingBase binding) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:117
at ....LoginPage.InitializeComponent () [0x00045] in ...\obj\Debug\netstandard2.0\Views\Navigation\Login.xaml.g.cs:34
at FieldServices.LoginPage..ctor () [0x0002b] in ..\Views\Navigation\Login.xaml.cs:25
where occurrs:
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")]
private void InitializeComponent() {
global::Xamarin.Forms.Xaml.Extensions.LoadFromXaml(this, typeof(LoginPage));
email = global::Xamarin.Forms.NameScopeExtensions.FindByName(this, "email");
password = global::Xamarin.Forms.NameScopeExtensions.FindByName(this, "password");
loginButton = global::Xamarin.Forms.NameScopeExtensions.FindByName(this, "loginButton");
}
I rarely get this error when pulling code down. First, double-check that your code is fine. In this case, I would make sure all the bindings are named correctly with no typos.
In the event that you cannot find an error and are thoroughly convinced there is nothing wrong with the code, try steps like
Clean and Rebuild
Close your Visual Studio and restart it
Hopefully the error is solved as easy as this.
On top of cleaning and rebuilding, manually delete all the obj and bin folders from your solution directory. Those xaml.gs files are generated files and sometimes they seem to not regenerate when they should.
I'm getting an exception on a Xamarin Forms content page with Xaml, on the initializecomponent method. The exception occurs on the generated xaml.gs page. I haven't changed any code form a working version. Maybe something upstream has changed.
It is not reproduceable by myside, but per experience there are a few things you can try:
Put your project in a short path like "C:\".
Try a new blank project, see if the error occors.
If none of the above works, you can try reinstalling Xamarin in your VS.
This was solved due to my not linking a static resource that was declared in the xaml
I found an issue with localization in WinPhone app. I added couple of resources and implemented localization. It is working fine in simulator, but crashing on Phone with exception Exception thrown: 'System.Resources.MissingManifestResourceException' in mscorlib.ni.dll
Any help?
Thanks to a bit of googling and a helpful blog post I have managed to solve this issue that happened intermittently with Xamarin.Forms projects.
This is the blog post that led me to the solution:
http://blog.tpcware.com/2016/06/xamarin-forms-localization/
Basically, the way you access resources on Android and iOS with Xamarin.Forms and Windows Phone is different:
To make it short, we need to “automagically” use the ResourceLoader.GetString(…) method when running on Store apps, while continuing to use the regular ResourceManager.GetString(…) method on all other platform. And because in the Xamarin Forms solution we use a resource file of type RESX, we also have the automatically generated resource class.
The super clever idea contained in the above linked post is to “hack” the resource class injecting a derived class of ResourceManager with an overridden GetString(…) method into the resource class “resourceMan” property (for a more detailed explanation of this hack, you can read the post).
We need to create our own version of ResourceManager like so and swap it for the existing ResourceManager using reflection:
public class WinRTResourceManager : ResourceManager
{
readonly ResourceLoader _resourceLoader;
private WinRTResourceManager(string baseName, Assembly assembly) : base(baseName, assembly)
{
_resourceLoader = ResourceLoader.GetForViewIndependentUse(baseName);
}
public static void InjectIntoResxGeneratedApplicationResourcesClass(Type resxGeneratedApplicationResourcesClass)
{
resxGeneratedApplicationResourcesClass
.GetRuntimeFields()
.First(m => m.Name == "resourceMan")
.SetValue(null, new WinRTResourceManager(
resxGeneratedApplicationResourcesClass.FullName,
resxGeneratedApplicationResourcesClass.GetTypeInfo().Assembly));
}
public override string GetString(string name, CultureInfo culture)
{
return _resourceLoader.GetString(name);
}
}
All that's then left to do is call this when the app starts for the first time:
WinRTResourceManager.InjectIntoResxGeneratedApplicationResourcesClass(typeof(AppResources));
After making these changes everything should work fine now.
Of course this is absolutely a hack but I have notified the Xamarin.Forms team of the issue and they are looking into it so hopefully it will be solved soon!
I am trying to build an application using Xamarin and I want to use G+ button in App. I also added Google Play Services Component still not able to build successfully.
Error:
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'IGoogleApiClientConnectionCallbacks' could not be found (are you missing a using directive or an assembly reference?) Taap C:\Users\Home\Documents\Visual Studio 2015\Projects\Taap\Taap\MainActivity.cs 18 Active
In your Taap\MainActivity.cs add and implement both of those interfaces to/within your Activity:
Example:
public class MainActivity : Activity, GoogleApiClient.IConnectionCallbacks, GoogleApiClient.IOnConnectionFailedListener
Implement IConnectionCallbacks:
void OnConnected (Bundle connectionHint);
void OnConnectionSuspended (int cause);
Note: This is in the Android.Gms.Common.Apis namespace
using Android.Gms.Common.Apis;
Implement IOnConnectionFailedListener
void OnConnectionFailed (ConnectionResult result);
Note: This is in Android.Gms.Common namespace:
using Android.Gms.Common;