locked
how to debug plugin from on premise CRM 2011 RRS feed

  • Question

  • hi all

    is there any step by step procedure to debug plugin in VS 2010 before registering  ... bcoz i registered plugin 12th times to debug the error "ISV code aborted the operation " but still the error is same .. is there any blog/site for this

    one more Ques what is the diff bet

    if (context.InputParameters.Contains("Query") == true && context.InputParameters["Query"] is QueryExpression) And

    if (context.InputParameters.Contains("Target")  && context.InputParameters["Target"] is Entity)

     

    actually i m creating plugin to hide views based on login user . i created a method to retrieve user roleid and check it with context.userId if true then hide... its a part of my code

     

     

     EntityCollection be = service.RetrieveMultiple(qe);

     Microsoft.Xrm.Sdk.Entity[] bEntity = be.Entities.ToArray();

    List<Guid> objRoleIDList = new List<Guid>();

     

     foreach (Microsoft.Xrm.Sdk.Entity bEnt in bEntity) //

                    {

     

                        Role objRole = (Role)bEnt;

                         objRoleIDList.Add(objRole.RoleId.Value);

                    }

     

    in this code Role is from OrganizationData service but if i remove this service it takes from MyOrganizationCrmSdkTypes.cs

    so from where i should use Role ...

    plz help me I stuck here

     

    Thank You


    • Edited by Absha Thursday, December 22, 2011 6:24 AM
    Thursday, December 22, 2011 6:19 AM

Answers

  • Hi,

    Please refer the following section Plug-In Debugging from the book Microsoft Dynamics CRM 2011- Unleashed, also look at CRM SDK for section Debug a Plug-in

     

    Details from the book

     

    Plug-In Debugging

    There are two ways to debug your plug-in. The first, as shown in Table 25.1, is attaching

    the debugger to the host process, and the other is forcing the plug-in to call the debugger.

    For either of these methods, it is recommended to try them in a testing environment

    because these methods use Visual Studio and will interrupt all user activity with the server

    if you attempt to enable debugging in a production environment.

    Before trying any of these methods, you need to build your plug-in with Debug mode

    and put the PDB (project database) file generated by the compiler in the following directory

    (assuming you have the CRM server installed on C:\Program Files\Microsoft

    Dynamics CRM.):

    C:\Program Files\Microsoft Dynamics CRM\Server\bin\assembly

    Unfortunately you must restart the IIS after copying the PDB file. This is something that

    can be done via the command prompt by running the following command:

    Iisreset

    You could also restart the IIS by using a PowerShell command:

    Restart-Service W3SVC,WAS –force

    From the Library of Thankachan Thomas

    Plug-In Debugging 847

    25

    FIGURE 25.33 Setting breakpoints on your code.

    TIP

    You must copy the PDB file every time you rebuild the solution and restart the IIS.

    CAUTION

    You must have Visual Studio 2010 installed on the server where the CRM Server is

    installed, or you can only install the Visual Studio 2010 Remote Debugger on the

    server and debug from a development workstation. This sample assumes you have

    Visual Studio 2010 installed on the same server where the CRM Server is installed.

    Attaching the Debugger to the host Process

    With this mode you have to open your plug-in solution in Visual Studio 2010 first and

    put breakpoints where you want to stop and debug your code. To set a breakpoint, press

    F9 (see Figure 25.33).

    You must start the debugger by attaching the Visual Studio debugger to the w3wp.exe

    process for example to debug an online plugin. To do that, go to the Debug menu, and

    select the Attach to Process option (see Figure 25.34).

    From the Library of Thankachan Thomas

    848 25 Plug-Ins

    FIGURE 25.35 Attaching the debugger to the w3wp.exe process.

    When the Attach to Process dialog appears, be sure to check the check boxes that say

    Show Processes from All Users and Show Processes in All Sessions. Locate the w3wp.exe

    process and select it (see Figure 25.35).

    FIGURE 25.34 Attach to process menu option.

    From the Library of Thankachan Thomas

    Plug-In Debugging 849

    25

    FIGURE 25.36 Debugging the plug-in.

    NOTE

    If you don’t find the w3wp.exe process, it is probably because you must first open an

    Internet Explorer window and browse to your CRM organization URL so that IIS will load

    the application pool represented by the w3wp.exe.

    You might also find there is more than one instance of the w3wp.exe processes running;

    this might depend on the number of different websites and application pools running

    on the same IIS. Because it is hard to say on which one our application is

    running, we recommend attaching to all the w3wp.exe instances.

    If you are using the Remote Debugger, you will need to change the qualifier name to the

    name of the computer where the CRM and the remote debugger are installed.

    If the plug-in has been registered with sandbox isolation mode, you will need to attach to

    another process instead of the w3wp.exe process. The process that hosts the plug-ins on a

    sandbox is called Microsoft.Crm.Sandbox.HostService.exe.

    Click the Attach button to start debugging the plug-in.

    Assuming you registered a plug-in with a step associated to the Account entity on the

    Create event (as our example did), when you go to the CRM web application and try to

    create a new Account, you will be automatically switched to the Visual Studio 2010

    application after you click the Save or Save and Close buttons on the Account form (see

    Figure 25.36).

    From the Library of Thankachan Thomas

    850 25 Plug-Ins

    FIGURE 25.37 Visual Studio just-in-time debugger.

    Forcing the Add-In to Call the Debugger

    To force CRM to call the debugger, you must add a line similar to the following in your

    add-in source code where you want to call the debugger:

    System.Diagnostics.Debugger.Launch();

    Assuming you registered a plug-in with a step associated to the Account entity on the

    Create event (as our example did), when you go the CRM web application and try to

    create a new Account, you will see the dialog shown on Figure 25.37 after you click the

    Save or Save and Close buttons on the Account form.

    Click Yes to open a new instance of Microsoft Visual Studio 2010, and you will see the

    code of your plug-in stopped its execution right on the line of code we added to launch

    the debugger (see Figure 25.38).

    NOTE

    If you try saving the Account from a machine different than the server, the dialog shown

    on Figure 25.42 will be displayed on the server machine and not on the client machine.

    Be sure to comment or remove all the lines where you put the Debugger.Launch() method

    after debugging and fixing your plug-in before deploying it to production.

    From the Library of Thankachan Thomas

    IServiceProvider 851

    25

    FIGURE 25.38 Plug-in debugging in Visual Studio.

     


    Thomas T(MCBMSS) If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Thursday, December 22, 2011 7:56 AM

All replies

  • Hi first open you project and make sure the dll's in server\assembly folder

     

    then attah to process in VS select processes w3wp.exe and crmasynchservice.exe put debug at Execute method


    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by san Sanz Thursday, December 22, 2011 6:39 AM
    Thursday, December 22, 2011 6:39 AM
  • yes it is in server\assembly folder but i m not on the same machine where CRM 2011 Server is installed

    and i m unable to see this process w3wp.exe in my VS 2010

    Thursday, December 22, 2011 6:52 AM
  • not a problem whenver plugin fires it automatically debugs/

    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Thursday, December 22, 2011 6:54 AM
  • but i m getting error " ISV code aborted the operation " without any clue .... why this is occurring  .......

     

    Thursday, December 22, 2011 7:11 AM
  • Hi,

    Please refer the following section Plug-In Debugging from the book Microsoft Dynamics CRM 2011- Unleashed, also look at CRM SDK for section Debug a Plug-in

     

    Details from the book

     

    Plug-In Debugging

    There are two ways to debug your plug-in. The first, as shown in Table 25.1, is attaching

    the debugger to the host process, and the other is forcing the plug-in to call the debugger.

    For either of these methods, it is recommended to try them in a testing environment

    because these methods use Visual Studio and will interrupt all user activity with the server

    if you attempt to enable debugging in a production environment.

    Before trying any of these methods, you need to build your plug-in with Debug mode

    and put the PDB (project database) file generated by the compiler in the following directory

    (assuming you have the CRM server installed on C:\Program Files\Microsoft

    Dynamics CRM.):

    C:\Program Files\Microsoft Dynamics CRM\Server\bin\assembly

    Unfortunately you must restart the IIS after copying the PDB file. This is something that

    can be done via the command prompt by running the following command:

    Iisreset

    You could also restart the IIS by using a PowerShell command:

    Restart-Service W3SVC,WAS –force

    From the Library of Thankachan Thomas

    Plug-In Debugging 847

    25

    FIGURE 25.33 Setting breakpoints on your code.

    TIP

    You must copy the PDB file every time you rebuild the solution and restart the IIS.

    CAUTION

    You must have Visual Studio 2010 installed on the server where the CRM Server is

    installed, or you can only install the Visual Studio 2010 Remote Debugger on the

    server and debug from a development workstation. This sample assumes you have

    Visual Studio 2010 installed on the same server where the CRM Server is installed.

    Attaching the Debugger to the host Process

    With this mode you have to open your plug-in solution in Visual Studio 2010 first and

    put breakpoints where you want to stop and debug your code. To set a breakpoint, press

    F9 (see Figure 25.33).

    You must start the debugger by attaching the Visual Studio debugger to the w3wp.exe

    process for example to debug an online plugin. To do that, go to the Debug menu, and

    select the Attach to Process option (see Figure 25.34).

    From the Library of Thankachan Thomas

    848 25 Plug-Ins

    FIGURE 25.35 Attaching the debugger to the w3wp.exe process.

    When the Attach to Process dialog appears, be sure to check the check boxes that say

    Show Processes from All Users and Show Processes in All Sessions. Locate the w3wp.exe

    process and select it (see Figure 25.35).

    FIGURE 25.34 Attach to process menu option.

    From the Library of Thankachan Thomas

    Plug-In Debugging 849

    25

    FIGURE 25.36 Debugging the plug-in.

    NOTE

    If you don’t find the w3wp.exe process, it is probably because you must first open an

    Internet Explorer window and browse to your CRM organization URL so that IIS will load

    the application pool represented by the w3wp.exe.

    You might also find there is more than one instance of the w3wp.exe processes running;

    this might depend on the number of different websites and application pools running

    on the same IIS. Because it is hard to say on which one our application is

    running, we recommend attaching to all the w3wp.exe instances.

    If you are using the Remote Debugger, you will need to change the qualifier name to the

    name of the computer where the CRM and the remote debugger are installed.

    If the plug-in has been registered with sandbox isolation mode, you will need to attach to

    another process instead of the w3wp.exe process. The process that hosts the plug-ins on a

    sandbox is called Microsoft.Crm.Sandbox.HostService.exe.

    Click the Attach button to start debugging the plug-in.

    Assuming you registered a plug-in with a step associated to the Account entity on the

    Create event (as our example did), when you go to the CRM web application and try to

    create a new Account, you will be automatically switched to the Visual Studio 2010

    application after you click the Save or Save and Close buttons on the Account form (see

    Figure 25.36).

    From the Library of Thankachan Thomas

    850 25 Plug-Ins

    FIGURE 25.37 Visual Studio just-in-time debugger.

    Forcing the Add-In to Call the Debugger

    To force CRM to call the debugger, you must add a line similar to the following in your

    add-in source code where you want to call the debugger:

    System.Diagnostics.Debugger.Launch();

    Assuming you registered a plug-in with a step associated to the Account entity on the

    Create event (as our example did), when you go the CRM web application and try to

    create a new Account, you will see the dialog shown on Figure 25.37 after you click the

    Save or Save and Close buttons on the Account form.

    Click Yes to open a new instance of Microsoft Visual Studio 2010, and you will see the

    code of your plug-in stopped its execution right on the line of code we added to launch

    the debugger (see Figure 25.38).

    NOTE

    If you try saving the Account from a machine different than the server, the dialog shown

    on Figure 25.42 will be displayed on the server machine and not on the client machine.

    Be sure to comment or remove all the lines where you put the Debugger.Launch() method

    after debugging and fixing your plug-in before deploying it to production.

    From the Library of Thankachan Thomas

    IServiceProvider 851

    25

    FIGURE 25.38 Plug-in debugging in Visual Studio.

     


    Thomas T(MCBMSS) If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Thursday, December 22, 2011 7:56 AM
  • It really helped. Thanks
    Tuesday, February 14, 2012 12:34 PM
  • I try to debug the plugin with w3wp.exe and crmasynchservice.exe  processses attached . But not able to debug the application. The plugin has not  registered with sandbox isolation mode.

    Shirish . M

    Monday, July 23, 2012 2:00 PM
  • I am going back to your code. Why are you using Organization Data service to retreiev the role? in a plugin you do thet using retrieve with plugin context. See the below url which explains the process to hide columns form the view based on security role.

    http://my-devils-workshop.blogspot.com/2012/07/plugin-to-remove-data-for-field-from.html


    Thanks,
    Raja Ramesh Varma
    http://my-devils-workshop.blogspot.com

    Monday, August 6, 2012 8:15 AM
  • You can do what i've written below - since you are trying to debug the plugin from another box and "not" your CRM application server.

    Open your plugin code on Vs2010, attach the VS debugger to tthe IE instance which has your CRM 2011 page (you will find it in thje list of processes to attach), and also attach it to the asp.net worker process. trigger your plugin and check if the breakpoint gets hit..


    • Edited by SwetaGupta Thursday, August 23, 2012 10:01 AM
    • Proposed as answer by SwetaGupta Friday, August 24, 2012 9:33 AM
    Thursday, August 23, 2012 9:58 AM
  • To DEBUG A Plugin(on premise)

    You need to fire Visual Studio 2010 in Administrator Mode on the Server(which have IIS + CRM).

    follow these steps:

    1. Change the Debug/Build Path to "C:\Program Files\Microsoft Dynamics CRM\Server\Bin\Assembly" (So when ever you compile the dll will directly go there)
    2. Always do( Clean Sol  ---> Build Sol).. this will update *.PDB file.
    3. Register the Plugin (using plugin Registeration tool)
    4. Attach Debugger to w3wp running for TSQL
    5. Add BreakPoint ( an start hitting F11)

    You need to perform all these steps again & again.. :(

    Hope it helps :)


    Contact["name"] = "Vin.k.s"; Contact["location"] = ?

    Friday, August 24, 2012 5:01 AM