CRM 2013 – Remote Debugging

Only those who dare to fail greatly can ever achieve greatly.”

― Robert F. Kennedy

Developer fear

When I was a junior CRM Developer I couldn’t get remote debugging working, Visual studio wouldn’t attach, port problems etc.  I gave up because I need to resolve the problem.

Until I have done something I’m not sure I can get it working.

The mind makes unknowns scarier; it exaggerates and focuses on worse case scenario’s. Like visiting somewhere you have never been before such as you first day at school/university.  The location seems bigger and shrinks in size with familiarity.

Remote debugging is frustrating because to find out why a customization is erroring you need to debug it.

One day I came to work determined to get remote debugging working and after half a day of trying I got it working.

When using a tool or functionality for the first time, you are outside of your comfort zone (How to cope when you are out of your Developer comfort zone)

Why we need a CRM Developer toolkit

It’s important the CRM developer toolkit is updated and works with CRM 2015/Visual studio 2015.  The CRM developer toolkit makes it easier new CRM developers to write, update and deploy plug-ins.  We don’t want barriers for new CRM developers we want to encourage them to join the CRM development community.

Remote debugging considerations

Remote debugging has some drawbacks, if the plugins has isolation mode = “none” you use the CRM async service, W3p.exe.  This stops the CRM server  processing system jobs, other users have to wait until you have finished debugging.  This is frustrating for other developers because it stops them using CRM.

A better alternative is to test your code using unit tests or console app if I want to call it with data in CRM, this has no effect on other developers and units tests can be rerun by any developer.

Most scenario’s you can test your logic without using the remote debugger, Why CRM Developers should unit test their code

I wrote about remote debugging for CRM 2011 before

CRM 2011 – how to set up Remote debugging for plugins

If you experience problems setting up the remote debugger, try this blog

Remote Debugging CRM 2011 Plugin

Learn Remote debugging before you need it

It’s better to learn a process, new functionality before you use it for the first time on a project,

Make mistakes in practice, it’s a less stressful place to learn than on a live project

Get experience remote debugging before you need to use it.

Remote debugging can be a frustrating due to difficulties in setup and configuration.

Remote debugging is on for On Premise CRM only

You cannot remote debug CRM online.

To debug plugins deployed on CRM Online, you have these choices

The purpose of remote debugging is to test the logic.  You can recreate the scenario from in dev by recreating the data.  Remote debugging shouldn’t be the first tool when diagnosing a problem, it can affect performance and other developers

  • Unit Test
  • Console app and Test plugin code
  • Plugin Registration tool

The debugging option work with CRM On Premise but you cannot use the remote debugger with CRM online.

You can unit test code and create a connection for IOrganisationService to your online CRM and pass and then run unit tests.

Console App

Create a console application, connect to your CRM online and test the code, mimicking the plugin.

Plugin Registration tool

The plugin registration tool can debug the code, it has the advantage of not freezing the whole server because it works with CRM on premise and CRM online.

This video has a good walkthrough of the process Debug CRM Online Plugins

CRM 2015 has added plugin tracing, read more about it here and here

Remote debugging steps

The process is the same for CRM 2011, CRM 2013 and CRM 2015 plugins.  Custom Workflows are different, this blog post walks through the process – Debugging Workflow Custom Activities with Plugin Registration Tool

In this blog post I focus on using the remote debugger and a plugin

I’m using CRM Developer toolkit and running the remote debugger, you can run it as a service which runs all the time (called Remote Debugger) or you can run it as application. which starts when you need it.

Running as a service is it’s always running and can be set to auto start on server reboots.

The downside is the remote debugger service will always be running and taking a bit of server memory/processing (although not much).  You can stop the service if you need.

Developers should use remote debugging in a development environment.

Build the plugin

Copy the plugin/custom workflow .dll and .PDB files to the CRM server directory

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

If you haven’t installed CRM on the C drive then you need to look for it on another drive

The DLL’s and PDB copied to the server must contain the code you want to debug in Visual Studio.  If the code on your local machine is different from the deployed plugin you won’t be able to debug

Important – Copy the .dll and .PDB files to C:\Program Files\Microsoft Dynamics CRM\Server\bin\assembly

Important 2 – Any dependencies in your plugins (dll‘swhich are not in the GAC need to be copied to the server as well.

I copied the PDB files here

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

What is a PDB file?

You may be wondering what a PDB file is, my knowledge of them is you need them for debugging and they contain the code you have written where as the DLL has the compiled code. 

Wiki describes PDB file as

http://en.wikipedia.org/wiki/Program_database

PDB stands for Program Database, a proprietary file format (developed by Microsoft) for storing debugging information about a program (or, commonly, program modules such as a DLL or EXE). PDB files commonly have a .pdb extension. A PDB file is typically created from source files during compilation. It stores a list of all symbols in a module with their addresses and possibly the name of the file and the line on which the symbol was declared. This symbol information is not stored in the module itself, because it takes up a lot of space.

A PDB is needed for debugging, it isn’t needed when you deploy your plugins or custom workflows.

recap of steps

  • Ensure the remote debugger is running as a service or application
  • Build the plugin
  • Deploy the plugin
  • copy the DLL and PDB to the CRM server folder
  • C:\Program Files\Microsoft Dynamics CRM\Server\bin\assembly

Attaching the process

You should be ready to attach Visual Studio to the process and wait for the code to be trigger and your visual studio breakpoint to be hit.

Set a breakpoint in the plugin, put the breakpoint at one of the first lines to avoid breakpoints not being hit because their code was either erroring or not being triggered.

Press the Attach button

remote debugger attach

Brings up this page, it will default to your local machine but you need to put in the name of the CRM server and the port used in the remote debugger.

If my port was 4016 and the CRM server was called CRM server.

CRM Server:4016

Remote Debugging 3

Make sure you tick Show Processes from all users, if you don’t you won’t be able to see the CRM services because  they are most likely run as a different user.

If you don’t know your port number, you can go to the CRM server, open the Remote Debugger to find the path of the application

Remote Debugging 1

click on msvsmon and it will error and tell you the port number you are using.

Remote Debugging 2

When you put in the correct CRM server and port number, the services running will be listed.

If you plugins are in the sandbox (Understanding Plugin sandbox mode) you need to attach the to the process Microsoft.CRM.Sandbox.WorkerProcess.

remote debugging

Usually there are multiple Microsoft.CRM.Sandbox.WorkerProcess. This is because you get one for each CRM web page.  It’s difficult to work out which process is the process you want to debug, so I usually select all of the Sandbox WorkerProcesses to ensure I debug my process.

The final stage is to trigger the plugin and debug your plugin.

Good luck

CRM 2011/2013 – use the debugger console to enabled/disable controls on a form

I was trying to fix a small bug but I was getting bogged down with the business logic (which I didn’t need/want to change) on the form.

The problem was there was lots of business logic which kept disabling the fields I wanted to change.

I tried briefly to understand the business logic but it was complex and detailed and I wasn’t really interested in understanding the form logic and/or briefly amending the JavaScript onload.  All I needed to do was to enable an optionset on the form, which would enable a ribbon button.

So it’s time for a bit of off the cuff hacking

I loaded the form

Press F12 to bring up the debugger window

You can use the console to manipulate the fields and enable/disable certain fields.

You have access to the CRM JavasScript objects

So I used the Xrm.Page, selected the control (not the field attribute) and did a setDisabled(false); which enables the control.
Xrm.Page.getControl(customerid”).setDisabled(false);
This didn’t enable the ribbon button because although the JavaScript function which is used by the ribbon button (e.g. the enable rule for the Ribbon button) the ribbon hadn’t been refreshed.

So I used the console to do a Ribbon Refresh

Xrm.Page.ui.refreshRibbon();

Fantastic, now my field was enabled and the ribbon button was enabled and ready to be pressed.

 

Other uses for F12 JavaScript debugger is to get the guid of the record, which I did on this blog post

 

Browser bookmark

An alternative to bringing up the F12 debugger is to create a bookmark, this will enable you to pass javascript into a form before loading it.

The blog post below created a God Button, which enables all fields

http://www.magnetismsolutions.com/blog/paulnieuwelaar/2014/07/29/activate-god-mode-in-crm-2013—don-t-let-your-users-see-this

 

This blog post will talk you through the logic and is the first part in a series of blog posts on the subject

http://blog.sonomapartners.com/2014/01/crm-2013-javascript-bookmark-series-part-1.html

 

CRM 2011/2013 – Ribbon problems

The investigation and problem I experienced where in CRM 2011 but I think it would be the same in CRM 2013, I had a problem with the ribbon javascript but I didn’t have a clue where it was because I had never seen a syntax error in the Javascript ribbon.

I put a debugger statement in the ribbon, so it would drop into the debugger.  The reason you  put the debugger statement into the Javascript code is because when the ribbon is loaded it is loaded in dynamic Javascript script block, this means when you press F5 it creates a brand new script file and you won’t have time to put a breakpoint in it if you bring up the debugger by pressing F12.

 

So I put my debugger line in and then the code hit my various display/enable javascript methods and I could step through them but the syntax error kept appearing.

I still wasn’t sure where/what the problem was.

I pressed F12 to bring up the debugger and this was bring up a syntax error

syntax error

I turned on fiddler and found on one of the calls I was getting a nasty red triangle on one of the calls.

The thing which kept bugging me was it was a syntax error

I could see the code and it looked fine (although syntax errors are not obvious to the naked eye). The file compiled in Visual studio and pressing F12 to get the debugger didn’t throw an error, so this would suggest the javascript syntax was not the problem

 

frustrating

I fired up the Visual Ribbon Editor for CRM 2011/2013

In the Visual Ribbon Editor here you have display rules, enable rules and action.

There was no disable rule

there was an enable rule and an action rule which both called a javascript function, you can see below

ribbon enable
ribbon action

Slowly something clicked, the error was trying to call the action, why was it calling the action whilst loading the form. Logically the ribbon has to make sure the Javascript method exists so when the user presses the button something will happen but why was it triggering a syntax error whislt loading the ribbon?

Syntax error, ribbon load…..hmmmmm

Look at the two rules, although I’m not showing you the actual file, look at the position of the library and the function boxes!

Finally after hours and dragging more eyes to the problem, my colleague found the problem by exporting the Ribbon xml, hazaaar the problem was obvious

The library and function values from the enable rule had been copied into the action rule, only this didn’t work because the function and library boxes are in different places.

He found the library – which should be the javascript library was pointing to a function.

Ribbon object not found

A new day a new ribbon problem.  Today on one of the forms the ribbon wasn’t loading and I was getting an error

 

SCRIPT5007: Unable to get value of the property Ribbon ‘value’ of undefined or null reference

 

The first thing I checked was to see if the function and library values were correct, they were.

In the Javascript files we use we build up the names spaces so the function calls are like this

Hosk.Functions.Account.Ribbon.NewAccount()

To find the problem I had to put debugger statements in the enable/action javascript rules and walk through them.

 

Eventually I found one where Javascript file hadn’t been loaded, so when it it was trying to call a function the javascript file was loaded, the function didn’t exist and we got a null reference.

 

Hosk’s Top CRM 2013 articles of the week 11th April 2014

Here are my friday CRM articles of the week, there have been some great Developers articles this week

but let us start as always with a celebrity thumbs up

Article of the week

As I am a “computer” person various members of my family have been asking me whether they need to change their passwords because of heartbleed

The simple answer is Yes, just do it.  Google and Facebook could have been compromised.  Interestly the banks (UK), amazon and linkedin all seem ok.  The biggest danger is you have probably used the same password all over the place, so if an account is important to you, go change that password.  You should check that the site has updated their code/certificate to patch up the security flaw, otherwise you will have to change the password again later.  Most of the big internet companies have changed their certificate.

This article on the BBC is pretty good
also this page

an in depth article

http://www.troyhunt.com/2014/04/everything-you-need-to-know-about.html

this site has a bit more clear data

“This is not the first defect of its kind and it certainly won’t be the last, but it is one of the more serious faults we’ve seen in recent internet history,” said Mr Lyne.

Name Vulnerable? Patched? Change password?

Amazon

No

No need

Only if shared with vulnerable service

Amazon Web Services

Yes

Yes

Yes

Apple

Not clear

Not clear

Not clear

Barclays

No

No

Only if shared with vulnerable service

eBay

No

No need

Only if shared with vulnerable service

Evernote

No

No need

Only if shared with vulnerable service

Facebook

Yes

Yes

Yes

Google/Gmail

Yes

Yes

Yes

HSBC

No

No need

Only if shared with vulnerable service

If This Then That

Yes

Yes

Will force users to log out and ask them to update

LinkedIn

No

No need

Only if shared with vulnerable service

Lloyds

No

No need

No

Microsoft/Hotmail/Outlook

No

No need

Only if shared with vulnerable service

PayPal

No

No need

Only if shared with vulnerable service

RBS/Natwest

No

No need

Only if shared with vulnerable service

Santander

No

No need

Only if shared with vulnerable service

Tumblr

Yes

Yes

Yes

Twitter

No

No need

Only if shared with vulnerable service

Yahoo/Yahoo Mail

Yes

Yes

Yes

CRM Article of the Week

Here is the CRM article of the week

This article/slideshow was tweeted by Jukka Niiranen and is a fantastic resource for any CRM Developers (like those who are subscribed to Hosk’s CRM Dev)

Developer Tips and Tricks by Marc Schweigert

Is basically a roundup of lots of great sites, great tips and best practices on all areas of CRM development, 33 slides of action packed CRM Developer goodness

 

CRM 2013 Articles

 

DEV Articles

Jukka Niiranen has not only been writing great CRM articles but also tweeting some very useful ones as well.  This article has a video and shows you how to debug your Javascript in Visual Studio

EUREKA: F5 debugging of CRM JavaScript web resources

The linked article from the above but this is amazing, you can debug Web Resources without deploying them by using a Scott Durow trick of using Fiddler 2. AWESOME

Debugging CRM web resources without ever deploying them

It’s not a blog but a youtube video, to whom someone described as the infamous CRM blogger Leon Tribe.  This video in the words of Leon Tribe is “making the world a better place”.  This is a good article for CRM Developers to consider

TFS for Microsoft Dynamics CRM Development Management

I was asked this question on the Hosk CRM Dev linkedin group and then rather marvelously the questioner found the answer and shared it with everyone

Install CRM Developer Tookit in Visual Studio 2013 

Well I couldn’t put articles of the week in without including some of mine surely.  I did another video featuring CRM plugins, I updated the previous weeks example and go into a bit more about plugin theory.  Join Hosk’s CRM Dev channel NOW

CRM 2013 Video – simple update plugin, Redeploying, improving and updating

 

Blog – CRM 2013 – Plugins – Simple update plugin – Redeploying, improving and updating

The blog post for the first Plugin video, a good step by step guide to developing a CRM

CRM 2013 – Step by Step Update Plugin Tutorial using the CRM 2013 Development Toolkit

 

How to connect and authenticate to Office 365 and CRM 2013

MS CRM 2013 Online upgrade to Office 365 authentication

The tip of the quick Dev tip shows how to refresh your web resources with code

Refreshing the Web Resource in CRM 2013

Microsoft like to call it PBL – Portable Business logic, everyone else calls them Business Rules

 Hiding a Tab in Dynamics CRM using Portable Business Logic (PBL)

 

CRM 2013 Articles

Jukka Niiranen who has 657 followers on google plus and no wonder he writes brilliant blog posts using his special CRM MVP powers, here he shows us how to report on the sneaky CRM system entities of Case Resolution and Opportunity closed.

Accessing “Special” Activity Data with CRM Report Wizard

Did you know there are a bunch of Business Process Flows inside CRM just waiting to be turned on? You do now

 How to Turn On Ready-to-Use Business Process Flows in Dynamics CRM 2013

There are three new server roles and services

Dynamics MS CRM 2013 – New Server Roles and Services

Joel Lindstrom the CRM MVP answering Hosk’s questions this week

CRM MVP Question and Answer – Joel Lindstrom

Be careful when you check some options on entities because like taking the Red pill in the matrix you can never go back

Tip #110: Don’t prematurely check the boxes

Common Queries Microsoft Support answer about CRM Async service, it’s a cheeky look under the covers

Common queries regarding Dynamics CRM Asynchronous Service

A Hosk blog reader asked me some questions about starting a CRM blog, my advise was do it, you will learn a bunch of stuff about CRM and you might help other people who want to know about CRM.  So she did and here is her first CRM blog, well done  Elaiza

I’m a CRM tourist, I need a tour guide!

 

CRM 2011 – Debugging plugins using the Plugin Registration tool

I was having a bit of a nightmare debugging my plugins.  The plugin was working in my test case but when I deployed it and tried to run it from CRM, I was getting errors.

I had tried to setup remote debugging which I have done before but this time I was having problems because of some kind of firewall related problems and when I dropped my firewall the remote debugger could talk to my computer but the debugger wasn’t catching.

I then tried to get the profile/debugger working in the plugin registration tool but I kept getting stuck when it asked for a profile location, WHAT THE HELL IS THIS PROFILE.

I tried to google instructions for the profile/debugger but I couldn’t find anything but then out of the blue one of the blogs I follow wrote an article about it and saved the day.

if you want to use the plugin registration tool debug then follow these instructions

http://inogic.blogspot.co.uk/2012/06/how-to-debug-plugins-using-profiler.html

so basically you have to install and turn on profiling, then go into CRM, trigger the plugin.  This will then download your profile file.  Then in the Plugin Registration tool debug the plugin, choose your dll and newly downloaded profile text document, set the debug on your visual studio and attach the process to the plugin registration tool.  Now in the Plugin Registration Debug page, click Start Plugin Execution.

Basically the profile you downloaded is probably serialized variables and values which is now loaded into visual studio, allowing you walk through the code with the values you entered into CRM.

The tool is great and you can do it all from your PC.

Now onto the problems I was having.  I had set up a plugin to run on the post operation of an entity update.

What seemed to be happening was the main values of the entity were being copied but no related entity information was being created.  My code was using one of the related entities in a query.

To get round the problem I used the guid of the entity and retrieved the related entity information and then I could walk through the rest of my code.

CRM 2011 – Outlook CRM Disconnected – Check the time on the server!

Today I had a very unusual problem, suddenly no one could connect to CRM 2011 using outlook.

The web url to CRM 2011 worked fine

but Outlook couldn’t connect.

Oddly my outlook was the only one in the company who could connect (I don’t see what the problem is guys :-))

I turned on tracing on one of the outlooks and the error file didn’t really help me much.  Googling the problem pulled back lots of entries but nothing that worked for me.

I tried to remove the organisation and add it again and then I got a slightly different error  message

CRM 2011 outlook There is a problem communicating with the microsoft Dynamics CRM server

Communication problem, no kidding, they were giving each other the silent treatment.

googling this error message finally brought me to this kb article

This issue may occur for any of the following causes:

  1. The operating system date on the client computer is not set to the correct date.
  2. The operating system time on the client computer is not set to the correct time.
  3. The operating system time zone on the client computer is not set to the correct time zone.
  4. The Microsoft Dynamics CRM server might be unavailable.

What??!?!?  I then got called into a meeting but when I came out one of the salesmen found out the time on the CRM server was 5 minutes slowly than his computer time and when he changed his computer time it worked.

The solution to the problem was to change the time on the CRM server to the correct time, for some reason it had lost 5 minutes.

it took me ages to find the cause of this problem, I can’t really understand why CRM has a such a strict policy about this.

 

Here is the solution from the KB article

For Causes 1, 2, and 3

  1. Exit the CRM Configuration Wizard.
  2. Change the operating system date and time. To do this, use one of the following methods.

    Method 1: Manually change the operating system time

    1. Click Start, click Control Panel, click Clock, Language, and Region, and then click Date and Time.
    2. In the Date and Time dialog box, click Change date and time to change the date and time settings. For example, click a date such as February 1, 2011 from the calendar, and change the time.
    3. Click OK.
    4. Click Change time zone, and then select your time zone.
    5. Click OK.

    Note These steps are for Windows 7 or Windows Server 2008 operating systems. To change date and time in Windows XP, please refer to the Windows XP help manual.

    Method 2: Configure the operating system time to synchronize with an Internet time server

    1. Click Start, click Control Panel, click Clock, Language, and Region, and then click Date and Time.
    2. In the Date and Time dialog box, click the Internet Time tab, and then click Change Settings.
    3. Click to select the Synchronize with an Internet Time Server check box, select a time server, click Update Now, and then click OK.

    Method 3: Use a command to sync time with the domain if the computer is a member of a domain

    1. Click Start, click All Programs, click Accessories, right-click Command Prompt, and then clickRun as Administrator.
    2. At the command prompt, type the following text, and then press Enter:
      net time [{\\ComputerName | /domain[:DomainName] | /rtsdomain[:DomainName]}] [/set]

      If you do not know the ComputerName or the Domain Name, try the following simple command:

      net time /set

      Then, type Y to finish the change.

      Expand this image

    For more information about the net time command, visit the following Microsoft website:

    Method 4: Force a synchronization of the NTP client if the computer uses an NTP client to sync with an NTP server

For Cause 4

To resolve the issue for Cause 4, you must contact your system administrator to verify the availability of the Dynamics CRM Server. Or, try to run the configuration again.

 

CRM 2011 – an error occurred while connecting to the MSCRM_CONFIG database

I got this error today when suddenly and for no reason I could work out their CRM 2011 stopped working (this has happened twice in one week with two different customers).

I have blogged about this error before and if you have got this error then check out the blog below

https://crmbusiness.wordpress.com/2011/09/02/crm-2011-mscrm_config-database-is-unavailable/

This time it was the same except the previous solution wasn’t working, although I thought it should

When I was trying to diagnose the problem, I noticed the MSCRM_CONFIG database wasn’t attched but  also it wasn’t detached.

I also noticed there was another database created with a guid type name, when I opened the database I noticed it was basically a copy of the MSCRM_CONFIG database (in terms of tables).

I’m not sure how this happened but it looked like some kind of backup or transaction had caused a copy of the MSCRM_CONFIG database.  I looked at the physical files of the guid database and it had the physical name of MSCRM_CONFIG.mdf.

I think maybe the server lost power and when the server came back up the guid database opened it locked the MSCRM_CONFIG.mdf file so when the real MSCRM_CONFIG database tried to lock it couldn’t.

CRM cannot function if the MSCRM_CONFIG database is down because this is basically a systems setting type database with information for all the organisations on the server.

To resolve the problem I had to unattach the guid database and then attach the MSCRM_CONFIG database and it came up and everything was working again.

here is a screenshot of the dodgy guid database