0

I am new in windows programming and I need to have communication between 2 projects(UWP and WinRT) in one solution. I was adding the reference of WinRT to my UWP one and now I can call methods from WinRT in UWP, but I need to do and vice versa, from UWP in WinRT , but if I try to add reference Visual Studio is showing an error dialog: Adding this project as reference would cause a circular dependecy that is quiet logic. So is there a way to make my bidirectional communication even possible?

EDIT

I was trying proposed solutions:

  • I created a SharedProject that contain one C# class like:

    namespace SharedProject { public interface Iuwp { void myMethodInWinRT(); } public interface Iwinrt { void myMethodInUWP(); } }

  • I added SharedProject references to both projects: WinRT and UWP;

  • I implemented myMethodInWinRT() in WinRT project and myMethodInUWP() in UWP project;

  • As it's metioned here I'd like to call myMethodInWinRT() from UWP project and myMethodInUWP() from WinRT project but I' getting stuck, how should i use that interfaces to call methods inside them?

Community
  • 1
  • 1
Vasile Doe
  • 1,674
  • 1
  • 24
  • 40
  • 2
    Create shared project which defines common interfaces to be shared with both projects. Implementation of those interfaces will reside in each of the project. – Sriram Sakthivel Feb 23 '16 at 10:08
  • http://stackoverflow.com/questions/14048235/circular-dependency-in-two-projects-in-c-sharp. Refer the link, it has the same problem. You probably should use a event to communicate between these two sections rather than accessing them via project reference – Carbine Feb 23 '16 at 10:10
  • @Sriram Sakthivel I'm not sure if I understand your idea, but think that it's something like in my edited post, can you provide one more "step into" please – Vasile Doe Feb 23 '16 at 12:46
  • Yes your approach is correct. You just need to give the instance of specific type to another project to work with. That said, I'm not sure that UWP and WinRt can go hand in hand. But it works for general case. – Sriram Sakthivel Feb 23 '16 at 13:52

1 Answers1

0

You can't reference a Windows App project to another one, instead, I'd recommended to create a WinRT Component project or a shared PCL project and share your codes and interfaces as @Sriram, so you can call functions, init it with your two projects..

UPDATE:

Make sure that your classes are public and your voids are public too, Then add a reference from your UWP/ WinRT App to your shared project then you can call it, don't forget to create an instance of your class, i.e.(

MyClass class = new MyClass();
class.MyUWPVoid();

)

Nasser AlNasser
  • 1,725
  • 2
  • 11
  • 12