1 2 Previous Next 16 Replies Latest reply: Nov 5, 2012 9:57 AM by Ron M-Oracle RSS

    NullReferenceException error

    dmccall
      2.     I created a validator for Sourcing Approvals (type 5012) where I want to get EntityViewerSections for the SourcedSpecification of the Sourcing Approval in context. I get a NullReferenceException error (i.e. Object reference not set to an instance of an object) for the code below. Any ideas what is causing the NullReferenceException?

      protected override bool Validate_Internal(IValidationContext ctx, object propVal)
      {
      try
      {
      var sourcingApproval = ctx.ValidationTarget.As<ISourcingApproval>();
      var sourcedSpec = sourcingApproval.SourcedSpecification;
      if (sourcedSpec is IIngredientSpecification)
      {
      IEntityViewerConfig vc = null;
      vc = new IngredientParentViewerConfig();
      var specSections = vc.GetEntityViewerSections(sourcedSpec, null);
      }
      }
      catch (Exception ex)
      {
      var errorId = EventLogWriter.AddEntry("{0}".F(ex.ToString()), EventLogEntryType.Error);
      AddValidationError(m_bReport, ctx, "An error has occured in ScrmRestrictedIngredientsValidator. Error Id #{0} has been assigned as the Id error. Please use this error Id #{0} when refering to this error.".F(errorId), GetType());
      }
      return ctx.ErrorCount == 0;
      }

      Edited by: user12207415 on Oct 26, 2012 9:35 AM
        • 1. Re: NullReferenceException error
          Ron M-Oracle
          Since this validator is your own code, try to debug it, and see what is causing the NullReferenceException. Also, seeing the full stack trace usually helps diagnose this better, by giving the class and method names.
          • 2. Re: NullReferenceException error
            dmccall
            I caught the exception. At a closer inspection the InnerException was null but here’s the StackTrace. It errored inside GetEntityViewerSections.

            at Xeno.Prodika.GSMLib.Common.GSMConfiguration.LocalGSMConfiguration.GetConfigIntValue(String featureKey, Int32 defaultValue)
            at Xeno.Prodika.GSMLib.Common.GSMConfiguration.LocalGSMConfiguration.get_MaxWhereToUseParentSpesTotal()
            at Xeno.Prodika.GSMLib.ViewerConfig.SpecViewMaxValidationHelper.ValidateParent(Int32 count)
            at Xeno.Prodika.GSMLib.ViewerConfig.StandardLoadingContext.AddItemToCollections(Object item)
            at Xeno.Prodika.GSMLib.ViewerConfig.SpecEntityParentViewerConfigBase.InitializeEntityForLoad(ILoadingContext loadingContext, String sectionKey, String typeName)
            at Xeno.Prodika.GSMLib.ViewerConfig.IngredientParentViewerConfig.LoadParents(ILoadingContext loadingContext)
            at Xeno.Prodika.GSMLib.ViewerConfig.SpecEntityParentViewerConfigBase.GetUnFilteredEntityViewerSections(Object root, Object customArg)
            at Xeno.Prodika.GSMLib.ViewerConfig.SpecEntityViewerConfigBase.GetEntityViewerSections(Object root, Object customArg)
            at Tyson.Pdm.Validator.Lib.ScrmValidators.ScrmRestrictedIngredientsValidator.Validate_Internal(IValidationContext ctx, Object propVal) in c:\PDMProjects\Prodika.Extensions\Dev\Trunk\Tyson.Pdm.Validator.Lib\ScrmValidators\ScrmRestrictedIngredientsValidator.cs:line 56
            • 3. Re: NullReferenceException error
              Ron M-Oracle
              I think that since you are in SCRM, you will need to add those config settings (that you added before) to the SCRM web.config.
              • 4. Re: NullReferenceException error
                dmccall
                "David, can you reply back to the thread asking Milner if they could refresh our memory as to what config changes he’s talking about. I just did a file compare of the web.configs in gsm and scrm and I didn’t see anything that stood out that would fix the problem. Hai"
                • 5. Re: NullReferenceException error
                  Trey
                  Ron, I have checked and we have never made any changes to the 6.1 SCRM web.config. I have to keep tabs on any changes to the original config files.
                  --Trey                                                                                                                                                                                                                                                                                                                       
                  • 6. Re: NullReferenceException error
                    Ron M-Oracle
                    The stack trace looks like it has to do with the Where Used functionality that you implemented previously. I believe you did this in your own web services, or something like that, in the Integration web application. When you implemented that, you had to add a setting to the Integration\web.config, to include the GSMSettings node. Since you are calling a validator in SCRM which requires that configuration data, you'll have to add that setting to the scrm\web.config too.
                    • 7. Re: NullReferenceException error
                      Hai Ha
                      thanks ron. i was able to find the GSMSettings node you mentioned and saw the config changes we did to get it to work in gsm. i tried adding the same node to the web.config in scrm and got the following error below. so i tried adding a new section called SCRMSettings and kept getting the error below. i modified the Web.config (in scrm), DeployedConfig.config, and CustomerSettings.config. i'm sending you an email with screenshots so you can see my config changes. can you tell me what i did wrong or what i might have missed?

                      Config Error: The configuration section 'GSMSettings' cannot be read because it is missing a section declaration
                      • 8. Re: NullReferenceException error
                        Ron M-Oracle
                        I assume that you should have a GSMSettings section, in the scrm web.config, because the Where Used functionality is looking for that specifically, not for an SCRMSettings section. You should do the same thing you did in the Integration web.config

                        Give that a try and let us know
                        • 9. Re: NullReferenceException error
                          Hai Ha
                          so i took out all the changes i did and reverted the configs back to where they were. after doing so i only added the GSMSettings node to the scrm web.config and i still got the config error above. i'm emailing you another screenshot.
                          • 10. Re: NullReferenceException error
                            Ron M-Oracle
                            Your screenshot shows that the error it is getting is that you didn't add then new section to the configsections node. Take a look at your integration web.config and see how you have it set up there.
                            • 11. Re: NullReferenceException error
                              Hai Ha
                              so i found the missing line i needed for the configsections node and put it in the srcm web.config. i'm now able to call the GetEntityViewerSections without error but now i'm getting another NullReferenceException (stack trace is at the bottom). here's the line of code it's happening on. any ideas as to why?

                              var specSections = vc.GetEntityViewerSections(sourcedSpec, null);
                              var formulationSpecs = (new ArrayList(specSections)
                              .Cast<IEntityViewerSection>()
                              .SelectMany(entityViewerSection => entityViewerSection.Items.Cast<IEntityViewerItem>(),
                              (entityViewerSection, item) => PdmGateway.GetBaseSpecByPkid(item.PKID))
                              .Where(x => x is IFormulationSpecification)
                              .Where(SpecWorkflowTagEvaluator.IsSpecApproved))
                              .ToArray();

                              Here's what GetBaseSpecByPkid does:

                              public IBaseSpec GetBaseSpecByPkid(string pkid)
                              {
                              return pkid == "" ? null : GetIXDataObject<IBaseSpec>(pkid);
                              }

                              Here's the stack trace:

                              at Xeno.Prodika.Services.ServiceManager.Xeno.Prodika.Services.IServiceManager.get_Item(String key)
                              at Oracle.Agile.PlmProcess.PLM4PExtensionUtils.Common.ServiceHelper.get_ClassScopedSpecService()
                              at Oracle.Agile.PlmProcess.PLM4PExtensionUtils.Workflow.SpecWorkflowTagEvaluator.IsSpecApproved(IBaseSpec baseSpec)
                              at System.Linq.Enumerable.<>c__DisplayClassf`1.<CombinePredicates>b__e(TSource x)
                              at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
                              at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
                              at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
                              at Tyson.Pdm.Validator.Lib.ScrmValidators.ScrmRestrictedIngredientsValidator.Validate_Internal(IValidationContext ctx, Object propVal) in c:\PDMProjects\Prodika.Extensions\Dev\Trunk\Tyson.Pdm.Validator.Lib\ScrmValidators\ScrmRestrictedIngredientsValidator.cs:line 63
                              • 12. Re: NullReferenceException error
                                Ron M-Oracle
                                The stack trace shows the following:
                                get_ClassScopedSpecService()
                                you'll need to add the class scoped spec service to your <services> node in the web.config

                                <config key="ClassScopedSpecificationService" value="Services/GSMSpecServiceClassScoped"/>

                                you may run into other services that need to be declared in similar manner, so if you get another exception with
                                at Xeno.Prodika.Services.ServiceManager.Xeno.Prodika.Services.IServiceManager.get_Item(String key)
                                take a look at what called it and see if you can determine which service you need.
                                • 13. Re: NullReferenceException error
                                  Hai Ha
                                  i was able to knock out a couple of the services but now i have this one. any ideas?

                                  at Xeno.Prodika.GSMLib.Utils.GSMUtilityFunctions.IsSpecApproved(ISpecificationService specService)
                                  at Oracle.Agile.PlmProcess.PLM4PExtensionUtils.Workflow.SpecWorkflowTagEvaluator.IsSpecApproved(IBaseSpec baseSpec)
                                  at System.Linq.Enumerable.<>c__DisplayClassf`1.<CombinePredicates>b__e(TSource x)
                                  at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
                                  at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
                                  at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
                                  at Tyson.Pdm.Validator.Lib.ScrmValidators.ScrmRestrictedIngredientsValidator.Validate_Internal(IValidationContext ctx, Object propVal) in c:\PDMProjects\Prodika.Extensions\Dev\Trunk\Tyson.Pdm.Validator.Lib\ScrmValidators\ScrmRestrictedIngredientsValidator.cs:line 63
                                  • 14. Re: NullReferenceException error
                                    Ron M-Oracle
                                    I'm not sure how your code compiled, actually.

                                    You have the following:
                                    .Where(SpecWorkflowTagEvaluator.IsSpecApproved))
                                    But you should be passing the IsSpecApproved method the spec (IBaseSpec)
                                    1 2 Previous Next