1. Miraben Apani
  2. SnapDevelop
  3. Wednesday, 8 February 2023 18:25 PM UTC

This "How-to" question is in continuation of the post I posted earlier: Web API transaction management and multiple DWs update/save changes in single transaction. (appeon.com) and got response as well.

Logan,

Thanks very much for the example of controller code. it is working well.

I have a question I am getting this error "System.ArgumentNullException: Value cannot be null. (Parameter 'name')" and I am thinking it is because "datacontext" is missing in below code snippet:

IDataStore ds1= dataUnpacker.GetDataStore("dw_1");
IDataStore ds2= dataUnpacker.GetDataStore("dw_2");

 I am not able to define datacontext in controller & call it in above code snippet.

any documentation/ "how-to" define and use Data Context in Controller? in my Service Implementation (Service Class) I already have data context defined.

Thanks !

Francisco Martinez @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 8 February 2023 18:33 PM UTC
  2. SnapDevelop
  3. # 1

Hi Miraben,

How are you defining/using the DataContext in your service?

Regards,
Francisco

Comment
  1. Francisco Martinez @Appeon
  2. Wednesday, 8 February 2023 18:40 PM UTC
Also, please show us more of the error you're getting. The stack trace should tell us better where the exception is being raised.
  1. Helpful
  1. Miraben Apani
  2. Thursday, 9 February 2023 13:05 PM UTC
Here is Exception Details:

System.ArgumentNullException: Value cannot be null. (Parameter 'name')

at SnapObjects.Commons.Check.NotNull[T](T value, String parameterName)

at DWNet.Data.DataStoreBase..ctor(String name)

at DWNet.Data.DataStore..ctor(String dataObject)

at DWNet.Data.DataStoreUnpackerExtensions.GetDataStore(IDataUnpacker dataUnPackage, String key, DataContext context, String name, DataFormatSetting setting)

at DWNet.Data.DataStoreUnpackerExtensions.GetDataStore(IDataUnpacker dataUnPackage, String key, DataContext context, String name)

at DWNet.Data.DataStoreUnpackerExtensions.GetDataStore(IDataUnpacker dataUnPackage, String key, DataContext context)

at Xyz_poc_only_Abc.Controllers.AbcServiceController.Modify(IDataUnpacker dataUnpacker) in C:\Xyz_Appeon_POC\Xyz_poc_only\Xyz_poc_only\Controllers\AbcServiceController.cs:line 86

at lambda_method(Closure , Object , Object[] )

at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)

at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)

at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()

at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)

at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
  1. Helpful
  1. Francisco Martinez @Appeon
  2. Thursday, 9 February 2023 16:50 PM UTC
Please share with us the versions of the NuGet packages your project is using

Regards - Francisco
  1. Helpful
There are no comments made yet.
Miraben Apani Accepted Answer Pending Moderation
  1. Wednesday, 8 February 2023 18:48 PM UTC
  2. SnapDevelop
  3. # 2

In my service class I have Datacontext as below:

  public class AbcService : IAbcService
    {
        private readonly sample.DataContext _dataContext;
        
        public AbcService(sample.DataContext dataContext)
        {
            _dataContext = dataContext;
        }

}

 

In my Controller I have below code snippet:

private readonly IAbcService _abcservice;
         
       
        public AbcServiceController(IJAbcService abcservice)
        {
            
            _abcservice = abcservice;
            
        }

 

 

Comment
  1. Miraben Apani
  2. Wednesday, 8 February 2023 19:48 PM UTC
Francisco, you are correct!

even though I pass data context, it still gives me same error.

Any idea/suggestion what could be causing this?



Thanks.
  1. Helpful
  1. Francisco Martinez @Appeon
  2. Wednesday, 8 February 2023 21:58 PM UTC
Please provide the entire error message, as well as a short sample of your code so that we can know that's actually happening

Regards - Francisco
  1. Helpful
  1. Logan Liu @Appeon
  2. Thursday, 9 February 2023 02:08 AM UTC
Hi Miraben,



Except for the exception, could you provide your sample PB and C# project here?



You can also refer to the code that contains a similar usage:

https://docs.appeon.com/powerscriptmigrator2022/PB_to_CSharp_Porting_Business_Logics_with_Minimum_Refactoring_Hassle/#prerequisites

Search "dataUnpacker.GetDataStore" in the finished C# solution.



Regards, Logan



  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.