c# - 无法从 UWP 项目中访问代码共享项目中定义的接口(interface)

标签 c# android xamarin uwp

我只是 Xamarin 的新手,所以我尝试创建简单的 Phoneword 应用程序,网址为 Xamarin on-line guides .

在 Visual Studio 中创建的解决方案包含 4 个不同的项目:

  1. 包含所有共享代码的可移植类库 (PCL) 项目
  2. 一个包含 Android 特定代码的项目
  3. 一个包含 iOS 特定代码的项目
  4. 一个包含通用 Windows 平台 (UWP) 特定代码的项目

这是解决方案结构的样子:

enter image description here

现在在第一个项目中声明了一个接口(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/

相关文章:

c# - 如何 : Project Organization and Output

c# Intersection 和 Union 不能正常工作

c# - 如何在 C# 中正确切换枚举?

Xamarin iOS : How to add properities into info. plist 源部分

xamarin - Xamarin 中的 Gradle 依赖项

c# - 数组的第二个元素发生了什么?

android - 强行关闭网络浏览器

android - float 弹出窗口-如何实现

android - 带有异步任务的进度对话框

android - Xamarin Android 应用程序在 Release模式下崩溃(未找到默认构造函数)