473,692 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unloadable Plugin Architecture in .NET

2 New Member
This is my first question here, so apologies if I have made a mistake.

I am developing a collection of small games using WPF with C# but have been having real difficulty in being able to load and unload each game into my main viewer application.

The structure of my program is I have a main view application GameViewer.EXE which basically consists of a Frame object to view pages.
Each game is a custom class GamePage.CS, shown below:

Expand|Select|Wrap|Line Numbers
  1. GameLibrary.DLL
  2.  
  3. namespace GameLibrary
  4. {
  5.  public class GamePage : Page
  6.     {
  7.         public Guid GameID;
  8.         public string GameName;
  9.         public string Description;
  10.         public virtual void PauseGame(){}
  11.  
  12.        public event GameEndArgsEventHandler GameEnd;
  13.  
  14.         protected void OnGameEnd(GameEndArgs e)
  15.         {
  16.             if (GameEnd != null)
  17.                 GameEnd(this, e);
  18.         }
  19.    }
  20.  
  21.  public class GameEndArgs : EventArgs
  22.     {
  23.         public double Score;
  24.         public bool Finished;
  25.         public int Level = 1;
  26.     }
  27. }

I also have a ControlLibrary. DLL , which contains a collection of stylized controls, i.e. customs, sliders, etc., which is used in all games and the main interface GameViewer.EXE.

The structure of the application is:
Expand|Select|Wrap|Line Numbers
  1. Home\
  2.          GameViewer.EXE
  3.          GameLibrary.DLL
  4.          ControlLibrary.DLL
  5.  
  6.         Games\
  7.                   Game1\
  8.                              game1.DLL
  9.                              game1Dependency1.DLL
  10.                              game1Dependency2.DLL
  11.                   Game2\
  12.                             game2.DLL
  13.                   Game3\
  14.                             game3.DLL
  15.                             image\
  16.                      ...
  17.                  Game n

My trouble is being able to load then successfully unload each game DLL into my main viewer. I have been reading dozen of threads, but I cannot seem to get anything to work. I am trying to create a new AppDomain load the assembly in there and create the GamePage object.
- I can then unload the appdomain when the game is finished, but on repeated opening and closing the game I see the memory usuage shoot up, so something is going wrong.
- I have also tried creating a separate loader, using the MarshalByRefObj ect, but on returning a GamePage I am told that GamePage is not Serializable.

This is my current attempt:

In the GameLibrary.DLL I have:
Expand|Select|Wrap|Line Numbers
  1. namespace GameLibrary
  2. {
  3.      [Serializable]
  4.       public class Factory
  5.       {
  6.           public GamePage CreateGamePageObject(string path, string typename)
  7.           {
  8.               return Activator.CreateInstanceFrom(path, typename).Unwrap() as GamePage;
  9.            }
  10.       }
  11. }
Then in the my app I have:
Expand|Select|Wrap|Line Numbers
  1.         private AppDomain domain  =null;
  2.  
  3.          void LoadGame(string GameFile)
  4.           {
  5.                 domain = AppDomain.CreateDomain("Remote Load");
  6.  
  7.                 ObjectHandle oh = domain.CreateInstance("GameLibrary", "GameLibrary.Factory");
  8.                 Object obj = oh.Unwrap();
  9.                 GameLibrary.Factory f = obj as GameLibrary.Factory;
  10.                 GameLibrary.GamePage addIn=null;
  11.  
  12.                 FileInfo fi = new FileInfo(GameFile);
  13.                addIn =f.CreateGamePageObject(fi.FullName, fi.Name.Substring(0, fi.Name.Length - 4) + ".Page1");
  14.  
  15.                 MainFrame.Content = addIn;
  16.           }
  17.          void UnloadGame()
  18.          {
  19.                MainFrame.Content = null;
  20.                AppDomain.Unload(domain);
  21.          }
  22.  
The trouble with this is the memory leak.

I would greatly appreciate any help and suggestions.
Nov 26 '09 #1
1 2177
A Popat
2 New Member
I have since realised that the reason for the increasing memory usage was due to the use of a Frame, which would store a history of past pages. By setting Frame.JournalOw nership to UsesParentJourn al, this problem is avoided.
Nov 27 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1952
by: Jer | last post by:
Hi all, I am trying to get plugins working in my application. I am using the approach of writing an interface and then implementing that interface in each plugin. I would like to be able to just have a plugin directory, and on program launch scan that directory, load each dll in it and decide whether it's a valid plugin dll. So far I've gotten the directory scan fine, loaded each assembly in turn,
2
2784
by: Chua Wen Ching | last post by:
Hi there, I had some doubts on creatings plugins. As most example on the internet shows how to write plugins onto a plugin host which is normally a windows form program. 1) Can i replace plugin host as class libraries instead of windows forms program?
5
3034
by: Tamir Khason | last post by:
Friends, maybe someone knows good references for .NET plugin based program architecture. E.g I want to be able to "put" class library(dll) in some place (where I do not the name of the class, but only structure ) and use it "plug-and-play" in main procedure without recompilation -- Tamir Khason You want dot.NET? Just ask: "Please, www.dotnet.us "
2
3063
by: Matt | last post by:
I'm hoping someone can steer me in the right direction to try to do the following: I am developing an application where we receive files from customers. Right now we receive a variety of formats. I was looking at writing some type of base application that would allow me to add-in either new assemblies or plugins, don't know how or which way, for different scenarios. We may just recieve a text file so an assembly would handle...
3
2345
by: CSharpNewBie | last post by:
Hi I am looking to create a Plugin Architecture. I looked at this extend or enhance the User Interface (UI) article http://www.codeproject.com/csharp/extensibleui.asp and It looks good and I would like to know if any better way to do. My requirements are I have several screens and each screen will have grid with data and thinking of putting each screen in a PlugIn(assembly) and loading it in a Container..
1
1194
by: Craig Buchanan | last post by:
I am building an application to help researcher record the outcomes of their studies. These outcomes are document across a number of paper forms. The information documented on these forms varies widely. My current approach is to use a Document class with a collection of Question classes. I create an instance of the Document, add a number of questions to it, serialize the Document object to XML, then treat this XML file as a...
0
944
by: Craig Buchanan | last post by:
I am building an application to help researcher record the outcomes of their studies. These outcomes are document across a number of paper forms. The information documented on these forms varies widely. My current approach is to use a Document class with a collection of Question classes. I create an instance of the Document, add a number of questions to it, serialize the Document object to XML, then treat this XML file as a...
0
1437
by: Dan Dorey | last post by:
I'm in the midst of creating a plugin framework with the goal of making it as easy as possible for myself and other developers to both create new plugins and work with existing ones. Each plugin has a seperate sub-dir for each plugin with all external dependencies located in this directory. When I load these plugins dynamically everything appears to work properly. So now let's pretend that I'm developing down the road and I'm creating...
4
2588
by: anglozaxxon | last post by:
I'm making a program that consists of a main engine + plugins. Both are in Python. My question is, how do I go about importing arbitrary code and have it be able to use the engine's functions, classes, etc? First, here's how it's laid out on the filesystem: -mainstarterscript.py -<engine> -__init__.py - -<plugin>
1
1944
by: Olie | last post by:
I was quite surprised to find virtually nothing about this but I may have been searching for the wrong thing. I want to know the best way to provide a programming interface to a plugin. I already have a plugin architecture that allows the application to call code in a plugin but I want the plugin to also be able to call code in the application. I can think of many ways to do this but I am not sure the best way:
0
8603
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8538
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8960
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8797
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6459
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4323
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4557
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
1957
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.