Calling a .Net Framework 4.6 assembly from a .Net Core 2.2 API

-1

We are trying to replace our current REST API ( built using .net framework ) with .Net Core Rest API. But instead of converting/writing all the Business logic in .net core\standard. We're thinking to use the existing DLLs that were built using.net framework 4.6.

To implement this:

  1. I have created a blank .net core API project
  2. Added reference to our existing Business DLL.
  3. Added code to call a business method.
        [HttpGet]
        public IActionResult Get()
        {
            // connectionString is intialized in the constructor 
            var allData = new MyBusinessLayer(connectionString).ListAllData();

            return Ok();
        }

"ListAllData" method reads the data from the database, applies some business rules and returns the data.

Above code compiles without any error but when I run the the service, it throws this error:

FileNotFoundException: Could not load file or assembly System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;. The system cannot find the file specified.

As my Business class is using System.Data.Entity assembly. I have tried adding the DLL reference to .net core project but then it threw a different error

BadImageFormatException: Could not load file or assembly System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)

How can I resolve this issue Or what I am trying to do here is not currently possible ?

c#
rest
asp.net-core
.net-core
.net-framework-version
asked on Stack Overflow Jul 31, 2019 by Imran Khan

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0