Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Plugin code after Decompile

Posted on by 450

Hi there All.
Thank you for your Help till now !
As you know I have Decompiled plugin as I asked Here and This, I have some problem with the code.
I have solved some of them, But some other exists.
Here is the problem :

    public new QuoteProduct CreatePreImageInstance()
    {
        QuoteProduct result = null;
        if (context.PluginExecutionContext.PreEntityImages.Contains(EntityResource.QuoteProduct) &&
            context.PluginExecutionContext.PreEntityImages().get_Item(EntityResource.QuoteProduct) != null)
        {
            Entity val = context.PluginExecutionContext.get_PreEntityImages().get_Item(EntityResource.QuoteProduct);
            result = val.ToEntity<QuoteProduct>();
        }
        return result;
    }

I changed this to :

    public new QuoteProduct CreatePreImageInstance()
    {
        QuoteProduct result = null;
        if (context.PluginExecutionContext.PreEntityImages.Contains(EntityResource.QuoteProduct) &&
            context.PluginExecutionContext.PreEntityImages.Values.FirstOrDefault(x=>x.LogicalName==EntityResource.QuoteProduct) != null)
        {
            Entity val = context.PluginExecutionContext.PreEntityImages.get_Item(EntityResource.QuoteProduct);

            result = val.ToEntity<QuoteProduct>();
        }
        return result;
    }


The problem is this line, Did I do the right thing in changing :

            context.PluginExecutionContext.PreEntityImages().get_Item(EntityResource.QuoteProduct) != null)


to :

 context.PluginExecutionContext.PreEntityImages.Values.FirstOrDefault(x=>x.LogicalName==EntityResource.QuoteProduct) != null)


?

The value EntityResource.QuoteProduct in .resx file is : quotedetail.

I guess I have done the right thing.

Also please help me on this :

public class DetailEntityHelper
{
	public Entity MergeEntity(Entity currentEntity, Entity preImageEntity)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		AttributeCollection attributes = currentEntity.Attributes;
		AttributeCollection attributes2 = preImageEntity.Attributes;
		Entity val = new Entity(currentEntity.LogicalName);
		foreach (KeyValuePair<string, object> item in attributes2)
		{
			if (attributes.Keys.Contains(item.Key))
			{
				val.get_Attributes().set_Item(item.Key, attributes.get_Item(item.Key));
			}
			else
			{
				val.get_Attributes().set_Item(item.Key, attributes2.get_Item(item.Key));
			}
		}
		foreach (KeyValuePair<string, object> item2 in attributes)
		{
			if (!val.Contains(item2.Key))
			{
				val.Attributes.Add(item2.Key, item2.Value);
			}
		}
		return val;
	}


on the line :

				val.get_Attributes().set_Item(item.Key, attributes.get_Item(item.Key));


I know I should use Add instead of set_Item,
But the second parameter (attributes.get_Item(item.key) is my problem.

Any help will Appreciate

*This post is locked for comments

  • Verified answer
    Albert_ Profile Picture
    Albert_ 450 on at
    RE: Plugin code after Decompile

    Hi there.

    Thank you for your help.

    I finally did that by this thread.
    If you use ILSpy , And decompile all .dll files that are require and necessary and then decompile the actual dll file, it will extract just complete !

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Plugin code after Decompile

    Hi Albert,

    If your plugin is working fine after implementing images then it should be fine. When we register plugins on update message, we do not get all the field values in the plugin context, we then use plugin images to get the data of the target entity to perform business logic. That article is one of the best to understand images however if you are looking for some basics then you can refer this one as well: crmbook.powerobjects.com/.../plug-in-images-pre-vs-post

    Hope this helps.

  • Albert_ Profile Picture
    Albert_ 450 on at
    RE: Plugin code after Decompile

    I did in this way and hope it works !

  • Albert_ Profile Picture
    Albert_ 450 on at
    RE: Plugin code after Decompile

    I just did sir.

    ;-)

    Thank you for mentioning.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Plugin code after Decompile

    If you appreciate other's help close previous threads using "Did this answer your question" section. Otherwise I'll merge this thread with ancestors you mentioned.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans