Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Is there any particular trick to getting DllImport to work?
NeilMacMullen
#1 Posted : Sunday, June 2, 2019 3:02:06 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/15/2016(UTC)
Posts: 13
Location: United Kingdom

Thanks: 7 times
Was thanked: 4 time(s) in 4 post(s)
In my continuing quest to "test all the things" I have set up a managed C++ class library/dll which is being called from a C# Unit-test project. The test code looks a bit like this....


Code:

    public static class    Caller
    {
        [DllImport("lib.dll")]
        static extern void codeToTest();
    } 

    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            Caller.codeToTest();
            ...
        }
    }


There is a project dependency between the C++ library and the test project.

Ncrunch is quite happy to build both projects and recognises that the test needs to be re-run if I touch the C++ code. However, it throws an exception saying it can't find the DLL when it tries to run the test...

Quote:
System.DllNotFoundException: Unable to load DLL 'lib.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)



The DLL _is_ being copied to the unit-test bin/debug folder by the normal build process and if I debug the test using vs/Resharper, they correctly load the DLL.

Is there some special bit of configuration I need to apply to get NCrunch to copy the DLL to its test environment? I'm not sure what's confusing NCrunch here - maybe the fact that folder conventions are different for a C++ project? In this case the lib project outputs to lib\debug\lib.dll rather than lib\bin\debug\lib.dll ?

Thanks for any insight... :-)
NeilMacMullen
#2 Posted : Sunday, June 2, 2019 3:07:52 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/15/2016(UTC)
Posts: 13
Location: United Kingdom

Thanks: 7 times
Was thanked: 4 time(s) in 4 post(s)
Just answering my own question....

Setting "Pre-load all assembly references into test environment" to TRUE seems to have resolved this.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.021 seconds.