Cannot access Interface defined in the Code Sharing Project from within UWP project

1

I am just a newbie in Xamarin, so I tried creating the simple Phoneword application available at Xamarin on-line guides.

The solution created in Visual Studio comprises 4 distinct Projects:

  1. A portable class library (PCL) project that holds all of the shared code
  2. A project that holds Android specific code
  3. A project that holds iOS specific code
  4. A project that holds Universal Windows Platform (UWP) specific code

This is how the solution structure looks like:

enter image description here

Now inside the first project an interface has been declared:

namespace Phoneword
{
    public interface IDialer
    {
        bool Dial(string number);
    }
}

I now try to use this interface from within the UWP project:

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
    {
      ...

Building the solution ends successfully. But when I try to Deploy the UWP project I get this error:

The type or namespace name 'IDialer' could not be found (are you missing a using directive or an assembly reference?)

Can anyone give me hint on what could be the source of this error?

Update

There was one more error I was getting when I tried to deploy:

Error DEP0700: Registration of the app failed. [0x80070005] error 0x80070005: Opening file from location: AppxManifest.xml failed with error: Access is denied.

I closed the solution, exited Visual Studio started and loaded again and the first error disappeared. So, it seems, there is nothing wrong in consuming an interface, declared in the Code Sharing Project, from within the UWP Project.

The actual error I was getting was due to access rights restrictions of the folder were the project was being deployed.

c#
android
xamarin
uwp
asked on Stack Overflow Jul 19, 2017 by Giorgos Betsos • edited Jul 24, 2017 by Giorgos Betsos

4 Answers

1

You are not referencing the Phoneword in your PhoneDialer.cs file. Add this to the top:

using Phoneword; // <== Add this
using Phoneword.UWP;
using System;
using System.Threading.Tasks;
using Windows.ApplicationModel.Calls;
using Windows.UI.Popups;
using Xamarin.Forms;
answered on Stack Overflow Jul 19, 2017 by Jon Stødle
0

I had a similar issue. The way to fix it is just to restart Visual Studio or reload the solution.

answered on Stack Overflow Apr 15, 2018 by Nweke • edited May 1, 2018 by Stephen Kennedy
0

I had the same problem, Add this to your code at the top

using static Phoneword.MainPage;

and it should work fine The reason it was not working is because you didn't have a reference to it. For some reason the Assets that you import for that course do not have this reference in it.

answered on Stack Overflow May 17, 2018 by Coding420Blazed
0

Had the same problem. You need to right click on the Phoneword project in the Solution Explorer and click build to build it on it's own.

Then add the using statement for the Phoneword project to your PhoneDialer file.

The reference to IDialer then becomes available.

answered on Stack Overflow Jul 13, 2018 by Dean Puckett

User contributions licensed under CC BY-SA 3.0