我只是 Xamarin 的新手,所以我尝试创建简单的 Phoneword 应用程序,网址为 Xamarin on-line guides .
在 Visual Studio 中创建的解决方案包含 4 个不同的项目:
- 包含所有共享代码的可移植类库 (PCL) 项目
- 一个包含 Android 特定代码的项目
- 一个包含 iOS 特定代码的项目
- 一个包含通用 Windows 平台 (UWP) 特定代码的项目
这是解决方案结构的样子:
现在在第一个项目中声明了一个接口(interface):
namespace Phoneword
{
public interface IDialer
{
bool Dial(string number);
}
}
我现在尝试在 UWP 项目中使用此界面:
using Phoneword.UWP;
using System;
using System.Threading.Tasks;
using Windows.ApplicationModel.Calls;
using Windows.UI.Popups;
using Xamarin.Forms;
[assembly: Dependency(typeof(PhoneDialer))]
namespace Phoneword.UWP
{
public class PhoneDialer : IDialer
{
...
构建解决方案成功结束。但是当我尝试部署 UWP 项目我收到此错误:
The type or namespace name 'IDialer' could not be found (are you missing a using directive or an assembly reference?)
谁能给我提示这个错误的根源是什么?
更新
我在尝试部署时又遇到一个错误:
Error DEP0700: Registration of the app failed. [0x80070005] error 0x80070005: Opening file from location: AppxManifest.xml failed with error: Access is denied.
我关闭了解决方案,退出 Visual Studio 启动并再次加载,第一个错误消失了。因此,从 UWP 项目中使用在代码共享项目中声明的接口(interface)似乎没有错。
我得到的实际错误是由于项目正在部署时文件夹的访问权限限制。
最佳答案
您没有在 PhoneDialer.cs
文件中引用 Phoneword
。将此添加到顶部:
using Phoneword; // <== Add this
using Phoneword.UWP;
using System;
using System.Threading.Tasks;
using Windows.ApplicationModel.Calls;
using Windows.UI.Popups;
using Xamarin.Forms;
关于c# - 无法从 UWP 项目中访问代码共享项目中定义的接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45190530/