ralmsdeveloper / EntityFrameworkCore.FirebirdSQL

FirebirdSQL database provider for Entity Framework Core.
Other
44 stars 26 forks source link

report bug 2.1.1 to 2.1.2 #42

Open ralmsdeveloper opened 6 years ago

ralmsdeveloper commented 6 years ago

from @mrjohnr on 11 de set de 2018 09:26 BRT

fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
System.NullReferenceException: Object reference not set to an instance of an object.
   at EntityFrameworkCore.FirebirdSql.Query.Sql.Internal.FbQuerySqlGenerator..ctor(QuerySqlGeneratorDependencies dependencies, SelectExpression selectExpression, IFbOptions fBOptions)
   at EntityFrameworkCore.FirebirdSql.Query.Sql.Internal.FbQuerySqlGeneratorFactory.CreateDefault(SelectExpression selectExpression)
   at Microsoft.EntityFrameworkCore.Query.Expressions.SelectExpression.CreateDefaultQuerySqlGenerator()
   at Microsoft.EntityFrameworkCore.Query.Internal.ShaperCommandContext.<NotifyReaderCreated>b__14_0(FactoryAndReader s)
   at Microsoft.EntityFrameworkCore.Internal.NonCapturingLazyInitializer.EnsureInitialized[TParam,TValue](TValue& target, TParam param, Func`2 valueFactory)
   at Microsoft.EntityFrameworkCore.Query.Internal.ShaperCommandContext.NotifyReaderCreated(DbDataReader dataReader)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable`1.AsyncEnumerator.BufferlessMoveNext(DbContext _, Boolean buffer, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable`1.AsyncEnumerator.MoveNext(CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext(CancellationToken cancellationToken)
   at System.Linq.AsyncEnumerable.Aggregate_[TSource,TAccumulate,TResult](IAsyncEnumerable`1 source, TAccumulate seed, Func`3 accumulator, Func`2 resultSelector, CancellationToken cancellationToken)
   at Rez.Controllers.api.ParamController.GetParametri() in d:\data_serv\rez\Controllers\ParamController.cs:line 40
   at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
   at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
ralmsdeveloper commented 6 years ago

Waiting for an example to reproduce the error.

mrjohnr commented 6 years ago

hi.I've created a sample ASP Core + Angular 6 packeges included:

 <ItemGroup>
    <PackageReference Include="EntityFrameworkCore.FirebirdSql" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.3" />
    <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="2.1.1" />
  </ItemGroup>

I've used firebird example EMPLOYEE.FDB (c:\Program Files\Firebird\Firebird_2_5\examples\empbuild) a simple model+configuration

namespace TEST.Models
{    
    using Microsoft.EntityFrameworkCore;
    using Microsoft.Extensions.Options;

    public partial class Entities : DbContext
    {
        public virtual DbSet<EMPLOYEE> EMPLOYEE { get; set; }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
           optionsBuilder.UseFirebird("database = localhost:D:\\data_serv\\z.fdb;user=SYSDBA;password=masterkey");

        }
        protected override void OnModelCreating(ModelBuilder mB)
        {
            mB.Entity<EMPLOYEE>().HasKey(e => e.EMP_NO);
        }
    }
}

and

namespace TEST.Models
{
    public partial class EMPLOYEE
    {
        public long EMP_NO { get; set; }
        public string FIRST_NAME { get; set; }
    }
}

in main controller

   [HttpGet("[action]")]
        public async Task<IActionResult> Res()
        {
            var res = await db.EMPLOYEE.Select(r=> new {NAME =r.FIRST_NAME }).ToListAsync();

            return Ok(res);
        }

all works with 2.1.1 after updating,not working entire project is here thanks

ralmsdeveloper commented 6 years ago

I did the tests using your example and I could not simulate your error. The .csproj information is:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
    <TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
    <IsPackable>false</IsPackable>
    <SpaRoot>ClientApp\</SpaRoot>
    <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>

    <!-- Set this to true if you enable server-side prerendering -->
    <BuildServerSideRenderer>false</BuildServerSideRenderer>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="EntityFrameworkCore.FirebirdSql" Version="2.1.2.2" />
    <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.3" />
    <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="2.1.1" />
  </ItemGroup>

  <ItemGroup>
    <!-- Don't publish the SPA source files, but do show them in the project files list -->
    <Content Remove="$(SpaRoot)**" />
    <None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
  </ItemGroup>

  <Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
    <!-- Ensure Node.js is installed -->
    <Exec Command="node --version" ContinueOnError="true">
      <Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
    </Exec>
    <Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
    <Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
  </Target>

  <Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
    <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build -- --prod" />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:ssr -- --prod" Condition=" '$(BuildServerSideRenderer)' == 'true' " />

    <!-- Include the newly-built files in the publish output -->
    <ItemGroup>
      <DistFiles Include="$(SpaRoot)dist\**; $(SpaRoot)dist-server\**" />
      <DistFiles Include="$(SpaRoot)node_modules\**" Condition="'$(BuildServerSideRenderer)' == 'true'" />
      <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
        <RelativePath>%(DistFiles.Identity)</RelativePath>
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
      </ResolvedFileToPublish>
    </ItemGroup>
  </Target>

</Project>

Follow the instructions and clear your cache and try again. https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-locals

mrjohnr commented 6 years ago

done.but the same error,tested on 2 computers thanks

gpanayotov commented 5 years ago

I have the same problem. I don't have a test project, but I've tested in one of ours - build the assembly with debug information and attach to it (using current 2.1.2 branch). The exception is thrown because in FbQuerySqlGenerator(...) the _queryCompilationContex is null The exception is thrown when i try to login to a web app.

The interesting thing is: If i start the application, and try to login - the exception is thown. If I attach the Visual Studio to the process and try to login again - it breaks at line 59 in FbQuerySqlGenerator.cs because the _queryCompilationContext is null

But If i start the application without trying to login, attach the Visual Studio debugger to the process and Then try to login - it Works.

In my case everything depends when the debugger is attached.

JeanRessouche commented 5 years ago

Hi, was able to reproduce it with the latest version, does not appear within the 2.1.1.

CsProj

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="EntityFrameworkCore.FirebirdSql" Version="2.1.2.2" />
  </ItemGroup>
</Project>

DbContext

using Microsoft.EntityFrameworkCore;

namespace TestFirebirdEFCore.Entities
{
    public class TestsContext : DbContext
    {
        private string _connectionString;

        public TestsContext(string connectionString)
        {
            _connectionString = connectionString;
        }

        public virtual DbSet<TestEntity> TestEntities { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseFirebird(_connectionString);
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<TestEntity>(entity =>
            {
                entity.ToTable("TEST");

                entity.HasKey(e => e.Id);
            });
        }
    }
}

Test Entity

using System.ComponentModel.DataAnnotations.Schema;

namespace TestFirebirdEFCore.Entities
{
    [Table("TEST")]
    public class TestEntity
    {
        public int Id { get; set; }
    }
}

Consumer

using System;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using TestFirebirdEFCore.Entities;

namespace TestFirebirdEFCore
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Please paste now the connection string");

            var connectionString = Console.ReadLine();

            using (var db = new TestsContext(connectionString))
            {
                Console.WriteLine("\tTests Count => " + db.TestEntities.Count()); // Object reference not set..
            }

            Console.ReadLine();
        }
    }
}
ralmsdeveloper commented 5 years ago

@souchprod, thanks for testing, I'll work on it today!

mrjohnr commented 5 years ago

Hi,is that fixed? I see no new update,still 2.1.2.2 available.thanks

mrjohnr commented 5 years ago

it is more than 4 months without a fix ... is that project dead?

ralmsdeveloper commented 5 years ago

@mrjohnr I want to apologize, I was involved in other projects of the company, I will start working on it .. as soon as possible ..

mrjohnr commented 5 years ago

another month with no fix :(

jjniemela commented 5 years ago

another month with no fix :(

I also waited for a while... Then switched to: https://www.nuget.org/packages/FirebirdSql.EntityFrameworkCore.Firebird/

mrjohnr commented 5 years ago

Hi,at this moment https://www.nuget.org/packages/FirebirdSql.EntityFrameworkCore.Firebird/ doesn't work with FB 2.5

jjniemela commented 5 years ago

It should at least to some point... I'm using it with FB 2.5.8 right now.

mrjohnr commented 5 years ago

I'm using 2.5.8 too but not working with subselects

ralmsdeveloper commented 5 years ago

I have to apologize for the absence here, I'm involved with the company's projects, it took a lot of my time, I believed that someone in the community could help with this, but nobody built it, so what I have left and sacrifice in the next few days to update this repository in respect to all of you.