Jump to content
  • Advertisement
Sign in to follow this  
cody

[.net] Assembly reference problems

This topic is 4507 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im trying to use assemblies for my maps in a game. but the problem is that those map-assemblies must reference the game library. now when my game loads the map, an exception is raised, that says that it cant find the referenced game library. it seams it searches for the assembly file, which is not in the same directory as the map-dll. i think that is stupid, as the game-library is already loaded anyway. i there a way to solve this problem, for example by modifiying the system how references are resolved?

Share this post


Link to post
Share on other sites
Advertisement
You can specify the location(s) to search for referenced assemblies. In your app.Config add the following:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" >
<probing privatePath="PathHere" />
</assemblyBinding>
</runtime>
</configuration>
MSDN link.

That will certainly work but I would be worried about two things. 1. The inability under .NET to programatically unload an assembly; 2. The duplication of assemblies in memory.

What you're probably looking to do involves the creation of a separate AppDomain and the loading and unloading of that AppDomain based on your application requirements. Basically you'd want to create an AppDomain upon first execution of your application, load your primary assembly into the deafult domain, and then load the required map assemblies into new AppDomains. Depending upon the architecture of your game you may want to create a new AppDomain for each map in order to ensure you can unload resources as necessary, however, crossing the AppDomain boundaries can cause a fairly significant performance hit. As well, calling Unload on the AppDomain will only remove the assemblies from memory if no other references exist to them.

You might check out the AppDomain FAQ for more mind numbing details.

Disclaimer: I've not yet had to deal with AppDomains outside the context of ASP.NET and COM interop, so I may be incorrect in my suggestions. I don't think I am, but.. take it with a grain of salt.

Share this post


Link to post
Share on other sites
yeah thanks, your link helped me pretty much.

this is how i do it now:
i use the AppDomain.AssemblyResolve event to return the library assembly when needed. so there should be no duplication in memory or something like that.

problem is of course, that i cant unload it right now, but i dont really need to. the maps just consist of code to place objects in the scene and maybe some logic. no more than a few kilobytes.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!