Microsoft CRM - Plugin debugging problem

apollo7 used Ask the Experts™
Hi, I am working on a complicated team project where I am not able to debug the code.  I am working with VS 2015 in a TFS environment and XrmToolKit to check in and build the plugin in CRM.

When attempting to debug a plugin, I get the attached message:
A project with an Output Type of Class Library cannot be started directly.
I have reviewed this with other developers on the team and they have had differing answers.  I need a way to set a breakpoint and step through the code to see what is not correct (missing quoteid, no guid, etc).

The answer I received was: Create a new .cs file in the unit test project to test code you want to implement.

Below is the code I was given for this process.  Set a break point where you want to debug the logic. Use the Test Explorer and locate your new .cs file.

using FakeXrmEasy;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Query;
using PACCAR_CRM_Code.Library;
using PACCAR_CRM_Code.Library.Result;
using PACCAR_CRM_Code.Plugins;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Xml;
using Xunit;

namespace UnitTestProject
    public class Test
        private static string OrgService = "http://spaceshuttle-test/LaunchTest";

        public void Test_Debug()
            var utilities = new Utilities();
            var ctx = new XrmFakedContext();
            var TracingService = new XrmFakedTracingService();
            var PIEventlog = new EventLog();

            //Establish Connection to CRM
            Uri organizatinUri = new Uri(OrgService + "/XRMServices/2011/Organization.svc");
            ClientCredentials credentials = new ClientCredentials();
            credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials; //new NetworkCredential("zzitdrentestcrm", "d#!b28$Oe@E1b!");
            credentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
            OrganizationServiceProxy service = new OrganizationServiceProxy(organizatinUri, null, credentials, null);

            //Retrieve a quote for example
            Entity quote = service.Retrieve("quote", new Guid("YOUR GUID GOES HERE"), new ColumnSet(true));

            // Implement your Code here and use the quote above as the data if you require it


Open in new window

This is not working for me.  I get errors in the Error List and cannot get a clean build locally.  Basically I am not sure what code to put in where the example above says:   // Implement your Code here and use the quote above as the data if you require it

I was also told that I could use a windows forms application to debug, I am not sure how this would work but I assume it involve writing additional code.

I need advice on using either method to debug my code.  Right now I am building and publishing to see the results once I get a clean build locally.  This doesnt work because it introduces potentially bad code into CRM and TFS.

Thanks for your help.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Pawan KumarDatabase Expert
Awarded 2016
Top Expert 2016

You have to select the startup project or file  ..e.g. .if you are using ASP.NET then you need to click on the project - right click and choose run as start up project.
What errors are you getting with the unit test recommendation?  The code you presented looks pretty straight-forward so most likely you have a dependency problem.

The intermediary application method isn't a bad idea either, you simply add a dependency to the library that you need to test and fire off the method in the library that you are debugging; e.g. -
using EE_Q29011704;
using System;
using System.IO;
using System.Threading.Tasks;

namespace EE_Q29069412
    class Program
        static readonly FileSystemWatcher watcher = new FileSystemWatcher(".");

        static void Main(string[] args)
            watcher.EnableRaisingEvents = true;
            watcher.Created += OnChanged;
            var t = Tasks.StartWithCancellation(() => {
                Console.WriteLine("Press any key to continue...");
                for (var i = 0; i < int.MaxValue; i++)

        static void OnChanged(object source, FileSystemEventArgs e)
                Console.WriteLine($"New file created - {e.Name}...  Throwing an unhandled exception...");
                throw new Exception("Unhandled Exception");
            catch (Exception ex)
                Console.WriteLine($"New Exception: {ex.Message}; we should continue though...");

Open in new window

In the preceeding code example; StartWithCancellation and WaitWithCancellation are methods from my EE_Q29011704 example application.  That project is not a part of the solution that contains this code, I only have my reference:Capture.PNG
When I build this application to either debug it or publish it, the binaries (and dependency binaries that are set to copy locally) are placed in the bin folder of the solution, along with any associated PDB files:Capture.PNG
When I debug my application I can access the associated methods in the referenced dependency:Capture.PNGCapture.PNG
David TrippMicrosoft Dynamics Consultant

it_saige: I would like to setup an online session to go through your solution.  I am in a sprint planning session now but let me know when would be a good day/time to go through your unit testing recommendations.



I am using this comment to do debugging, thanks for your help

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial