public static void DeclareNewCustomReportItem(string itemName, Type type)
        {
            if (!typeof(ICustomReportItem).IsAssignableFrom(type))
            {
                throw new ArgumentException("The type does not implement the ICustomReportItem interface: " +
                                            type == null ? "null" : type.Name);
            }

            if (CustomReportItemEntries == null)
            {
                RdlEngineConfigInit();
            }

            // Let's manage doublons, if any.
            CustomReportItemEntry item;

            if (!CustomReportItemEntries.TryGetValue(itemName, out item))
            {
                CustomReportItemEntries[itemName] = new CustomReportItemEntry(itemName, type, null);
            }
            else if (!item.Type.Equals(type))
            {
                throw new ArgumentException("A different type of CustomReportItem with the same has already been declared.");
            }
        }
        public static ICustomReportItem CreateCustomReportItem(string friendlyTypeName)
        {
            CustomReportItemEntry crie = null;

            if (!CustomReportItemEntries.TryGetValue(friendlyTypeName, out crie))
            {
                throw new Exception(string.Format("{0} is not a known CustomReportItem type", friendlyTypeName));
            }
            if (crie.Type == null)
            {
                throw new Exception(crie.ErrorMsg ??
                                    string.Format("{0} is not a known CustomReportItem type", friendlyTypeName));
            }

            ICustomReportItem item = (ICustomReportItem)Activator.CreateInstance(crie.Type);

            return(item);
        }
        static void GetCustomReportItem(Dictionary <string, CustomReportItemEntry> crieDir, XmlNode xNode)
        {
            string friendlyTypeName = null;
            string codemodule       = null;
            string classname        = null;

            foreach (XmlNode xNodeLoop in xNode.ChildNodes)
            {
                if (xNodeLoop.NodeType != XmlNodeType.Element)
                {
                    continue;
                }
                switch (xNodeLoop.Name)
                {
                case "Type":
                    friendlyTypeName = xNodeLoop.InnerText;
                    break;

                case "CodeModule":
                    codemodule = xNodeLoop.InnerText;
                    break;

                case "ClassName":
                    classname = xNodeLoop.InnerText;
                    break;

                default:
                    break;
                }
            }
            if (friendlyTypeName == null)
            {
                return;         // nothing to do if no provider specified
            }
            CustomReportItemEntry crie;

            try
            {   // load the module early; saves problems with concurrency later
                string   msg        = null;
                Type     dotNetType = null;
                Assembly la         = null;
                if (codemodule != null && classname != null)
                {
                    // Check to see if previously loaded.  Many CustomReportItems share same CodeModule.
                    Assembly[] allLoadedAss = AppDomain.CurrentDomain.GetAssemblies();
                    foreach (Assembly ass in allLoadedAss)
                    {
                        // Added "!ass.IsDynamic" to prevent "NotSupportedException" of the property Location (new since framework 4.0) by new dynamic assemblies of the new .NET framework update (2015).
                        if (!ass.IsDynamic && ass.Location.EndsWith(codemodule, StringComparison.CurrentCultureIgnoreCase))
                        {
                            la = ass;
                            break;
                        }
                    }

                    if (la == null)     // not previously loaded?
                    {
                        la = Utility.Assembly.AssemblyLoadFrom(codemodule);
                    }
                    if (la == null)
                    {
                        msg = string.Format("{0} could not be loaded", codemodule);
                    }
                    else
                    {
                        dotNetType = la.GetType(classname);
                    }
                }

                crie = new CustomReportItemEntry(friendlyTypeName, dotNetType, msg);
                crieDir.Add(friendlyTypeName, crie);
            }
            catch (Exception e)
            {      // keep exception;  if this CustomReportItem is ever used we will see the message
                crie = new CustomReportItemEntry(friendlyTypeName, null, e.Message);
                crieDir.Add(friendlyTypeName, crie);
            }
        }