Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Sales forum / System.NotImplementedE...
Sales forum

System.NotImplementedException: The method or operation is not implemented

Posted on by Microsoft Employee

I am very new to CRM technology as well as to .NET framework. This is one of my first programs I'm trying to execute. I am getting this error when I'm trying to run my Plugin. I am trying to auto populate the credit limit field in my Account entity as soon as user provides the countrycode while creating a record in account. Build was successful and I have registered my plugin. Please give your comments on the error as well as guide me if there are other issues in the program. Since this exception error was the first one I'm not sure if any more errors are there or not.

Here is the code:

using Microsoft.Xrm.Sdk.Query;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace Microsoft.Xrm.Sdk

{

    namespace PSPlugins

    {

        public class SetDefaultCreditLimitPlugin : IPlugin

        {

            public void Execute(IServiceProvider serviceProvider)

            {

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

                //check if pre-operation stage

                if (context.Stage != 20)

                    throw new InvalidPluginExecutionException("Must run as pre operation stage 20");

                if (context.MessageName != "Create")

                    throw new InvalidPluginExecutionException("Registered for " + context.MessageName + " only create is supported");

                if (context.PrimaryEntityName != "Account")

                    throw new InvalidPluginExecutionException("Registered for " + context.PrimaryEntityName + " entity and only account is supported");

                ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

                tracingService.Trace("Hello from the plug-in");

                Entity account = context.InputParameters["Target"] as Entity;

                tracingService.Trace("Check if credit limit is set");

                if (account.Contains("creditlimit"))

                    return;

                tracingService.Trace("Get Country code from account");

                string countrycode = string.Empty;

                if (account.Contains("address1_country"))

                    countrycode = account.GetAttributeValue<string>("address1_country");

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

                IOrganizationService service = serviceFactory.CreateOrganizationService(null);

                QueryExpression query = new QueryExpression()

                {

                    EntityName = "m3_defaultcreditlimit",

                    ColumnSet = new ColumnSet("m3_creditlimit")

                };

                query.Criteria = new FilterExpression();

                query.Criteria.AddCondition("m3_countrycode", ConditionOperator.Equal, countrycode);

                var queryResults = service.RetrieveMultiple(query);

                tracingService.Trace("Query Completed Found " + queryResults.Entities.Count);

                if (queryResults.Entities.Count == 0)

                    throw new InvalidPluginExecutionException("Default for country " + countrycode + " is not configured");

                tracingService.Trace("Setting default value on account");

                var defaultLimitEntity = queryResults.Entities[0];

                account["creditlimit"] = defaultLimitEntity.GetAttributeValue<Money>("m3_creditlimit");

            }

        }

    }

}

Thanks!

Categories:
  • Abby Kong Profile Picture
    Abby Kong 6 on at
    RE: System.NotImplementedException: The method or operation is not implemented

    Hi Tushar,

    Refer MSDN for this class, there is an example at the bottom of this page:

     https://msdn.microsoft.com/en-us/library/system.notimplementedexception(v=vs.110).aspx

    There is not much to check in samples for NotImplementedException, because it is just a system exception from .net framework, as the name suggested to say it's not yet developed.  

    You can also use it during development while some features are not yet developed, and you want to get rid of build error to test/internalRelease other features.

    If you search in visual studio in the plugin project, can you find any in your source code?

    business.png

    Also, when you see a business process error popup, use the download log file button to download ErrorDetail.txt to see more details.

    business.png

    Regards,

    Abby

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: System.NotImplementedException: The method or operation is not implemented

    Hi Abby,

    Thanks for your reply. Can you please give me a sample code or a snippet so that I can refer how can I apply this exception in my code. I am not finding any blogs related to its implementation.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: System.NotImplementedException: The method or operation is not implemented

    Thanks for your reply Ashay. I tried doing this, but still it shows the same error. I have changed framework version to 4.5

  • Ashay Shingornikar Profile Picture
    Ashay Shingornikar 135 on at
    RE: System.NotImplementedException: The method or operation is not implemented

    Hi Tushar,

    I have encountered this issue earlier in last month.

    This usually occurs when your dynamics 365 version is 9 and you try to build your plugin with .net framework 4.6 and above.

    They are not compatible.

    Also there is issue  in Dynamics 365 Version 9 where a call to ITracingService.Trace(message) from inside a plugin caused the following exception:

    System.MissingMethodException: Method not found: '!!0[] System.Array.Empty()'   or

    System.MissingMethodException: Method not found:

    'System.String System.String.Format(System.IFormatProvider, System.String, System.Object)'.

    I would recommend you to use .net framework 4.5 to build plugin and then use.

    Hope this helps.

    Regards,

    Ashay

  • Suggested answer
    Abby Kong Profile Picture
    Abby Kong 6 on at
    RE: System.NotImplementedException: The method or operation is not implemented

    Hello Tushar,

    Please search in your plugin project source code for throw new NotImplementedException()

     

    This is common in .NET that after you created a function, you can throw this NotImplementatedException and come back to implement it later. So that there will not be any build error even though your function does not have expected return type. Sometimes Visual Studio will automatically insert this for you.

     

    The code you posted does not have this exception, I guess exception was thrown in other plugins before this plugin is executed.

     

    Also, download ErrorDetail.txt on Business Error Popup and have a look inside, it should tell you exactly which plugin this Exception is from.

     

    Regards,

    Abby

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: System.NotImplementedException: The method or operation is not implemented

    Thanks David for your reply.

    Trace logs show that the code did not even reach the first trace output.

    I also want to bring to your notice that if I am running the code with C# plugin assembly which is in-built in Visual Studio, the code is running fine and giving expected output.

    Only when I'm trying to create all the IPlugin instances one by one from the scratch I am getting the error.

  • David Jennaway Profile Picture
    David Jennaway 14,063 on at
    RE: System.NotImplementedException: The method or operation is not implemented

    How far does the code get before you get the exception ?

    One thing I've noticed is the PrimaryEntityName is always the lowercase name, so the code should be the following, but that wouldn't cause the error you're getting:

     if (context.PrimaryEntityName != "account")


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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

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,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans