473,321 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

How to load dependent Assembly using <dependentAssembly>

I have three dlls ProjBL.dll , ProjDL.dll and ProjMC.dll.

ProjBL.dll is Business object dll

ProjDL.dll is Data Access layer method dll

ProjMC.dll is Master Class dll contains Properties


ProjDL.dll depends on ProjMC.dll and ProjBL.dll depends on ProjDL.dll

I have load ProjBL.dll in Memory using Assembly.Load() method from folder on D: drive with specified folder.

Currently it gives error that "One of dependent Assembly not found"
Mar 2 '09 #1
2 4270
Frinavale
9,735 Expert Mod 8TB
You need to load all 3 of the assemblies required by your application, not just your ProjBL.DLL.
Mar 2 '09 #2
I have used following method which doesnot work.
I loads individual assembly but if we combine result it doesn't work.
I think there requires linking between these assemblies and i doesn't know exact way.

================================================== ==
Expand|Select|Wrap|Line Numbers
  1. private Assembly ReadAssemblyFromMemory()
  2.     {       
  3.         DirectoryInfo dllDirectory = new DirectoryInfo(folderPath);
  4.         FileInfo[] dllFiles = dllDirectory.GetFiles("*.dll");
  5.         int dllCount = dllFiles.Length;
  6.         FileStream fs = null;        
  7.         if (dllCount > 0)
  8.         {
  9.             long streamLength = 0;
  10.             for (int fileCount = 0; fileCount < dllCount; fileCount++)
  11.             {
  12.                 fs = new FileStream(dllFiles[fileCount].FullName, FileMode.Open);
  13.                 streamLength += fs.Length;
  14.                 fs.Close();
  15.             }
  16.             byte[] memory = new byte[streamLength];
  17.             byte[] memory1 = null;
  18.             byte[] memory2 = null;
  19.             byte[] memory3 = null;
  20.  
  21.             fs = new FileStream(dllFiles[0].FullName, FileMode.Open);
  22.             BinaryReader br = new BinaryReader(fs);
  23.             memory1 = br.ReadBytes(Convert.ToInt32(fs.Length));  // Loads ProjMC.dll
  24.  
  25.             fs = new FileStream(dllFiles[1].FullName, FileMode.Open);
  26.             br = new BinaryReader(fs);
  27.             memory2 = br.ReadBytes(Convert.ToInt32(fs.Length));  // Loads ProjDA.dll
  28.  
  29.  
  30.             fs = new FileStream(dllFiles[2].FullName, FileMode.Open);
  31.             br = new BinaryReader(fs);
  32.             memory3 = br.ReadBytes(Convert.ToInt32(fs.Length));   // Loads ProjBL.dll
  33.  
  34.             fs.Close();
  35.             br.Close();
  36.  
  37.             memory1.CopyTo(memory, 0);
  38.             memory2.CopyTo(memory, memory1.Length);
  39.             memory3.CopyTo(memory, (memory1.Length + memory2.Length));
  40.  
  41.             assemblyUsed = Assembly.Load(memory);  
  42.  
  43.         }        
  44.         return assemblyUsed;
  45.   }
================================================== ==

To solve this problem I have done it in another way as below method


Expand|Select|Wrap|Line Numbers
  1. private Assembly ReadTotalAssemblyFromList()
  2.     {
  3.         FileInfo fileName = new FileInfo(AssemblyPath);
  4.         DirectoryInfo dllDirectory = new DirectoryInfo(AssemblyPath.Replace(fileName.Name,""));
  5.         FileInfo[] dllFiles = dllDirectory.GetFiles("*.dll");
  6.         int dllCount = dllFiles.Length;
  7.         FileStream fs = null;
  8.         byte[] memory = null;
  9.         Assembly CombinedAssembly = null;
  10.         if (dllCount > 0)
  11.         {
  12.             for (int fileCount = dllCount - 1; fileCount >= 0; fileCount--)
  13.             {
  14.                 if (dllFiles[fileCount].Name == fileName.Name)   // Loads ProjBL.dll at last after loading ProjMC.dll and ProjDL.dll
  15.                 {
  16.                     fs = new FileStream(dllFiles[fileCount].FullName, FileMode.Open);
  17.                     BinaryReader br = new BinaryReader(fs);
  18.                     memory = br.ReadBytes(Convert.ToInt32(fs.Length));
  19.                     assemblyUsed = Assembly.Load(memory);
  20.                     br.Close();
  21.                     fs.Close();
  22.                 }
  23.                 else    // Loads ProjMC.dll and ProjDL.dll
  24.                 {
  25.                     fs = new FileStream(dllFiles[fileCount].FullName, FileMode.Open);
  26.                     BinaryReader br = new BinaryReader(fs);
  27.                     memory = br.ReadBytes(Convert.ToInt32(fs.Length));
  28.                     assemblyUsed = Assembly.Load(memory);
  29.                     br.Close();
  30.                     fs.Close();
  31.                 }                         
  32.             }
  33.         }
  34.         return assemblyUsed;
  35.     }

=================================================

Please provide the way to combine these Assemblies . Above two way doesn't work
Mar 3 '09 #3

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

Similar topics

3
by: Peter Blum | last post by:
I have built an assembly (dll) from which I expect third parties to subclass. As a result, when my assembly has a version change, it will cause any third party assembly based on it to break unless...
0
by: Marcin Polewski | last post by:
I am trying to redirect a dependant assembly using the following in my machine.config file <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity...
0
by: Rokas Valantinas | last post by:
Hi, After deploying ASP.NET webservices to clients testing environment, some problems occured with assembly versioning. Exception log showed that CLR ignores <bindingRedirect> tag and it's...
8
by: Subra Mallampalli | last post by:
Hi, I am trying to use <runtime> section within the web.config file. However, the contents of the <runtime> section seem to be ignored. What am i missing here? Is <runtime> section not used by...
10
by: =?Utf-8?B?TUNN?= | last post by:
What does this do? <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35" />...
0
by: =?Utf-8?B?S2VuIExlbWlldXg=?= | last post by:
My Clickonce app fails when the install button on the publish.htm page is clicked. User is prompted with a "Cannot Start Application" dialog. Details provided from the dialog are: PLATFORM...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.