OrderBy throws Could not load file or assembly System.Data.Entity

asp.net-core c# entity-framework-core


Trying to get DataTables to work in a ASP.NET Core 2 project. When the following line of code executes, the application throws exception on OrderBy

var data = (from app in _context.Applications select app);

if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir)))
    data = data.OrderBy(sortColumn + " " + sortColumnDir);

The exception is:

{System.TypeInitializationException: The type initializer for 'System.Linq.Dynamic.ExpressionParser' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Data.Entity, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
   at System.Linq.Dynamic.ExpressionParser..cctor()
   --- End of inner exception stack trace ---
   at System.Linq.Dynamic.ExpressionParser..ctor(ParameterExpression[] parameters, String expression, Object[] values)
   at System.Linq.Dynamic.DynamicQueryable.OrderBy(IQueryable source, String ordering, Object[] values)
   at System.Linq.Dynamic.DynamicQueryable.OrderBy[T](IQueryable`1 source, String ordering, Object[] values)
   at assetreportv2.Controllers.HomeController.LoadData() in C:\Users\chentiangemalc\Documents\Visual Studio 2017\Projects\DataTableTest\DataTableTest\Controllers\HomeController.cs:line 64}

The csproj file is currently configured like so:

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


    <PackageReference Include="bootstrap" Version="4.0.0" />
    <PackageReference Include="Entityframework" Version="6.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
    <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.1" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.2" />
    <PackageReference Include="System.Linq.Dynamic" Version="1.0.7" />
    <PackageReference Include="WindowsAzure.Storage" Version="8.3.0" />

    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.1" />

    <WCFMetadata Include="Connected Services" />


Is there a way to use this OrderBy in ASP.NET Core, or suggest an alternative option?

3/13/2018 12:14:17 AM

Accepted Answer

Sorry I'm a bit late to your question, but I had exactly this problem and I've just fixed it. I'm also using Core 2.0 and was using System.Linq.Dynamic and got that error when I used an OrderBy extension, but I uninstalled it and installed System.Linq.Dynamic.Core instead, and now it's working perfectly

4/25/2018 9:11:59 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow