Hamza Khalil
Hamza Khalil

Reputation: 481

The type or namespace name 'Xamarin' missing error in Xamarin Studio

I'm getting this error:

"MyApp\App.cs(7,7): Error CS0246: The type or namespace name 'Xamarin' could not be found (are you missing a using directive or an assembly reference?) (CS0246)".

I'm using Xamarin Studio to make a cross platform app via Xamarin.Forms. Whenever I build the basic form project I get this error and I don't know why.

I'm new in Xamarin.

Here is the code of app.cs:

using System;
using Xamarin.Forms;             //This is the line where error occurs

namespace FIrstFormProject
{
    public class App
    {
        public static Page GetMainPage ()
        {
            return new ContentPage 
            {
                Content = new Label 
                {
                    Text = "Hello, Forms !",
                    VerticalOptions = LayoutOptions.CenterAndExpand,
                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                },
            };
        }
    }
}

Upvotes: 30

Views: 92166

Answers (16)

Aleksei Burov
Aleksei Burov

Reputation: 43

I went to Visual Studio Installer and installed .Net classic apps package (sorry, i don't know exact name, because i have russian version) And it helped me.

enter image description here

Upvotes: 0

Koenigsberg
Koenigsberg

Reputation: 1798

Trivial solution to try before proceeding with more severe methods: Restart Visual Studio


The context in my case is that the solution was already compiling previously, yet stopped doing so after changes to the code. In my case all I did was change the XAML file, add a resource and reference said resource in the XAML file. Prior to this Xamarin.Forms was found, afterwards it was no longer found by Visual Studio for an unknown reason.

Restarting Visual Studio resolved the problem for me.

This is likely only relevant if Xamarin.Forms was found before and suddenly went missing, a restart is obviously unsuitable in fixing errors with the project setup.

This also sometimes (though not always) occurs when the Xamarin.Forms NuGet package is changed, i.e. a different one is installed for projects.

Upvotes: 1

Adam Hey
Adam Hey

Reputation: 1691

I have VS 2019 and I was prompted to update the Android SDK. After doing this I got a load of compiler errors including The type or namespace name 'Forms' does not exist in the namespace 'Xamarin' After updating my NuGet package to the latest version, the errors resolved (from 4.3.0.947036 to 4.3.0.991211)

Upvotes: 1

NikolaiT
NikolaiT

Reputation: 116

I had it today in the VS MAC.

Deleting the ".vs" hidden folder fixed it for me.

Upvotes: 3

Suplanus
Suplanus

Reputation: 1601

I have to combine some previous answers:

  • Reinstall Nugets (Xamarin.Forms)
  • Restart VS2019

Upvotes: 5

myroslav
myroslav

Reputation: 1778

After removing/reading Xamarin.Forms NuGet package two times and hot having this fixed, I had restarted my Visual Studio(15.9.0) and it worked. This was a brand new solution I created and started having this issue immediately.

Upvotes: 2

Saleem Kalro
Saleem Kalro

Reputation: 1142

  1. Go to "Manage NuGet Packages...
  2. View in Installed Tab
  3. If Xamarine.Forms package exist, update it.
  4. If not Go to Browse tab find Xamarine.Forms and install it.

Upvotes: 4

IvanH
IvanH

Reputation: 1

I had to uninstall and reinstall Nuget Xamarin.Forms in both the Android and PCL library.

Upvotes: 0

FabioSSena
FabioSSena

Reputation: 41

Select the solution & right click Go to Restore Manage Nuget Packages

Upvotes: 2

M Fatih Koca
M Fatih Koca

Reputation: 601

Do the following:

  1. Go to Manage NuGet Packages for Solution
  2. Remove Xamarin.Forms
  3. Reinstall Xamarin.Forms

Upvotes: 9

Nisargi Joshi
Nisargi Joshi

Reputation: 316

  • Select Solution & Right click.
  • Go to Manage Nuget packages for solution.
  • Go to updates.
  • if xamarin.forms is there, update it.

You are ready to work with xamarin.forms :)

Upvotes: 2

Vagner Gon
Vagner Gon

Reputation: 645

Look for your Target. Some targets aren't compatible with Xamarin.

Upvotes: 0

ebandersen
ebandersen

Reputation: 2352

MihaMarkic's post here led me to the right answer. For each project in your solution you'll need to do the following:

  1. Select the project in the Solution tab
  2. Select "Project" along the top menu
  3. Select "Add Nuget Packages..."
  4. Do a search for "Xamarin.forms"
  5. Add "Xamarin.forms" to that project

This is the workflow that got it working on my Mac. I'm not sure what the exact steps are for you PC users out there.

Upvotes: 57

David Douglas
David Douglas

Reputation: 10503

This happened when I removed the Xamarin.Android.Support.v4 and Xamarin.Forms library in order to downgrade to an earlier version. I got it working again by resetting the Droid packages.config to:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Xamarin.Android.Support.v4" version="22.1.1" targetFramework="MonoAndroid44" />
  <package id="Xamarin.Forms" version="1.4.2.6355" targetFramework="MonoAndroid44" />
</packages>

Then right-click the Droid Packages folder to Restore missing packages. The final step is to add the References > From Packages to the *.Droid.csproj

<Reference Include="Xamarin.Android.Support.v4">
  <HintPath>..\packages\Xamarin.Android.Support.v4.22.1.1\lib\MonoAndroid403\Xamarin.Android.Support.v4.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Platform.Android">
  <HintPath>..\packages\Xamarin.Forms.1.4.2.6355\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll</HintPath>
</Reference>
<Reference Include="FormsViewGroup">
  <HintPath>..\packages\Xamarin.Forms.1.4.2.6355\lib\MonoAndroid10\FormsViewGroup.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Core">
  <HintPath>..\packages\Xamarin.Forms.1.4.2.6355\lib\MonoAndroid10\Xamarin.Forms.Core.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Xaml">
  <HintPath>..\packages\Xamarin.Forms.1.4.2.6355\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Platform">
  <HintPath>..\packages\Xamarin.Forms.1.4.2.6355\lib\MonoAndroid10\Xamarin.Forms.Platform.dll</HintPath>
</Reference>

Upvotes: 0

Shyju M
Shyju M

Reputation: 9923

Do the following

  1. Install latest Microsoft .NET Portable Library Reference Assemblies.
  2. Extract the file in "C:\Program Files\Microsoft .NET Portable Library Reference Assemblies 4.6\PortableReferenceAssemblies.zip" to "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable" in 64bit and "C:\Program Files\Reference Assemblies\Microsoft\Framework.NETPortable" in 32 bit

3.Go to control panel select programs and features and right click xamarin choose repair. 4. Start xamarin studio again.

Upvotes: 0

Hamza Khalil
Hamza Khalil

Reputation: 481

I just had to add the Xarmin.Forms.Addin.dll in app's references. :) (Thanks @sam holder your hint in the comments led me to the answer.)

Upvotes: 6

Related Questions