Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

An unexpected error occurred from ISV code

Posted on by 130

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
    himy10 130 on at
    RE: An unexpected error occurred from ISV code
  • himy10 Profile Picture
    himy10 130 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);
    }
    }
    }
    }
    }

  • 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
    Sateesh123 130 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

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans