How to Resolve a PowerPhoto and Silverlight Issue

Have you been having some issues with errors in Silverlight since the last Silverlight upgrade in May? Well, so have we! Some parts and pieces of our PowerPack add-ons are built in Silverlight, which is how we came across this issue.

PowerPhoto users specifically have been reporting that they were seeing the below error when trying to load a picture on their CRM records:

PowerPhoto and Silverlight issue - error

The PowerPhoto error stems from an issue that was introduced in the latest version of Silverlight. To rectify this issue, please follow the steps below. Note that this does need to be done on each machine that is experiencing the issue.

1.       Navigate to http://www.microsoft.com/en-us/download/details.aspx?id=36946

silverlight issue image 2

2.       Download the file called 20125.00runtimeSilverlight_Developer_x64.exe (for 64 bit Silverlight installations) OR 20125.00runtimeSilverlight_Developer.exe and click Next.

solving the powerphoto and silverlight issue

3.       When prompted, click Run.

4.       Click on Install Now, and wait for the program to install.

5.       For the changes to take effect, please restart your computer.

Downloading the developer Silverlight above will resolve the error in PowerPhoto, and could resolve some other Silverlight issues you've been experiencing as well.

Happy CRM'ing!

Impersonating a Dynamics CRM User in Silverlight

Impersonating a Dynamics CRM user is fairly straightforward in server-side code and using SDK. We have covered it before in the blog post How to Impersonate in Microsoft Dynamics CRM.

But how can we do this in client-side code, specifically Silverlight?

The first obvious approach would be not to use the context to obtain service, but to create your own, and define the username/password for another user in the code. This is widely used in Dynamics CRM portals and many server-side implementations, but we try to avoid this method in client-side applications such as Silverlight.

For that reason, the approach we would use in this case is impersonating the CallerId in the SOAP header of the call. We do not need to know anyone's password or even username, just their CRM GUID:

using (var scope = new OperationContextScope(service.InnerChannel))

{
    //Impersonate caller Id
    ns = "http://schemas.microsoft.com/xrm/2011/Contracts";
    callerGuid = "{AAAAAAAA-0000-0000-0000-000000000000}"); //replace with real GUID
    var userHeader = MessageHeader.CreateHeader("CallerId", ns, callerGuid);
    OperationContext.Current.OutgoingMessageHeaders.Add(userHeader);
    service.CreateAsync(entity);
}

In one implementation of this code, we needed this to have a custom audit of the user's actions in the Silverlight component. If we're going to do this, we want any user action to happen with the user's own context and credentials, so that CRM security is used for the calls and so that we can get the correct "modified by" data. However, we don't want to give the user any unnecessary permissions to the audit entity, or else a malicious user could tamper with the auditing.

So let's run a few tests:

A user with absolutely no permissions for the entity will fail to impersonate:

impersonating a Dynamics CRM user - no permissions

A user will need at least the minimum read/create permission for the entity before the delegation can work:

impersonating a Dynamics CRM user - some permissions

The created records will be created by and owned by a service user, and "Created By (Delegate)" will be our actual user:

Note that while users have basic permission to the entity, they cannot see any of the created records because they are owned by the service user.

There you go—impersonate away!

If this relevant to your interests, you might also be interested in our Dear Joe CRM post on the differences between JavaScript, Silverlight and Plug-ins for Dynamics CRM.

Happy CRM'ing!

Dear JoeCRM – Volume #3: Javascript, Silverlight, Plugins and Processes

Dear JoeCRM,

I am confused about all this talk about JavaScript, Silverlight, Plugins and processes. They all seem to be capable of solving the same problems. Can you help me to understand the difference at high level and what to use when?

-Confused

Dear Confused,

Main differences listed below:

JavaScript

Silverlight

Plugins

Processes

Happy CRM'ing!

# CRM Expert, Microsoft Dynamics CRM, CRM How To