This project is read-only.

UPDATE 12/20/2012

Some major additions have been added to the project and we've moved over to TFS. The latest update includes all of the following highlights. As well, chitrarasan has joined the project as a developer to continue growing the project, welcome chitrarasan!
  • IOrganizationService service pool that can lazy load N number of service instances (against 1 or more CRM environments) that can be easily pulled from and recycled back into the singleton Services implementation. This is great for running multithreaded operations because the IOrganizationServiceProxy that the CRM SDK uses is not thread safe, so any multi threaded processes (migration applications especially) cannot use the IOrganizationService in multiple threads without wiring up a new one for each thread. The service pool allows multithreaded applications with a lot of I/O operations to run at 10 times the speed or more.
  • Greatly improved logging support. Rebuilt the tracing library from the ground up to utilize the Apache log4net library in a more CRM centric, flexible manner.
  • Additional extension methods - I’ve added a lot of extension methods for doing common operations with the IOrganizationService, EntityCollection, SqlConnection, and other classes.
  • Extension libraries and adapter support - I’ve started work on a library for doing integration applications and have built support for CRM 4.0 apps (allows writing native 2011 .NET 4 for the CRM 4.0 version).

For the most part, all of these new features are backwards compatible with the exception of the new logging / tracing features. Most projects should be easy to convert over with Visual Studio tools.

Please build from source if you want to use the latest and greatest version, the binary download has not yet been updated to the latest version since I haven't had time yet to update all of the documentation for it. I highly recommend working with the latest version in source.

Project Description

The XrmLibrary is a .NET 4 C# class library that can be used for rapid integration with one or more Microsoft Dynamics CRM 2011 environments. The library contains a thread-safe singleton implementation of the CRM 2011 IOrganizationService (1 or many instances) and a global "Tracer" that utilizes Apache's log4net for enterprise class tracing and logging support.


  • Extension methods for common operations. XML commented for full IntelliSense support.
  • Support for multiple organization service endpoints in a single project.
  • Support for all models of Microsoft CRM 2011 (AD/IFD/CRM Online).
  • Lightweight - gives direct access to the IOrganizationService without wrapping it inside another object.
  • Utilizes Apache's log4net for quick and easy tracing and logging -


  • Rapidly wire up an IOrganizationService and retrieve all contacts with first name "John".
using(var service = Services.Instance.OrganizationService)
    IEnumerable<Entity> johnContacts = service.RetrieveRecords("contact", "firstname", "John");

  • Retrieve a contact, and remove the "Marketing User" role if the user has it.
using(var service = Services.Instance.OrganizationService)
    // Retrieve first user named John.
    Entity user = service.RetrieveRecords("contact", "firstname", "John").First();

    // Retrieve all roles for this user.
    IEnumerable<Entity> roles = service.RetrieveAllRolesForUser(user);

    // Iterate the roles and remove the "Marketing User" role if it exists.
    foreach (Entity role in roles)
        if (role.GetAttributeValue<String>("name") == "Marketing User")
            service.RemoveRoleFromUser(user.Id, role);

  • UPDATE 12/20/2012 Get an IOrganizationService from the service pool, use it, then recycle it.
// Get a service instance for a source organization (pulls from application config) and log results with new updated logger.

var service = Services.Instance.GetOrganizationServiceFromPool();
String details = service.WhoAmI().GetDetails();

// Log details of the WhoAmI request.
LogContext ctx = LogContext.InstantiateInfo(details);

Please visit the Documentation page for details on setup and full documentation of all extension methods offered by the XrmLibrary.

Last edited Dec 20, 2012 at 4:35 PM by cchamberlain, version 16