I'm trying to set up a brand new Xamarin Android project where I can use Xamarin.Forms (with .NET Standard 2.0) for the UI and can use Xamarin Live Player to preview XAML/run it. I've been getting a strange error that I don't know how to resolve.
I create a New Project > Cross-Platform App (Xamarin) leaving the default name of "App1". I select a Blank App, with UI Technology set to Xamarin.Forms and Code Sharing Strategy to Portable Class Library (PCL).
The moment the solution is generated, I proceed to delete the iOS and UWP projects. I build the project and preview in Xamarin Live Player just fine.
Next, I create Add > New Project to the solution. I select a .NET Standard > Class Library (.NET Standard). I leave the default name as "ClassLibrary1". I click OK. I right-click the ClassLibrary1 project and Manage NuGet Packages..., then browse and install Xamarin.Forms (which is the same version as the PCL, which is 2.4.0.280).
Next, I copy and paste App.xaml and MainPage.xaml from the PCL (named App1 (Portable) into the ClassLibrary1 project.
Next, I delete the App1 (Portable) PCL project. This causes an error in the MainActivity.cs of App1.Android because the reference to App is not found. I right-click and add the ClassLibrary1 reference in App1.Android. Additionally, in MainActivity.cs, I add using ClassLibrary1;
This is what my App1.Android now looks like:
using System;
using ClassLibrary1;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace App1.Droid
{
[Activity(Label = "App1", Icon = "#drawable/icon", Theme = "#style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
}
}
The project builds just fine. But when I go to preview it in Xamarin Live Player, I get this weird error message:
The following errors were encountered when building and running your
app:
• MainActivity.cs: The type or namespace name 'ClassLibrary1' could
not be found (are you missing a using directive or an assembly
reference?) • MainActivity.cs: The type or namespace name 'App' could
not be found (are you missing a using directive or an assembly
reference?)
Can anyone tell me anything I can do to fix this error and get Xamarin Live Player to work?
I've additionally, tried doing a NuGet update on everything in the solution (nothing pre-release though) with no success.
I'm running Visual Studio 15.4.2. I've tried going to 15.5 (preview) and have had no luck.
Unfortunately, The Live player does not yet work on .Net Standard.
Ref: https://forums.xamarin.com/discussion/comment/303636
I think you need to add your newly created .netstandard project as a reference each of the platform specific project. Follow these two steps
Step 1:
Step 2:
17a: Right click Project(eg. Android project) -> 17b: Add -> 17c: Reference -> 18a: Tick the newly created project and click OK (this will basically tell your project that, it needs to add the .NETStandard project as a reference) and 18b: click OK to add as reference.
Repeat the same for Android, UWP & iOS.
At the same time, you have to ensure all projects installed with same version of Xamarin.Forms & .NET Standard 2.0.
You can refer to my written post on "Create Cross Platform Mobile App with .NET Standard 2.0" for steps that will guide you converting Xamarin.Forms from PCL to .NET Standard.
Related
I'm trying to set up a basic UWP project in Unity and use parts of the Windows namespace.*
However, no matter which part of the Windows namespace I try to import in my script, I always get
CS0246: The type or namespace name 'Windows' could not be found (are you missing a using directive or an assembly reference?)
Build support both for Windows and UWP is set up in Visual Studio and Unity and Windows 10 SDK (10.0.19041.0) is installed. Any other ideas how to fix this?
Based on https://forum.unity.com/threads/windows-storage-is-missing-when-building-for-uwp-hololens.541415/ I would have assumed that Windows is available in Unity for UWP as they were able to fix it there?
Thanks
*In the long run, I am trying to use 'Windows.Devices.Input.Preview' to access Gaze Input in a project that also uses Vuforia and thus needs to be UWP. Other tips on how to combine Gaze Tracking and Marker recognition in Unity are also welcome.
The Windows namespace in Unity is made for Windows PC build only. It won't work for other systems. On the top of the script try to add a
#if UNITY_STANDALONE_WIN
You should add the whole declaration like
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
Use SpeechRecognitionEngine class
#endif
If you are building for android or ios you will need also to add:
#if UNITY_ANDROID
Use SpeechRecognizer class
#endif
#if UNITY_IOS
Use SFSpeechRecognizer class
#endif
I have an Android app created in Xamarin.Forms (4.7.0) and I want to implement ads from AdMob into it. For that i have to create a ViewRenderer wrapper around a View class that I made earlier. As soon as i add this line into the ViewRenderer
[assembly: ExportRenderer(typeof(AdBanner), typeof(AdBanner_Droid))]
then build and launch the app, I get this error :
System.TypeLoadException: 'Could not load type DDKTCKE.Controls.AdBanner, APP_NAME, Version=1.2.2.0, Culture=neutral, PublicKeyToken=null while decoding custom attribute: (null)'
I already tried :
Deleteing bin and obj folders
Wiping data from test device
Cleaning the solution
A also used the exact same code in a new blank project and it worked as it should. What could be causing problems in my main project ? What should I look into ?
To implement the Android renderer, two classes are needed; an AdBanner class in the Forms project (or an Netstandard project as a project reference to the Forms project) and an AdBannerRenderer in an Android project:
AdBanner:
using Xamarin.Forms;
namespace MyProject
{
public class AdBanner: View
...
AdBannerRenderer:
using Android.Gms.Ads;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using AdBanner = MyProject.AdBanner;
[assembly: ExportRenderer(typeof(AdBanner), typeof(Droid.Renderers.AdBannerRenderer))]
namespace Droid.Renderers
{
public class AdBannerRenderer : ViewRenderer<AdBanner, AdView>
...
I created a new project and copied all my code from my old solution into it. Now everything works flawlessly.
So once again this was a problem with VS that just popped up for no good reason and took me a week to find a f̶i̶x̶ workaround. And people wonder how anyone could hate Visual Studio.
I have read all the similar posts here on stackoverflow and I'm still unable to resolve the issue.
These are my steps in Visual Studio 2015.
I create new project named "208" choosing Web -> ASP NET Web application (Net Framework)-> Empty
I right click on my project and choose Add -> New Item -> Web form
Just to test I create a new project in the same solution, a Class library solution and name it "MyClasses." Then I add a public class "Class1" with one public property.
I right click on the project "208" and add a reference to "MyClasses."
I add "using MyClasses;"
I build the project locally and it works fine.
I publish using FTP to my host and I get "CS0246: The type or namespace name 'MyClasses' could not be found..."
Both projects, "208" and "MyClasses" are built against Net Framework 4.6.1
The host has Net Framework 4.6.1
When published to the host, I can open the "bin" folder and I see the .dll file "MyClasses.dll" there.
Any suggestions are greatly appreciated.
The dll file is there when I publish:
Using added:
And the error (CS0246: The type or namespace name 'MyClasses' could not be found (are you missing a using directive or an assembly reference?):
I am just starting with xamarin to play around with it, and thought xamarin forms would be a good place to start to learn.
I began following this tutorial:
https://developer.xamarin.com/guides/xamarin-forms/templates/control-templates/creating/
which has a line as follows:
contentView.ControlTemplate = (originalTemplate) ? tealTemplate : aquaTemplate;
The problem for me is that my local code says that ContentView does not contain a definition for ControlTemplate.
The only xamarin related using statement in the document is:
using Xamarin.Forms;
I have the following declaration at the top of the class aswell:
ControlTemplate mainTemplate = new ControlTemplate(typeof(MainTemplate));
This has the error 'The type or namespace ControlTemplate could not be found'
When I try rebuild it throws that as an error, so it isn's just VS 2015 being slow.
I downloaded xamarin yesterday.
My JDK is 1.7.0_55.
My android SDK was downloaded yesterday (don't know where to find version)
My android NDk is version r10e.
Any suggestions are appreciated.
Thanks
Use Nuget manager in VS to be sure you have the latest version of the Xamarin Forms packages.
In Xamarin Studio on Mac OS X 10.10.2 I wrote a C# class that uses SQLiteConnection.
Xamarin complained about not knowing the class so I added using System.Data.SQLite;
Then when compiling Xamarin said:
The type or namespace name `SQLite' does not exist in the namespace `System.Data'.
Are you missing an assembly reference? (CS0234) (CmisSyncContextMenu)
So I opened Edit References and added the Mono.Data.Sqlite:
I clicked OK, pressed Rebuild all and... I get the exact same error message as above.
What am I doing wrong?
If you open References in the Solution window and double click Mono.Data.Sqlite you will see that it does not use the System.Data.Sqlite namespace but the Mono.Data.Sqlite namespace.
So you will either need to change the using statement in your code or use a different version of the Sqlite assembly, perhaps from NuGet.