Sunday, January 16, 2022

Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies

While trying to connect to Dynamics CRM Online via an MVC application, I was having below error


ERROR REQUESTING Token FROM THE Authentication contextException has been thrown by the target of an invocation. => Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.Unable to connect to CRM: Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Unable to Login to Dynamics CRMOrganizationWebProxyClient is null

OrganizationWebProxyClient is null


Root Cause:

You normally get this issue when you take the reference of certain third party library in your application.

For example, you took the reference of RestSharp (A third-party library) from NuGet. That RestSharp internally may have used the reference of System.Net.Http 4.2.0.0 version. And your project is also using the reference to System.Net.Http 4.0.0.0 (From GAC). Now when you run the application & try to call any method which is using RestSharp, at the same time Runtime (CLR) tries to locate the System.Net.Http assembly with version 4.2.0.0 & when it fails to locate the desired version, it throws System.IO.FileNotFoundException exception with below error message.

Solution:

Just add the below configuration in the web.config or app.config of your startup project. 

<dependentAssembly>

        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />

        <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.0.0.0" />

</dependentAssembly>


Hopefully, this should fix the issue.


Here are some other links for Troubleshooting and learning:

·       Plugin in Dynamic 365 CRM

·       Connect to Dynamic 365 CRM from Console App using Azure Authentication

·       Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies

·       Unable to Login to Dynamics CRMOrganizationWebProxyClient is null

·       Assembly 'Microsoft.Crm.Sdk.Proxy' with identity 'Microsoft.Crm.Sdk.Proxy, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' uses 'Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'Microsoft.Xrm.Sdk' with identity 'Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

·       Could not load file or assembly 'Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.

·       Could not load file or assembly 'Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies




Wednesday, January 12, 2022

Dynamic CRM Sandbox Service

The Sandbox Processing Service is part of the CRM deployment and is responsible for executing plugins that are registered in isolation mode. 

Here are some of the limitations of a plugin running under Sandbox.

  • Access to the file system (C Drive)
  • system event log
  • certain network protocols
  • registry
  • You cannot access any other DLL’s
  • IP addresses cannot be used
  • Only HTTP and HTTPS protocols are allowed.
  • In isolated mode, you cannot call any external DLL’s\DLL’s in the GAC
  • It has a timeout for 2mins of the operations.


Other Key Notes:

Debugging a Sandbox plugin is the same as we do when referring a plugin on a database for an online CRM instance, but for On-Premise you need to attach your debugger to the Sandbox service.


Refer here for knowing about - Dynamic CRM Asynchronous Service

Dynamic CRM Asynchronous Service

The Microsoft Dynamics 365 Asynchronous Processing Service (called the async service) executes long-running operations independent of the main Microsoft Dynamics 365 (online & on-premises) core operation.  This results in improved overall system performance and improved scalability.

How does it work?

The asynchronous service features a managed queue for the execution of asynchronous plug-ins, workflows, and long-running operations such as bulk mail, bulk import, and campaign activity propagation.  These operations are registered with the asynchronous service and are executed periodically when the service processes its queue. Since these operations are queued up and must be executed in time globally, there are some well-defined resource quotas that enable resources to be distributed amongst all online customers equally.

 

Where I can see these Jobs running?

A System Job also known as an asynchronous operation, is used to define and track the execution of asynchronous operations for example an asynchronous registered plug-in, workflow, or other background system operation. 




The following table lists the states, and the statuses for each state, of an AsyncOperation.





An asynchronous operation can be made dependent on another asynchronous operation. A dependent asynchronous operation does not execute until the operation that it is dependent on has finished executing.


Refer here to know about - Dynamic CRM Sandbox Service

Tuesday, January 11, 2022

How to send email to all users who are following a case.


Refer here: To know about Follow Functionality in Dynamics 365 CRM

 

This blog describes the functionality where all users will receive an email notification for case bring followed by them is updated. To demonstrate this we are considering the case origin field on the Case entity.

Through this, the user will know about any actions being performed on the case instead of manually looking into it. 

Users can also unfollow the case from receiving email notifications whenever they wish to. 



Plugin Code:

namespace Crm.Plugins

{

public class EmailToUsersForCaseFollowed: IPlugin

{

public void Execute(IServiceProvider serviceProvider)

{

    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

    IOrganizationServiceFactory serviceFactory =(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

    ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

 

    Entity targetentity = (Entity)context.InputParameters["Target"];

 

    EntityCollection users = GetUsersWhoFollowCase(service, targetentity.Id);

    if (users.Entities.Count > 0)

    {

        EntityCollection toPartyCollection = new EntityCollection();

        foreach (Entity user in users.Entities)

        {

            Guid userId = user.GetAttributeValue<EntityReference>("ownerid").Id;

 

            Entity toParty = new Entity("activityparty");

            toParty["partyid"] = new EntityReference("systemuser", userId);

            toPartyCollection.Entities.Add(toParty);

        }

        if (toPartyCollection.Entities.Count > 0)

        {

            EntityReference caseref = new EntityReference("incident", targetentity.Id);

          

            //Please change GUID for SystemUserID to send an email

            EntityReference from = new EntityReference("systemuser", new Guid("319c52a2-fc46-ec11-8c60-000d3af29037"));

          

            Entity fromParty = new Entity("activityparty");

            fromParty.Attributes.Add("partyid", from);

         

            EntityCollection fromPartyCollection = new EntityCollection();

            fromPartyCollection.EntityName = "systemuser";

            fromPartyCollection.Entities.Add(fromParty);

 

            Entity email = new Entity("email");

            email.Attributes.Add("regardingobjectid", caseref);

            email.Attributes.Add("subject", "Case Origin is being Updated");

            email.Attributes.Add("description""your detail description about case updated goes here");

            email.Attributes.Add("from", fromPartyCollection);

            email.Attributes.Add("to", toPartyCollection);

            Guid emailID = service.Create(email);

 

            SendEmailRequest reqSendEmail = new SendEmailRequest();

            reqSendEmail.EmailId = emailID;

            reqSendEmail.TrackingToken = "";

            reqSendEmail.IssueSend = true;

            SendEmailResponse res = (SendEmailResponse)service.Execute(reqSendEmail);

        }

    }

}

 

public EntityCollection GetUsersWhoFollowCase(IOrganizationService orgService, Guid caseId)

  {

    EntityCollection userEntityCollection = new EntityCollection();

    QueryExpression caseQuery = new QueryExpression("postfollow")

    {

        NoLock = true,

        ColumnSet = new ColumnSet("regardingobjectid", "ownerid")

    };

    caseQuery.Criteria.AddCondition("regardingobjectid", ConditionOperator.Equal, caseId);

 

 

    userEntityCollection = orgService.RetrieveMultiple(caseQuery);

    return userEntityCollection;

  } 

 }

}


Register the Plugin on 

  • Update of Case Entity 
  • with Filtering Attributes caseorigincode. 



You can Check the Timeline for the email received by the user whenever the records are updated. 

























Follow Functionality in Dynamics 365 CRM

In this blog, we will learn about the "Follow" functionality in Dynamics CRM.

  • The Follow functionality helps to track various activities performed for a record or multiple records.
  • We can follow records for out-of-box entities like leads, accounts, and contacts and get to see views like Leads I follow, Accounts I follow or Contacts I follow
  • For custom entities, we need to manually activate (configure) Follow functionality.


Let’s begin. We have a custom entity named “Student”

Navigate to Advance settings > Security > Activity Feeds Configuration.


Search the custom entity from the Post Configuration view. The status for the custom entity must be Inactive, you need to activate it.


To Activate the entity for Follow functionality, select the entity. Click on Activate Button as shown in the below screenshot.


You will get a confirmation box for activation. Click on Activate.


In order to replicate the same in the form, we need to Publish the Customization.



Now navigate to the custom entity (Student in my scenario) and notice two new views added


Open any existing record. Click on 3 dots you will find a follow option now. 


You can now check

  • list of Students you follow from view Student I Follow
  • list of Students Followed by other users as well, from the option Students being Followed.



Troubleshooting the ‘I Follow’ functionality

If you do not get the Follow option try the following:

  • Make sure you publish the entity customization
  • Make sure that the user has sufficient privilege under his security role.




Hope this will resolve your issue.