Base solution for your next web application
Open Closed

Exception in invoking service from myapp in different console app #9894


User avatar
0
KPCS created

Hi Team,

We are getting following issue. Request you to please provide the solution ASAP.

Exception: The source IQueryable doesn't implement IAsyncEnumerable<MyApp.MyDto.Dtos.AddressCountryLookupTableDto>. Only sources that implement IAsyncEnumerable can be used for Entity Framework asynchronous operations

We tried using .Net Core based console app with aspnetzero support. In that we tried to do dependency injection of the services from MyApp. We tried invoking method from AddressesAppService from MyApp.

Below are the details of MyConsoleAppModule.cs, MyConsoleAppDbContext.cs and Program.cs code

1) Below is the module MyConsoleAppModule.cs - DependsOn(typeof(AbpEntityFrameworkModule))] public class MyConsoleAppModule : AbpModule

a> In its PreInitialize() , we read appsettings.json and did

IConfigurationRoot configuration = builder.Build(); Configuration.DefaultNameOrConnectionString = //connection string for DB of MyApp

b> In its Initialize(), We did service registration for AddressesAppService and what it depends on as below-

IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly()); IocManager.Register<IAddressesAppService, AddressesAppService>(DependencyLifeStyle.Transient); IocManager.Register<IRepository<Address, long>>(DependencyLifeStyle.Transient); IocManager.Register<IRepository<Country, long>>(DependencyLifeStyle.Transient); IocManager.Register<IRepository<StateOrProvince, long>>(DependencyLifeStyle.Transient); IocManager.Register<IAddressesExcelExporter, AddressesExcelExporter>(DependencyLifeStyle.Transient); IocManager.Register<ITempFileCacheManager, TempFileCacheManager>(DependencyLifeStyle.Transient);

2) Also, we had MyConsoleAppDbContext.cs -

public class MyConsoleAppDbContext : AbpDbContext where we added below DbSet for the tables needed by AddressesAppService as below public virtual IDbSet<Address> Addresses { get; set; } public virtual IDbSet<Country> Countries { get; set; } public virtual IDbSet<StateOrProvince> StateOrProvince { get; set; }

public MyConsoleAppDbContext() : base("Default") {

}

public MyConsoleAppDbContext(string nameOrConnectionString) : base(nameOrConnectionString) {

}

  1. With above, in Program.cs -

static async Task Main(string[] args) { using (var bootstrapper = AbpBootstrapper.Create<MyConsoleAppModule>()) { bootstrapper.IocManager .IocContainer .AddFacility<LoggingFacility>(f => f.UseAbpLog4Net().WithConfig("log4net.config"));

    bootstrapper.Initialize();

    {
        //Test_Way_MyAppAsync(bootstrapper.IocManager);
        var result = await Test_Way_MyAppAsync(bootstrapper.IocManager);
        if (result != null)
        {
            Console.WriteLine(result.ToList().Count);
        }
    }
}

public static async Task&lt;List&lt;AddressStateOrProvinceLookupTableDto&gt;> Test_Way_MyAppAsync(IIocManager iocManager)
{
  var addressesAppService = iocManager.Resolve&lt;AddressesAppService&gt;();
//below was a sync result returning service method and it worked well
    //var result = addressesAppService.Object.GetAll();
    //Console.WriteLine(result.StateOrProvinceId);

//below was a async result returning service method and here we had the exception var result = await addressesAppService.GetAllStateOrProvinceForTableDropdown(); //return result; return await Task.FromResult(result.ToList()); } }

Thanks,

Kind Regards, Kumar Prashant


9 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    1. Could you share the content of GetAllStateOrProvinceForTableDropdown ?
    2. Is GetAllStateOrProvinceForTableDropdown working on your web app ?

    Thanks,

  • User Avatar
    0
    KPCS created

    Hi,

    Please refer following link for the code of GetAllStateOrProvinceForTableDropdown:

    https://prorigosoftware.sharepoint.com/Shared%20Documents/Forms/AllItems.aspx?id=/Shared%20Documents/AspNetZeroSupport&p=true&originalPath=aHR0cHM6Ly9wcm9yaWdvc29mdHdhcmUuc2hhcmVwb2ludC5jb20vOmY6L2cvRWpXRldJTTBJUFpCbXhjU1Fsc3VxbW9CaEs3ME1qcGFxR05adS00aFcxc01UZz9ydGltZT1lS0hrcnFTZDJFZw

    The details of the code are:

    Interface/ and Implementation/ folders containing service, interface, dtos for City which is representative code of the service/method which is consumed in ReceiverApp

    In ReceiverApp/ folder the code which does dependency injection of required City services and its inner dependecies and code to call the service is present. This is where we get the exception

    The code is representative and not complete code, but only the relevant part in Interfaces/ Implementation/ this is done for privacy purpose (replacing project name, namespace etc.). Also a baseservice which is extended in CitiesAppService is not included. But this looks irrelevant to problem at hand.

    We have ensured that GetAllCities() work correctly from Swagger UI which does http based call to the service method. Methods like this also work equally well from Angular UI which is again http based call mechanism.

    In place of GetAllStateOrProvinceForTableDropdown , ​please refer to GetAllCities(). Syntactically it is exacly same.

    Thanks,

    Kind Regards, Kumar Prashant

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @KPCS

    I couldn't access the link you have shared. Is it possible to share your project with [email protected] and also share the steps to reproduce this problem. If this is working from swagger ui, probably there is a module dependency problem.

  • User Avatar
    0
    KPCS created

    Please use following github link to download the code:

    https://github.com/kumaresop/MyApp-ReceiverApp-Exception

    Thanks,

    Kind Regards, Kumar Prashant

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @KPCS

    Thanks. But, I think the problem is somewhere else. Is it possible to share your projects via email with [email protected] and also share steps to reproduce this problem ?

  • User Avatar
    0
    KPCS created

    Hi,

    Please see the following link to download the project:

    ###############################

    Steps:

    1. Extract zip
    2. Open KPCSDemo.Web.sln in visual studio and run (first Get DB Setup using migration and then run Web.Host project. This will launch swagger UI. Here API GetAllCities() can be accessed.
    3. Open KPCSDemo.Receiver.App.sln in visual studio and run KPCSDemo.Receiver.App. This will call the above Service Method and will throw the mentioned exception.

    Thanks,

    Kind Regards, Kumar Prashant

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @KPCS,

    I have deleted the link you have shared after downloading the project. This website is open to everyone and everyone can download your project.

    I will investigate the problem and share result with you.

  • User Avatar
    0
    KPCS created

    Hi Team,

    Any update?

    Kind Regards, Kumar Prashant

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @KPCS

    We couldn't run the shared MyApp-ReceiverApp-Exception project. Is it possible for you to share both projects via email if you haven't solved this problem ?

    Thanks,