DLL import not working in web api project(.net core)

0

Hi I tried to import c library into c# console application as below.

 class Program
    {
        [DllImport("C:/Users/INNIGOD1/source/repos/Dll1/Debug/Dll1.dll", CallingConvention = CallingConvention.Cdecl,EntryPoint = "sum")]
        internal unsafe static extern int Sum(int x, int y);
        public static void Main(string[] args)
        {
            int a = 1;
            int b = 2;
           int c= Sum(a, b);
        }
    }.

Later I created .net core webapi project and tried to import same dll as below.

 [DllImport("C:/Users/INNIGOD1/source/repos/Dll1/Debug/Dll1.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "sum")]
        internal unsafe static extern int Sum(int x, int y);
        // GET api/values
        [HttpGet]
        public IEnumerable<string> Get()
        {
            int a = 1;
            int b = 2;
            int c = Sum(a, b);
            return new string[] { "value1", "value2" };

        }

Below is my build screenshot from properties enter image description here Below is my application scree shot enter image description here when I do this I got error System.BadImageFormatException: 'An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)'. May I know what could be the issue? Any help would be greatly appreciated. Thank you.

c#
c
dll
asked on Stack Overflow Dec 8, 2017 by Niranjan Godbole • edited Dec 8, 2017 by Niranjan Godbole

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0