Home > C# > Testing Code with the Mono Csharp REPL

Testing Code with the Mono Csharp REPL

I’m porting a full enterprise application to Mono so it can be deployed on Linux as requested by customers. I’m using the term “porting” loosely, because really, I just need to verify the existing code will run under Mono and make some minor adjustments so everything runs cross-platform. The Mono csharp read-evaluate-print-loop (REPL) has been an invaluable tool in this process.

Take Active Directory authentication for example. This is one of the areas that the Mono framework is not compatible with the .NET framework. You can see this right away in the csharp REPL, and then work out a quick alternative with the lower level DirectoryServices libraries. Just type ‘csharp’ at the terminal on a Linux system with Mono installed:

csharp> LoadAssembly("System.DirectoryServices.AccountManagement");
error CS0006: Metadata file `System.DirectoryServices.AccountManagement' could not be found

No worries – the AccountManagement API’s aren’t there on Linux – it’s good to be able to find this out right away (you can also check the Mono GAC, but this is REPL school). Now we just need to verify that a lower level call will work:

csharp> LoadAssembly("System.DirectoryServices");
csharp> DirectoryEntry adsEntry = new DirectoryEntry("LDAP://10.0.1.22/dc=mydomain,dc=local", "mydomain\\testUser", "testPa55w0rd");
csharp> var searcher = new DirectorySearcher(adsEntry);
csharp> var res = searcher.FindOne();
csharp> res.Properties;

It’s great to be able to do some quick API checks to understand and isolate compatibility issues right away. Go Mono REPL!

Advertisements
Categories: C#
  1. real
    September 14, 2012 at 6:52 am

    This does not work in ‘csharp’ for linux.

    • loosexaml
      September 14, 2012 at 7:35 am

      What errors are you getting?

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: