Calling a method inside a 32-bit .NET dll from a 64-bit version of .NET using reflection

I have a 32-bit .NET class library that has a simple public class and a simple public method. I have a 64-bit .NET console application where I use reflection, I want to load a 32-bit assembly and use its method.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Host.TestLib;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var lib = Assembly.LoadFrom("Simple32bitAssembly.dll");
        }
    }
}

When I run this, I get the following exception:

System.BadImageFormatException was unhandled
Message=Could not load file or assembly 
'file:///E:\AjitTemp\c\32bit64Bit\ReflectionTest\test\bin\Debug\Simple32bitAssembly.dll' 
or one of its dependencies. An attempt was made to load a program with an incorrect format.

Googling suggests that I need to create a 64-bit shell for this 32-bit dll and load this shell using the overboot in my 64-bit console application? Is it so? Any sample code would be very helpful.

+3
source share
1 answer

32- 64- , 32- 64- ( ).

, 32- " "? "Simple32bitAssembly" 64 .

:

" -, 32- dll " ".

- 32- 32- . .NET, :

    WCF
    Remoting
    ASP.NET Web Service

, ( WCF Remoting) .

- 64 ( ).

.

+4

Source: https://habr.com/ru/post/1768051/


All Articles