Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] DLL loading problem

Started by FxMazter Jan 11, 2005 at 5:07 PM 1 replies 650+ views
Original Post
FxMazter
FxMazter
Hey! I got problems while loading a DLL file with c#. This is how the plugins are related: //Loader.exe //Loads an IEngine and an IApplication from DLL's //Engine.dll //Contains the following class:

public class CurrentEngine 
{
    public static IEngine Instance
    {
        get
        {
            m_instance = new CEngine();
        }
    }
}

public class CEngine : IEngine {
}

public interface IEngine {
}
So, I try to load the "Engine.dll" which goes just fine. Then I try to get the Property "Instance" from the "CurrentEngine" type. Works fine. Then I try to get the "get" method of the property, which goes just fine. Then I try to Invoke the get method, which also seems to be OK since no exception is thrown. And the returned object is not null. But then I try to do something like this in Loader.exe: //Engine.dll - CurrentEngine.Instance is stored into "loadedEngineObj" IEngine engine = (loadedEngineObj as IEngine); This gives me a null value. I have made sure the object created by CurrentEngine.Instance is derived from IEngine. I have also made sure to use the same IEngine.cs file in both the Engine.dll and the Loader.exe Seems like the types differ across the Loader.exe and Engine.dll. Does anyone know how to solve this? Thx!
DaWanderer
DaWanderer
I would suggest moving IEngine into an outside assembly and referencing it in both the host and the plugin assemblies. If that's not what you want to do, I'd try moving the CurrentEngine.Instance.get{} into a non-static method and see if that works. Use Activator.CreateInstance to create an instance of CurrentEngine and see if you can get an IEngine object that way.
FxMazter
FxMazter
You mean like putting all interfaces that are shared across modules into
a dll like Shared.dll and then add a reference to it in every project?

That worked :)
It will prolly even be better to have all the shared interfaces in one
place, so there is no need to copy the new interfaces between the projects.

[Edited by - FxMazter on January 12, 2005 5:09:18 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.