Reputation: 1475
I have a C# dll
, with some methods, which I am trying to access in my native project with /CLR
support.
I reference this DLL
using a #using
directive, and the DLL
is recognized and the project compiles.
However, during runtime, I get a FileNotFoundException
, which is pretty weird since the DLL is present in the source directory of the project.
TheDLL
is compiled inVS 2015
with .NET Version 4.5.2
. Since I have CLR
support on my C++ mixed, I have edited the project file to make TargetFrameworkVersion
as 4.5.2, but still the runtime
does not work.
Kindly advise on what could be the issue?
EIDT - ADDED SOME CODE
C#
namespace TestManagedLibrary
{
public class Class1
{
public int i;
public Class1()
{
i = 5;
}
public int returnValue()
{
return i;
}
}
}
C++/CLI
#using <TestManagedLibrary.dll>
using namespace System;
using namespace System::Runtime::InteropServices; // Marshal
using namespace TestManagedLibrary;
ref class ManagedFoo
{
public:
ManagedFoo()
{
Console::WriteLine(_T("Constructing ManagedFoo"));
Class1 ^testObject = gcnew Class1();
int a = testObject->returnValue();
}
};
Upvotes: 1
Views: 1599
Reputation: 1475
The compiled DLL
should have been in the same location as the executable for the CLR
to search for it. In my case, the .NET
compiled DLL
was in the solution folder and not searchable.
Upvotes: 0
Reputation: 3709
First of all you need to ensure that the TestManagedLibrary.dll
file is located in a place where Fusion could find it. Your first try should be the location of the executable you are running.
One way to handle this is via the reference properties. If the reference to your TestManagedLibrary.dll
is set with the copy local
flag than during the build the referenced library is going to be copied from the referenced location to the output directory.
You can enable the internal fusion logging to find out the details:
Developer Command Prompt
with administrative privileges.fuslogvw
Assembly Binding Log Viewer
hit settings and set either Log bind failures to disk
or Log all binds to disk
.Refresh
in the Assembly Binding Log Viewer
, pick your executable and hit View Log
Upvotes: 3