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
 Below is my application scree shot
Below is my application scree shot
 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.
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.
User contributions licensed under CC BY-SA 3.0