469,964 Members | 1,670 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,964 developers. It's quick & easy.

Could not load file or assembly

2
Hi,

I have developed an application in C#. Now I'm working on a tool which is again written in c# which will give me all the assemblies referenced by my application. In the code i need to get each assembly recursively and load it. When I run my tool some of the assemblies are loaded successfully but it end up giving following exception:


Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Windows.Forms' o
r one of its dependencies. The system cannot find the file specified.
File name: 'System.Windows.Forms'
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, ____
embly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Asse
mbly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyNa me assemblyRef, Evidence assemblySecurity, StackCrawlM
ark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark
& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at ReflectionDemoCSharp.ReferencedAssemblies.Main(Str ing[] args) in C:\Documents and Settings\lasi\My Docum
ents\Visual Studio 2008\Projects\ConsoleApplication1\ConsoleApplicati on1\Program.cs:line 20

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DW
ORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Can anyone help me out with this. Im totally stuck here.

Thanks in advance for all the inputs
Nov 10 '08 #1
4 4572
PRR
750 Expert 512MB
could you post some sample code?
Nov 10 '08 #2
lasida
2
sAssemblyName = "C:/Program Files/Myapplication/Myapplication.exe";

// load the given assembly...
Assembly assem = Assembly.LoadFrom(sAssemblyName);
AssemblyName[] a = assem.GetReferencedAssemblies();
foreach (AssemblyName assm in a)
{
Assembly ms = Assembly.LoadFrom(assm.Name);
Console.WriteLine("name: " + ms.FullName);
}

This is the simple code i have written. Can you tell me what is going wrong?
Nov 11 '08 #3
PRR
750 Expert 512MB
i guess you cant do this "Assembly ms = Assembly.LoadFrom(assm.Name);".. as you dont have the all *.dll in your bin dir.. of your application ...
Nov 11 '08 #4
PRR
750 Expert 512MB
if you have *.dll in your bin of your application( which your application refers... not the .net Dll) and you want to put them into appdomain ...then i guess you could check the following code ....
Expand|Select|Wrap|Line Numbers
  1.  
  2. AppDomain myapp = AppDomain.CreateDomain("Test");//AppDomain.CreateDomain("Test", null, meset);
  3.             //Assembly a1 = Assembly.Load("ClassLibrary1.dll");
  4.  
  5.                 myapp.Load("ClassLibrary1");                 
  6.  
  7.             Assembly[] aa = myapp. GetAssemblies();
  8.  
  9.             foreach (Assembly a in aa)
  10.             {
  11.                 Console.WriteLine(a.FullName);
  12.  
  13.                 Type[] tt=a.GetTypes();
  14.                 foreach (Type t in tt)
  15.                 {
  16.                     if (t.FullName.ToString() == "System.Object")
  17.                     {
  18.                         object o = Activator.CreateInstance(t);
  19.  
  20.                         if (o != null)
  21.                         {
  22.                             MethodInfo m = o.GetType().GetMethod("ToString");
  23.  
  24.                             Console.WriteLine(m.Invoke(o, null));
  25.                         }
  26.                     }
  27.  
  28.                     if (t.FullName.ToString() == "ClassLibrary1.Class1")// namespace+classname
  29.                     {
  30.                         object o = Activator.CreateInstance(t);
  31.  
  32.                         if (o != null)
  33.                         {
  34.                             MethodInfo m = o.GetType().GetMethod("my");// funtion: messagebox.show("Hi")
  35.  
  36.                             m.Invoke(o, null);
  37.                         }
  38.                     }
  39.                 }
  40.             }
  41.  
  42.  
Nov 11 '08 #5

Post your reply

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

Similar topics

2 posts views Thread by antonyliu2002 | last post: by
1 post views Thread by Steve Wofford | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.