Home

Using entity framework core assembly and linqpad

Recently I have created a post about EF Core and postgresql. I had following error message:
Derived types must either match the security accessibility of the base type or be less accessible
Today I tried use EF Core assembly for SQL Server and got the same error message.

Anyone faced with the same issue?


Comments

  • Have you set any security attributes on the assembly that contains your data context? And if so, are these attributes necessary for what you're doing?
  • I have the same issue. I can successfully create the connection, and see the tables in the explorer pane. But any query gives me the error:

    source: Microsoft.EntityFrameworkCore

    message: Inheritance security rules violated by type: 'Remotion.Linq.Parsing.RelinqExpressionVisitor'. Derived types must either match the security accessibility of the base type or be less accessible.

    TypeName: Remotion.Linq.Parsing.RelinqExpressionVisitor
  • Found a clue here - https://www.redgreencode.com/time-tortoise-resolving-dependencies-part-2/

    tl;dr mismatch of assemblies being loaded

    Steps to resolve with a ef core / .net standard 2.0 project:

    1. In Visual Studio, build your assembly, drop to PowerShell and publish the assembly using: dotnet publish -c debug -r win10-x64

    1.a. Ensure your assembly references all 2.1.1 versions of EF Core or else you will not be able to connect to it via linqpad.

    2. In linqpad when you add your connection. Select EF Core 2.1.1 driver then before browsing to your published dll add the NuGet package Microsoft.AspNetCore.Identity.EntityFrameworkCore. Note, as of this post one could only do this if using beta v5.33.11 of linqpad.

    3. Browse to your published assembly, select it, and the full time name.

    3.a. Side note I had to add a constructor to my ApplicationDbContext so linqpad could call it:

    public ApplicationDbContext(string connectionString) : this(new DbContextOptionsBuilder()
    .UseSqlServer(connectionString).Options)
    { }

    4. Back to linqpad, add in your connection string

    5. Should connect, and one should be able to query the db
Sign In or Register to comment.