Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

An unexpected error occurred from ISV code

(0) ShareShare
ReportReport
Posted on by 134

Hi ,

i made a plugin to check some condition .

so if that condition is not equal it show custom error message but it show in some different message 

can plz any one suggest that how to solve that problem

error show in that:

An unexpected error occurred from ISV code. (ErrorType = ClientError) Unexpected exception from plug-in (Execute): TestPlugin.ImageDemo: System.Exception: The field  count is Zero.
pastedimage1565338532517v1.png
but i want to show only The field  count is Zero..

*This post is locked for comments

  • himy10 Profile Picture
    134 on at
    RE: An unexpected error occurred from ISV code
  • himy10 Profile Picture
    134 on at
    RE: An unexpected error occurred from ISV code

    Yes, I use that code to show customized code.

    using System;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Crm.Sdk.Messages;

    namespace TestPlugin
    {
    public class ImageDemo : IPlugin
    {
    private void ThrowPluginException()
    {
    throw new InvalidPluginExecutionException("The subgrid count is Zero");
    }
    public void Execute(IServiceProvider serviceProvider)

    {

    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

    IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

    // Create service with context of current user
    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

    //create tracing service
    ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

    if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)

    {

    Entity entity = (Entity)context.InputParameters["Target"];
    if (entity.LogicalName.ToLower() != "incident") return;
    try
    {

    Entity preImage = (Entity)context.PreEntityImages["Image"];
    if (preImage.Contains("statecode"))
    {
    if (preImage.GetAttributeValue<OptionSetValue>("statecode").Value == 0)//if Pre image have priority = Low
    {
    if (entity.Contains("statecode") && entity.GetAttributeValue<OptionSetValue>("statecode").Value == 1)
    {
    if (preImage.Contains("new_subcount"))

    {
    Int32 countval = Convert.ToInt32(preImage.GetAttributeValue<Int32>("new_subcount").ToString());

    if (countval == 0)
    {
    ThrowPluginException();
    // throw new InvalidPluginExecutionException("The subgrid count is Zero");

    }


    }
    }
    }
    }
    }
    catch (Exception ex)
    {
    throw new Exception("" + ex.Message);
    }
    }
    }
    }
    }

  • MohammadFaheemuddin1600 Profile Picture
    15 on at
    RE: An unexpected error occurred from ISV code

    Hi

    Could you please provide more details or provide the the code logic you are using.

  • Sateesh123 Profile Picture
    132 on at
    RE: An unexpected error occurred from ISV code

    Hi

    throw new InvalidPluginExecutionException("type your message here..");

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans