LinqPad 5 with EFCore - TypeLoadException: Inheritance security rules violated by type: 'Remotion.Li

Hi,

Posted a query on Stack Overflow here but didn't appear to get any traction.

Anyone have a solution to (or had a similar issues, so I can identify if its my setup or a broader issue) the following error when trying to query an EFCore DbContext from LinqPad against SQL Express..

TypeLoadException: 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.

I found a similar issue posted here but with no resolution either..

Anyone any ideas?

Thanks

Comments

  • Do you have the AllowPartiallyTrustedCallers attribute set on your DbContext assembly, or any other code-access security attributes?

    If so, try removing them.
  • Hi Joe,

    Thanks for coming back to me. Nothing special with the DB context apart from inherting from IdentityDbContext.

    Just to be sure, I cloned and ran the sample code as part of the EFCore official tutorial here: https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/intro?view=aspnetcore-2.2

    I have modified the sample slightly, firstly to move the data stuff to a netstandard2.0 lib as the 'EF Core Driver v2.2' doesn't appear to support netcoreapp.

    I also added the 'CopyLocalLockFileAssemblies' attribute to the Data.csproj to copy all assemblies to the output folder, so I can reference the Data.dll from /data/bin/debug/netstandard2.0

    Finally I added support to the DbContext for using a parameterless constructor

    You can find the minimal sample here:
    https://github.com/stevenknox/LinqPad-EfCore-Issue

    When I create the connection with the following settings:


    It finds and loads the tables:


    However trying to execute any sort of query blows up:


    Any thoughts?

    Thanks,
    Steven

  • @sknox I chased a similar bug with asp.net core where I had three different projects:
    • BusinessEntities -- my model
    • Data Transfer Objects -- what I sent to the front end
    • asp.net core application
    I kept pointing LINQPad to my Data Transfer Objects project, because I wanted to use AutoMapper in LINQPad to see the 'actual result'. I figured if I pointed LINQPad to the dll for my BusinessEntities project next to the Data Transfer Objects it would all 'work itself out'.

    I kept receiving the same error you are seeing in your setup. Solution was to point LINQPad to the BusinessEntities project and ensure the BusinessEntities.deps.json file was generated. Lastly I told LINQPad to Restore NuGet Dependencies from the Entity Framework DbContext Connection pop up.
  • Hi @benhysell , thanks for your feedback, very much appreciated.

    In my example project (https://github.com/stevenknox/LinqPad-EfCore-Issue) both model/domain objects and the dbcontext are encapsulated into one project, which i'm then pointing LinqPad too the compiled assembly for that project (no need to resolve any additional libs etc).

    I also just checked and the deps.json file is getting generated/copied to the output folder alongside the DLL i'm targeting. Also tried running the 'Restore NuGet Dependencies' however just getting the same error.

    Does the minimal repro project I added above work for you by any chance? If so it means its some version/config issue on my machine and not the project/code structure.

    Thanks,
    Steven
  • I've encountered the same issue in a very basic use case:
    • Scaffold a DB context using the 'dotnet ef dbcontext scaffold ...' command
    • Build the project as a netstandard2.0 library
    • Add DB context in the Linqpad EF core driver (v2.2)
    I also tried to use the same DB context by adding it as a reference in a fresh Linqpad query which gave the same error so it doesn't seem to be a problem specific to the EF core driver.

    The only workaround for me was to revert back to an older version of EFCore (2.0.0) which uses a different version of the Remotion.Relinq package.
  • I'll try targeting that version in my sample repo shortly to see if that works. If so could just be a case of waiting until the Remotion.Relinq supports the latest EFCore 2.2
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!