I just tried this plugin with a CRM Online trial instance (5.0.9690.3358) and is working.
The plugin is registered on Create message, Task entity, Pre-operation, Synchronous.
using System;
using Microsoft.Xrm.Sdk;
namespace TestPlugin
{
public class MyPlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName != "task")
return;
try
{
entity.AddOrUpdate("description", "updated by plugin");
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message);
}
}
}
}
public static class ExtensionMethods
{
public static void AddOrUpdate(this Entity e, string propertyName, object value)
{
if (e.Attributes.Contains(propertyName))
{
e.Attributes[propertyName] = value;
}
else
{
e.Attributes.Add(propertyName, value);
}
}
}
}
This to be sure that the problem is not the extension method.
My best guess (in order):
- One project in your solution is compiled with .NET Framework 4.5
- You are using old SDK version
- You are using old Plugin Registration Tool