Category: Technology

Error While Refreshing CRM 2011 Main Page Grid – UR 12

In our CRM 2011 ribbon we had written code to Refresh the Grid after click of a ribbon button.

It was like

crmGrid.Refresh(); or you might have implemented it like document.getElementById(“crmGrid”).Refresh();

After updating to UR 12 we were getting an error on crmGrid object.

“Object doesn’t support property or method ‘Refresh'”

After looking into DOM (for long-long time) we found that the Refresh method has been moved inside control class, so it can Now be implemented as

crmGrid.control.Refresh();

Android and iOS Development using C# : Xamarin

Long back when Android was in its initial stages. Android 1.6 sdk was out there and Google trying hard to push developers to develop for it using various competitions I downloaded Donut SDK and IDE.

Those were initial days of my career and I had been using Visual Studio as IDE and Eclipse felt like a Haunted Village when compared to Visual Studio which was like a Metropolitan city.

After that experience Developing for Android went out of Window and I missed the train of New and Rising OS.

 

But it’s never too late to start developing and if you are like me and have phobia to develop in Eclipse and Java there is good news for you. Download Xamarin and start developing for Android and iOS.

You’ll definitely love the experience and the comfort of good ol C#.

http://xamarin.com/

Unable to install Silverlight: Windows 8/Windows 8.1

While trying to install Silverlight on Windows 8.1 I got installation error saying that “The same version of Silverlight is already installed”

Silverlight Error Message
Silverlight Error Message

To fix the issue I followed given steps.

This helped solving the issue and reinstalling Silverlight.

Windows Phone Emulator Error

While trying to run Windows Phone emulator I was facing given error.

The Windows Phone Emulator wasn’t able to create the virtual machine: Something happened while creating a switch: Xde couldn’t find an IPv4 address for the host machine.

 

Simple Resolution to this problem is:

  • Run Hyper-V Manager as Admin



     

  • Go to Action > Virtual Switch Manager.


 

  • Click on “New Network Switch’


     

  • Select Internal and Create Virtual Switch


     

  • Give Name of Virtual Switch as “Windows Phone Emulator Internal Switch”


     

  • Click “OK” and restart your machine.

     

     

    After following these steps you should be able to run Windows Phone 8 Emulator without any issue.

    In case it solves/ doesn’t solve your problem mention that in comments.

 


 

Import Solution Issue in UR 12

Recently we tried to import solution on CRM which was recently updated from UR 6 to UR 12.

Solution we had was taken from same server from a different org (after upgrade) and was getting stuck at the import step with no activity (at all) in progress bar.

Following Exception was there in CRM Trace log viewer

 

at CrmException..ctor(Int32 errorCode, Object[] arguments) ilOffset = 0x36

at SolutionImportProcessPage.ProcessRequestData() ilOffset = 0x4A

at SolutionImportProcessPage.ProcessAction(String action) ilOffset = 0x92

at AppUIPage.OnPreRender(EventArgs e) ilOffset = 0xD

at Control.PreRenderRecursiveInternal() ilOffset = 0x54

at Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) ilOffset = 0x6D3

at Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) ilOffset = 0x3C

at Page.ProcessRequest() ilOffset = 0x14

at Page.ProcessRequest(HttpContext context) ilOffset = 0x31

at CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() ilOffset = 0x18D

at HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) ilOffset = 0x15

at ApplicationStepManager.ResumeSteps(Exception error) ilOffset = 0x10A

at HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) ilOffset = 0x5C

at HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) ilOffset = 0x16A

at ISAPIRuntime.ProcessRequest(IntPtr ecb, Int32 iWRType) ilOffset = 0x4B

>Crm Exception: Message: An error occurred while importing a Solution., ErrorCode: -2147188685

 

 

To resolve this following post from Microsoft discussion forum helped

http://social.microsoft.com/Forums/en-US/crmdeployment/thread/755b7161-4ec3-40d1-bc37-776460656d9e

  1. Stop Async Service in services.msc
  • Run “services.msc”
  • Stop Async Service

     

  1. Take Microsoft.crm.sdk.proxy.dll from latest sdk
  2. Open Visual studio command line tools (in administrator privileges)

Run

gacutil /i c:sdkbinMicrosoft.crm.sdk.proxy.dll

do

  1. IIS reset, restart CRM Async Service in services.msc

Try importing the solution

 

PS: If you are in a farm deployment then Install Microsoft,crm.sdk.proxy.dll in the server running CRM Async Service.

Before installing dll, stop the async service, install dll in gac and restart async service.

 

 

The operation ‘*************Async’ could not be loaded because it has a parameter or return type of type System.ServiceModel.Channels.Message or a type that has MessageContractAttribute and other parameters of different types. When using System.ServiceModel.Channels.Message or types with MessageContractAttribute, the method must not use any other types of parameters.

We were getting Below given error in all our environments except one.

Searching on net gave various reasons for this error like : DataContract if used in WCF Service then gives exception if you return with primitive type etc…

None of those criteria fit it as it was working fine in One CRM environment.

Reason
for this error was that Plugin was built against .Net framework 4.5 but servers Giving error had framework 4.0.

So to resolve
this we can either upgrade server to 4.5 (as it worked in one environment with Framework 4.5) or we can Build plugins against Framework 4.0.

“The operation ‘*************Async’ could not be loaded because it has a parameter or return type of type System.ServiceModel.Channels.Message or a type that has MessageContractAttribute and other parameters of different types. When using System.ServiceModel.Channels.Message or types with MessageContractAttribute, the method must not use any other types of parameters.”

The Web Service plug-in failed in OrganizationId: d7e722c9-6fa5-4bac-8ec3-05174cd4c8db; SdkMessageProcessingStepId: eb06f709-1ecd-e211-bd85-00155d885d81; EntityName: ******; Stage: 40; MessageName: Create; AssemblyName: ****************************, ************.Plugins, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c1b635ad77c3aa7c; ClassName: *****************; Exception: Unhandled Exception: System.InvalidOperationException: The operation ‘*************Async’ could not be loaded because it has a parameter or return type of type System.ServiceModel.Channels.Message or a type that has MessageContractAttribute and other parameters of different types. When using System.ServiceModel.Channels.Message or types with MessageContractAttribute, the method must not use any other types of parameters.

   at System.ServiceModel.Dispatcher.OperationFormatter.Validate(OperationDescription operation, Boolean isRpc, Boolean isEncoded)

   at System.ServiceModel.Dispatcher.OperationFormatter..ctor(OperationDescription description, Boolean isRpc, Boolean isEncoded)

   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter..ctor(OperationDescription description, DataContractFormatAttribute dataContractFormatAttribute, DataContractSerializerOperationBehavior serializerFactory)

   at System.ServiceModel.Description.DataContractSerializerOperationBehavior.GetFormatter(OperationDescription operation, Boolean& formatRequest, Boolean& formatReply, Boolean isProxy)

   at System.ServiceModel.Description.DataContractSerializerOperationBehavior.System.ServiceModel.Description.IOperationBehavior.ApplyClientBehavior(OperationDescription description, ClientOperation proxy)

   at System.ServiceModel.Description.DispatcherBuilder.BindOperations(ContractDescription contract, ClientRuntime proxy, DispatchRuntime dispatch)

   at System.ServiceModel.Description.DispatcherBuilder.BuildProxyBehavior(ServiceEndpoint serviceEndpoint, BindingParameterCollection& parameters)

   at System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint serviceEndpoint, Boolean useActiveAutoClose)

   at System.ServiceModel.ChannelFactory.CreateFactory()

   at System.ServiceModel.ChannelFactory.OnOpening()

   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)

   at System.ServiceModel.ChannelFactory.EnsureOpened()

   at System.ServiceModel.ChannelFactory1.CreateChannel(EndpointAddress address, Uri via)

   at System.ServiceModel.ClientBase1.CreateChannel()

   at System.ServiceModel.ClientBase1.CreateChannelInternal()

   at System.ServiceModel.ClientBase1.get_Channel()

   at *****************.BusinessProcess.EmailService.Service1SoapClient.*****************.BusinessProcess.EmailService.Service1Soap.SendSingleEMAIL(SendSingleEMAILRequest request)

   at *****************.BusinessProcess.EmailService.Service1SoapClient.SendSingleEMAIL(String userName, String password, String mobileNumber, String contenet)

   at *****************.BusinessProcess.XrmNew_Email.SendMessage(new_Email EmailContext, IOrganizationService service)

   at *****************.Plugins.PostEMAILCreateSendEMAIL.ExecutePostEMAILCreate(LocalPluginContext localContext)

   at *****************.Plugins.Plugin.Execute(IServiceProvider serviceProvider)

   at Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext context)

   at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)

Fakes Tutorial 3: Basic Shim Sample

To Begin with Basic example of Shim, We have 3 Projects and these are on same lines as that of previous blogpost “Basic Stub Sample“.

I’ve not used any System dll in this case so that it is easier to relate between differences in Stub and Shim. Projects are:

  1. BasicShim : This is simple class library with one method which is to be tested with Fakes Unit Testing
  2. ToBeShimmed : Contains code for an assembly which is referred in BasicShim Project and will be faked in unit test.
  3. BasicShimUnitTest: Unit test

 

Looking into Projects:

  1. ToBeShimmed

    Opposed to ToBeStubbed project this project does not contain an y Interface. There is just one Class “FetchRowCount”. This class will ideally contain logic which we need to fake.

Class

Here class FetchRowCount will be used in BasicShim class and method FetchNumberOfRows will be called.

 

  1. BasicShim

     

    In BasicShim Class we have method “MethodToTest” which we are interested in testing. In case of Shim we are not passing any Interface object to method, so in unit test instead of passing object we will fake the object at runtime.

     

    Class

  2. BasicShimUnitTest:

     

    Similar to previous example, firstly we’ll add reference to all the assemblies we need, Here it will be “BasicShim” for testing and “ToBeShimmed” for Faking.

     

    After that we’ll need to fake assembly TooBeShimmed for that

            Goto ToBeShimmed in Unit test project, -> References -> Right Click assembly to be faked. -> Click Add Fakes Assembly

     

    Test Method:

    In this sample First thing we’ll have to do is create a ShimContext, this ShimContext is used to fake the assemblies at runtime. Then we’ll set the fake behavior of Method.

    If it’s a static method then use <shim class>.<method>, if it is an instance method use <shim class>.AllInstances.<method> to set faking behavior.

    Now same as in any Object Oriented Paradigm, create object, call the method and get the return value.

    Finally we will assert it with our value i.e. “Average”.


     

    Above is the most basic unit test from fakes which can be done using “shim”.

    Keep reading for more posts around this.

Fakes Tutorial 2: Basic Stub Sample

This is in continuation to “Introduction to Microsoft Fakes

To Begin with Basic example of Stub, We have 3 Projects:

  1. BasicStub : This is simple class library with one method which is to be tested with Fakes Unit Testing
  2. ToBeStubbed : Contains code for an assembly which is referred in BasicStub Project and will be faked in unit test.
  3. BasicStubUnitTest: Unit test

 

Looking into Projects:

  1. ToBeStubbed

    This project Contains One Interface “IFetchRowCount” which is referred in Class “FetchRowCount”. This class will ideally contain logic which we need to fake

 

Interface

Class

Here class FetchRowCount will be used in BasicStub class and method FetchNumberOfRows will be called.

 

  1. BasicStub

     

    In BasicStub Class we have method “MethodToTest” which we are interested in testing. Here important part is that we are passing object “fetch” to method.

    If it’s not implemented like this it will be difficult to test it using stubs (Discussion on how to handle other scenarios are for other postsJ)

     

    Class

  2. BasicStubUnitTest:

     

    First thing to be done in Unit test is to add reference to all the assemblies we need, Here it will be “BasicStub” for testing and “ToBeStubbed” for Faking.

     

    After that we’ll need to fake assembly TooBeStubbed for that

            Goto ToBeStubbed project, -> References -> Right Click assembly to be faked. -> Click Add Fakes Assembly

     

    Test Method:

    Below you can see that in test we have Created the object of Stub class StubIFetchCount generated from interface, Set the return value of method and then passed it to the method to be tested.

    Finally we have asserted it with our value “Average”.


     

    Above is the most basic unit test from fakes which can be done using “stub”. It doesn’t cover much detail but gives overview of how stub works.

    Keep reading for more posts around this.

     

    Next: “Basic Shim Sample

Fakes Tutorial 1: Introduction to Microsoft Fakes

There has been a lots of buzz going around that there is no moles for VS 2012 and now we have to use Microsoft’s OWN unit testing framework.

So to clear that:

  1. MOLES WAS from Microsoft Only.
  2. Fakes is nothing but a differently packaged Moles J. At least from functionality perspective.
  3. You are welcome to use any other Unit testing framework if it fulfills your need and a compatible version is out there for VS 2012.

Now to begin with fakes

What is Fakes?

Fakes is isolation framework for replacing the part of code, which you don’t have control over (like webservices). Using fakes you can write your unit test and make your code believe that the values of uncontrolled part of code are coming from original source only.

Where to use it?

Let’s say we have a web service that counts the no. of rows in a database and send an Integer value to you. Depending on the integer value you show Less for value < 100, Average for value >=100 && value <1000 and More for value >=1000.

Now you can’t predict the value you will get after the service call for a particular condition as values in database constantly change.

In given scenario you will isolate that webservice, Mock it and make your code believe that the value its getting is from original service itself. Depending on Integer value you are giving while mocking you already know the output and you can Assert your unit test case against that.

 

Above example was one of the scenarios where you can use fakes, there can be many more scenarios like isolating your own code that you have written etc…

 

Some Fakes terms.

There are two different type of fakes that you can generate.

  1. Stubs: A stub is generally used to fake the code which is designed in a way that classes are inherited from interfaces.
  2. Shims: Shims are used to point your code at runtime to a method provided in test. So, shims can be used to modify behavior of assemblies.

 

What to use?

An excerpt from MSDN to explain all that’s there to know:

[quote]As a general guide, use stubs for calls within your Visual Studio solution, and shims for calls to other referenced assemblies. This is because within your own solution it is good practice to decouple the components by defining interfaces in the way that stubbing requires. But external assemblies such as System.dll typically are not provided with separate interface definitions, so you must use shims instead.[/quote]

Queue Item Work On vs. Case Assign

.

  1. When we say Assign on a particular CRM Case then it changes the Owner of the case.

     

     

    But when we say “Work on” on a “Queue Item” then it updates “Worked By” field in “Queue Item Details” rather than changing the owner of the case.

     

     

    Many a times mistake is made in considering these functionalities as same and can lead to design flaws in Application.

     

  2. When a case is assigned “Assign” message is triggered for a plugin but when we “Work On” from “Queue”, Update message is triggered on “Queue Item”.

     

  3. Out of the box CRM 2011 doesn’t provide any functionality to keep these both in sync so custom code (plugin) will be required to keep both these values in sync.

     

  4. If you want to move a case to user queue when it is assigned to user you can use out of the box feature of case entity (but it is not same as keeping work on and assigned to in sync as it is limited till a user queue only)