首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xamarin.Forms错误找不到基础‘CS0246’

Xamarin.Forms错误找不到基础‘CS0246’
EN

Stack Overflow用户
提问于 2020-04-23 12:07:45
回答 1查看 672关注 0票数 1

我在Visual Studio2017中创建了一个应用程序(Xamarin.forms)。我想将wifi连接功能添加到我的iOS项目中(使用NEHotspotConfigurationManager),并在Mac上编译以下代码:

代码语言:javascript
复制
bool success = await UIApplication.SharedApplication.OpenUrlAsync(
NSUrl.FromString(UIApplication.OpenSettingsUrlString), options: new UIApplicationOpenUrlOptions());

var config = new NEHotspotConfiguration(ssid, password, isWep: false);
config.JoinOnce = false;
var tcs = new TaskCompletionSource<NSError>();
NEHotspotConfigurationManager.SharedManager.ApplyConfiguration(config, err => tcs.SetResult(err));
var error = await tcs.Task;
if (error != null)
{
    var alert = new UIAlertController
    {
        Title = "Error",
        Message = error.Description
    };
    alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
    PresentViewController(alert, true, null);
    return;
}

尽管当我右击红色的单词时,我可以看到"Add reference 'Xamarin.iOS.dll'“,但它仍然显示三个错误,即在我编译项目后找不到基础、UIKit和NetworkExtension。

代码语言:javascript
复制
Error CS0246 The type or namespace name 'Foundation' could not be found (are you missing a using directive or an assembly reference?)
Error CS0246 The type or namespace name 'UIKit' could not be found (are you missing a using directive or an assembly reference?)
Error CS0246 The type or namespace name 'NetworkExtension' could not be found (are you missing a using directive or an assembly reference?)

我用0.0.0.0版本的enter image description here检查iOS项目(Modbusbutton3.iOS)中引用列表中的'Xamarin.iOS‘

但是,项目(Modbusbutton3)中的引用'Xamarin.iOS‘为空。我不知道这是否与我的enter image description here问题有关

我发现项目(Modbusbutton3)中的引用'Xamarin.iOS‘显示红色错误"Assembly not found for framework .NET Protable Subset (.NET Framework4.5,Windows8,Windows phone8.1,Windows Phone Silverlight8)“enter image description here

我应该如何处理这个问题?

EN

回答 1

Stack Overflow用户

发布于 2020-04-25 07:26:40

你正在尝试做的事情的问题是,你需要理解关注点/抽象的分离。核心项目被Android & iOS项目引用,但是Android & iOS项目没有被核心项目引用。从原理上讲,

Core-->Android & Core-->iOS而不是Core<-x-Android, Core<-x-iOS

这是设计出来的,即使你可以让它做你正在尝试的事情,你也不应该做。

我们知道iOS和Android SDK有很大的不同。因此,为了执行wifi连接功能(NEHotspotConfigurationManager),您必须在底层执行不同的功能。您共享的代码是仅为iOS本机检索路径/文件名的正确方式。

为了让它工作,还有许多其他的方法,如官方Microsoft docs here中所示。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61379215

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档