What do you call a managed (C #) function from C ++?

I have a C # dll ( my_cs_dll.dll) project that defines a static class with a static member function.

namespace Foo
{
    public static class Bar
    {
        public static double GetNumber() { return 1.0; }
    }
}

I also have a C ++ dll project that uses / clr.

#using <my_cs_dll.dll>

double get_number_from_cs() { return Foo::Bar::GetNumber(); }

I added a link to 'my_cs_dll.dll'in the "Links to General Properties" section of the C ++ project (copy local / copies).

And I also added a path to 'my_cs_dll.dll'in the C ++ project of the project "Configuration Properties" C / C ++ "Allow # using links".

Everything builds without errors, but at runtime I continue to get the "System.IO.FileNotFound" exception from the system, stating that I cannot find the assembly my_cs_dll.dll.

Both Dlls are definitely present in the same directory I am running from.

, , , manged/unmanaged interop, , ...

VS2008 .NET 3.5

+5
1

, # . # dll , ( ) ? , , , ​​ GAC, ( ), , DLL, . .NET.

, . ++, Clr, :

using namespace System;
using namespace System.Reflection;
void Resolve()
{
    AppDomain::CurrentDomain->AssemblyResolve +=
        gcnew ResolveEventHandler(OnAssemblyResolve);
}
Assembly ^OnAssemblyResolve(Object ^obj, ResolveEventArgs ^args)
{
#ifdef _DEBUG
    String ^path = gcnew String(_T("<path to your debug directory>"));
#else
    String ^path = gcnew String(_T("<path to your release directory>"));
#endif
    array<String^>^ assemblies =
        System::IO::Directory::GetFiles(path, _T("*.dll"));
    for (long ii = 0; ii < assemblies->Length; ii++) {
        AssemblyName ^name = AssemblyName::GetAssemblyName(assemblies[ii]);
        if (AssemblyName::ReferenceMatchesDefinition(gcnew AssemblyName(args->Name), name)) {
            return Assembly::Load(name);
        }
    }
    return nullptr;
}

, , . clr. , Resolve() , , get_number_from_cs().

COM - , . . - , . , , .

+4

All Articles