【问题标题】:System could not be found, Xamarin.Forms not found找不到系统,找不到 Xamarin.Forms
【发布时间】:2021-05-05 16:12:24
【问题描述】:

严重性代码描述项目文件行抑制状态 错误 CS0246 找不到类型或命名空间名称“System”(您是否缺少 using 指令或程序集引用?) Beer Garden1 C:\Users\henry\source\repos\Beer Garden1\Beer Garden1\Beer Garden1\ViewModel \LoginViewModel.cs 3 活动

严重性代码描述项目文件行抑制状态 错误 CS0246 找不到类型或命名空间名称“Xamarin”(您是否缺少 using 指令或程序集引用?) Beer Garden1 C:\Users\henry\source\repos\Beer Garden1\Beer Garden1\Beer Garden1\ViewModel \LoginViewModel.cs 7 活动

我目前收到上述错误,但不确定原因。我花了几个小时查看堆栈溢出和谷歌,但没有任何工作,

清理解决方案、重建、构建重新加载都不起作用。

修复visual studio没有用

我很难过请任何帮助将不胜感激!

using Beer_Garden1.Services;
using Beer_Garden1.View;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using Xamarin.Forms;

namespace Beer_Garden1.ViewModel
{
    public class LoginViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
    public Command cmdLogin { get; set;  }
    public Command cmdCreateAccount { get; set; }
    public Command cmdForgotPassword { get; set; }
    public Command cmdSetting { get; set; }

    ILoginService ilog = DependencyService.Get<ILoginService>();

    public LoginViewModel()
    {
        cmdLogin = new Command(gotoMainPage);
        cmdCreateAccount = new Command(gotoCreateAccount);
        cmdForgotPassword = new Command(gotoForgotPassword);
        cmdSetting = new Command(gotoSetting);
        
    }

    private void gotoSetting(object obj)
    {
        App.Current.MainPage.Navigation.PushAsync(new SettingPage());
    }

    private void gotoForgotPassword(object obj)
    {
        App.Current.MainPage.Navigation.PushAsync(new ForgotPasswordPage());
    }

    private void gotoCreateAccount(object obj)
    {
        App.Current.MainPage.Navigation.PushAsync(new CreateAccountPage());
    }

    private void gotoMainPage(object obj)
    {
        if (ilog.login(UserName, Password))
        {
            App.Current.MainPage.Navigation.PushAsync(new MainPage());
        }
        else
        {
            LoginMessage = "Please enter a valid user name and password!";
            TurnLoginMessage = true;
        }

    }
    //-------------------------------------------------------------
    private string userName;
    public string UserName
    { get 
        { 
            return userName; 
        } 
        set 
        { 
            userName = value;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("UserName"));
        } 
    }

    private string password;
    public string Password
    {
        get
        {
            return password;
        }
        set
        {
            password = value;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Password"));
        }
    }

    private string loginMessage;
    public string LoginMessage
    {
        get
        {
            return LoginMessage;
        } set
        {
            loginMessage = value;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LoginMessage"));
        }
    }

    private bool turnLoginMessage = false;
    public bool TurnLoginMessage
    {
        get
        {
            return turnLoginMessage;
        }
        set
        {
            turnLoginMessage = value;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("TurnLoginMessage"));
        }
    }
}

}

_________________________________________________________________________________更新::

我设法修复了包源问题,它现在正在接受 xamarin.forms 和系统,但在 using System.Collections.Generic; 下抛出错误 using System.ComponentModel; using System.Text;

还原 NuGet 包时出现以下错误

NU1603: Beer Garden1.iOS depends on Xamarin.Forms (>= 4.8.0.1451) but Xamarin.Forms 4.8.0.1451 was not found. An approximate best match of Xamarin.Forms 5.0.0.2012 was resolved.
NU1102: Unable to find package System.Numerics.Vectors with version (>= 4.5.0)
  - Found 2 version(s) in Microsoft Visual Studio Offline Packages [ Nearest version: 4.1.1 ]
NU1603: Beer Garden1.Android depends on Xamarin.Essentials (>= 1.5.3.2) but Xamarin.Essentials 1.5.3.2 was not found. An approximate best match of Xamarin.Essentials 1.6.1 was resolved.
NU1603: Beer Garden1.Android depends on Xamarin.Forms (>= 4.8.0.1451) but Xamarin.Forms 4.8.0.1451 was not found. An approximate best match of Xamarin.Forms 5.0.0.2012 was resolved.
NU1102: Unable to find package System.Numerics.Vectors with version (>= 4.5.0)
  - Found 2 version(s) in Microsoft Visual Studio Offline Packages [ Nearest version: 4.1.1 ]
NuGet package restore failed. Please see Error List window for detailed warnings and errors.
Time Elapsed: 00:00:00.1797576

【问题讨论】:

  • 你恢复了 NuGet 包吗?
  • using System; System 添加到您要使用的项目中。与 Xamarin 相同。当它说Are you missing a directive or assembly reference? 时,请听。这意味着你没有引用你的项目试图使用的东西。
  • 我恢复了 NuGet 包,但它没有做任何事情,我同时使用 xamarin.forms 和系统
  • 进行编辑以向您显示文件,此错误不仅出现在此文件上,而且出现在整个项目中,并且此错误在新项目中仍然存在
  • @Jason 这是我在尝试恢复 NuGet 包时收到的错误Error occurred while restoring NuGet packages: Failed to retrieve information about 'NETStandard.Library' from remote source 'https://packagesource/FindPackagesById()?id='NETStandard.Library'&amp;semVerLevel=2.0.0'.

标签: c# xamarin xamarin.forms xamarin.android xamarin.ios


【解决方案1】:

我最终解决了我的问题,我从%appdata% 中删除了 NuGet 文件夹,然后在 VS 启动时使用其默认值重新创建它,我只需要运行 NuGet 包还原,它就删除了我的所有 98 个错误和我的 13 条警告。

我希望这对遇到相同问题的人有用,因为我自己在网上很难找到解决方案。

感谢大家的帮助!

【讨论】:

    猜你喜欢
    • 2021-11-12
    • 2014-02-28
    • 2018-08-15
    • 1970-01-01
    • 2017-03-06
    • 1970-01-01
    • 2015-06-01
    • 2019-02-27
    • 1970-01-01
    相关资源
    最近更新 更多