Extension Methods for CRM 2011 Online Instances Causing TypeLoad Exceptions -


i writing plugin client on crm online trial tenant (so assume has latest patches etc.) , have come across error i’ve not seen before. speaking use extension method along lines of following, clarity of code really:

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);     } } 

nothing hugely controversial there think? anyway whatever reason if include class file part of plugin client, following error thrown:

unhandled exception: system.servicemodel.faultexception`1 system.typeloadexception: microsoft dynamics crm has experienced error. reference number administrators or support: #9a0442a7  [foo.bar.plugins: foo.bar.plugins.trackactivity] [6ed535ec-c7a8-e211-858f-3c4a92dbdc37: foo.bar.plugins.trackactivity: create of task] 

there no trace included, shows plugin isn’t executed (even if first line of code throwing exception!).

i did bit of digging , seems client/instance @ least: - if include static class file (public static class foo) method, error, whether class used code or not - when error generated, plugin not executed (the exception occurs before code)

anyone seen before or have insight system.typeloadexception exceptions?

i tried plugin crm online trial instance (5.0.9690.3358) , working.

the plugin 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"] entity)             {                 entity entity = (entity)context.inputparameters["target"];                 if (entity.logicalname != "task")                     return;                  try                 {                     entity.addorupdate("description", "updated 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 sure problem not extension method.

my best guess (in order):

  • one project in solution compiled .net framework 4.5
  • you using old sdk version
  • you using old plugin registration tool

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -