CRM 2011 – Sample Visual Studio Projects contain more than one entry point

I had a noddy error today in visual studio but they are always frustrating when you are trying to translate the error into what you have to do to fix the darn thing.  They always offer you hints in the right direction but never tell you definitely where to go.

Error      1              Program ‘c:\users\ben.hosking\documents\visual studio 2010\Projects\CRM\MetaData Extract\MetaData Extract\obj\x86\Debug\MetaData Extract.exe’ has more than one entry point defined: ‘MetaData_Extract.Program.Main(string[])’.  Compile with /main to specify the type that contains the entry point.                c:\users\ben.hosking\documents\visual studio 2010\Projects\CRM\MetaData Extract\MetaData Extract\Program.cs         23           21           MetaData Extract

This was a pretty straight forward problem, it’s saying my project has many entry points.  At this point I was just trying to get some of the CRM samples to work.

Finally I figured out that I had a few console type applications which were all self running code, e.g. more than one of my classes had a main function and Visual studio was saying it didn’t know which one to run first.

The way to fix this is to right click on the project

Select one of the classes in the Startup object.

This is also a good tip for running the CRM 2011 samples.  I was looking at the entity project.  This included 5 different class files.

The problem I had I wasn’t sure what class was going to run first, on web applications you set a default page to run first but I wasn’t sure

What happened when you had multiple classes in a console project.

Well the answer as I’m sure most of you already knew was you go into the project properties and select the start up object.

You live and learn people.  This is one example of noddy things I have missed out on because I didn’t go through the learning basics of .NET and was working on projects which were already half built.  I find I have some stupid and basic gaps in my knowledge but thanks to working on CRM 2011 I am learning some of the basics and some of the new functionality in .NET 4, like Linq etc.


CRM 2011 – You can now add tracing to your plugins

I have been looking at creating my first plugin in CRM 2011.  As usual with CRM, things are always a bit of mystery until you have created that first working example

I will talk about plugins in future blogs but at the moment I am just going to talk about the ITracingService feature that has been added.

it’s basically a new feature which allows you to put out some tracing whilst you are developing the plugin and if the plugin throws an exception in the code it will not only put out the error but will put out the tracing comments so you can get an idea of how far it got within your plugin code

//Initialize the service
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

once you have initialized the service you then just need to create messages in your code


This webpage has a great explanation of the new ITracingService feature

MSCRM 2011 – Useful ITracingService addiion when creating plugin assemblies.

So i started working on upgrading our plugin assemblies today to work in the isolated mode “Sandbox” for the CRM Online deployments. whilst browsing the SDK i came across a great new tracing tool for debugging the code called ITracingService this service alows a trace log to be generated at runtime. see the following code example and the output.

using System;
using System.ServiceModel;
// Microsoft Dynamics CRM namespace(s)
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Crm.SdkTypeProxy;
namespace Kms.Xrm.Plugin.OnlineTestPlugin
 public class FollowupPlugin: IPlugin
 /// <summary>
 /// A plugin that creates a follow-up task activity when a new account is created.
 /// </summary>
 /// <remarks>Register this plug-in on the Create message, account entity,
 /// and asynchronous mode.
 /// </remarks>
 public void Execute(IServiceProvider serviceProvider)
 //Extract the tracing service
 ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
 if (tracingService == null)
 throw new InvalidPluginExecutionException("Failed to retrieve the tracing service.");

 // Obtain the execution context from the service provider.
 IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

 // The InputParameters collection contains all the data passed in the message request.
 if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
 // Obtain the target entity from the input parmameters.
 Entity entity = (Entity)context.InputParameters["Target"];
// Verify that the target entity represents an account.
 // If not, this plug-in was not registered correctly.
 if (entity.LogicalName != "account")
// Obtain the organization service reference.
 IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
 IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
tracingService.Trace("01 - Hosk tracing started..");
 tracingService.Trace("02 - about to do query expression");

 //Query Project Link Settings
 QueryExpression query = new QueryExpression(" account ");
 ColumnSet cols = new ColumnSet();
 cols.AllColumns = true;
 query.ColumnSet = cols;

 EntityCollection settings = service.RetrieveMultiple(query);
foreach (Entity ent in settings (plus [s)
 tracingService.Trace(" account name " + ent.attributes["name"] &quot);

 tracingService.Trace("The Plugin tracing has finished ..");
throw new InvalidPluginExecutionException("Hosk account plugin has finished running 🙂 ");

 catch (FaultException<OrganizationServiceFault> ex)
 throw new InvalidPluginExecutionException("An error occurred in the Hosk Test plug-in.", ex);

The output can be seen below. If coded correctly the end user can supply much more detailed information to support. this obviously saves time on the searching trace files and error messages…

below is an image from a great blog post on tracing from inogic

tracing description