Forum Cross Platform with Xamarin
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How may I use the same file for two particular platforms? (iOS, Android)

CollinIrwinCollinIrwin USMember ✭✭

EDIT: See my own replies below.

My question's reason for existence:

I'm working on a Xamarin cross platform app (using PCL + forms), and I need to use System.Security.Cryptography and System.Net.Sockets. My PCL does not let me use either of these. My PCL is profile 78. I only intend to develop for mobile devices (iOS, Android) in particular. Windows phone would be a cherry on top, but is definitely not a requirement. I know that Android and iOS support both of these namespaces. I could simply use the DependencyService and put the same exact file in both my platform ios and platform droid folders, but then every time I edit one I would have to copy paste to the other.

My question:
How can I either:

A. Modify my PCL to let me use System.Net.Sockets and System.Security.Cryptography

B. Use the same C# file for both iOS and Android (i.e. my AES class or my Communications class that I currently believe I have to copy-paste in two places).

C. Some other alternative that you may notice while reading this post.

Best Answer


  • CollinIrwinCollinIrwin USMember ✭✭
    edited May 2015

    Well... I think I found the answer to using the same C# file in multiple platforms, or rather the solution to my ultimate question of using System.Crypto and System.Sockets:

    For some reason I didn't think you could do both PCL and Shared in the same solution. I was wrong there. I also didn't realize that the option for making these directories was under the Add New Project - > .Net, I expected it to be under Cross-Platform.

    I still don't know how to modify my PCL's assemblies, but that isn't needed any more so I'll push that off for later.

  • CollinIrwinCollinIrwin USMember ✭✭
    edited May 2015

    Okay so now I have a PCL, with viewmodels for Xamarin.Forms, a shared project, and platform projects.

    The PCL's viewModels need to make use of the classes in the shared project, but I must be missing something as I am getting "The type or namespace could not be found. Are you missing an assembly reference?

    But I can't include the reference because then my shared project loses its ability to access System.Net.Sockets and System.Security.Cryptography

    I'm beginning to feel like it would be easier to just make the whole project a shared project rather than messing around with part PCL/part shared project. I am also seemingly losing understanding of why PCL is useful in the first place. Is it purely a tool that limits you to only a specific subset of .NET?

Sign In or Register to comment.