Could not load file or assembly

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lasida
    New Member
    • Nov 2008
    • 2

    #1

    Could not load file or assembly

    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.FileN otFoundExceptio n: 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.Reflecti on.Assembly._nL oad(AssemblyNam e fileName, String codeBase, Evidence assemblySecurit y, ____
    embly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotF ound, Boolean forIntrospectio n)
    at System.Reflecti on.Assembly.nLo ad(AssemblyName fileName, String codeBase, Evidence assemblySecurit y, Asse
    mbly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotF ound, Boolean forIntrospectio n)
    at System.Reflecti on.Assembly.Int ernalLoad(Assem blyName assemblyRef, Evidence assemblySecurit y, StackCrawlM
    ark& stackMark, Boolean forIntrospectio n)
    at System.Reflecti on.Assembly.Int ernalLoad(Strin g assemblyString, Evidence assemblySecurit y, StackCrawlMark
    & stackMark, Boolean forIntrospectio n)
    at System.Reflecti on.Assembly.Loa d(String assemblyString)
    at ReflectionDemoC Sharp.Reference dAssemblies.Mai n(String[] args) in C:\Documents and Settings\lasi\M y Docum
    ents\Visual Studio 2008\Projects\C onsoleApplicati on1\ConsoleAppl ication1\Progra m.cs:line 20

    WRN: Assembly binding logging is turned OFF.
    To enable assembly bind failure logging, set the registry value [HKLM\Software\M icrosoft\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\M icrosoft\Fusion !EnableLog].

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

    Thanks in advance for all the inputs
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    could you post some sample code?

    Comment

    • lasida
      New Member
      • Nov 2008
      • 2

      #3
      sAssemblyName = "C:/Program Files/Myapplication/Myapplication.e xe";

      // load the given assembly...
      Assembly assem = Assembly.LoadFr om(sAssemblyNam e);
      AssemblyName[] a = assem.GetRefere ncedAssemblies( );
      foreach (AssemblyName assm in a)
      {
      Assembly ms = Assembly.LoadFr om(assm.Name);
      Console.WriteLi ne("name: " + ms.FullName);
      }

      This is the simple code i have written. Can you tell me what is going wrong?

      Comment

      • PRR
        Recognized Expert Contributor
        • Dec 2007
        • 750

        #4
        i guess you cant do this "Assembly ms = Assembly.LoadFr om(assm.Name);" .. as you dont have the all *.dll in your bin dir.. of your application ...

        Comment

        • PRR
          Recognized Expert Contributor
          • Dec 2007
          • 750

          #5
          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 ....
          Code:
          AppDomain myapp = AppDomain.CreateDomain("Test");//AppDomain.CreateDomain("Test", null, meset);
                      //Assembly a1 = Assembly.Load("ClassLibrary1.dll");
                     
                          myapp.Load("ClassLibrary1");                 
          
                      Assembly[] aa = myapp. GetAssemblies();
          
                      foreach (Assembly a in aa)
                      {
                          Console.WriteLine(a.FullName);
                          
                          Type[] tt=a.GetTypes();
                          foreach (Type t in tt)
                          {
                              if (t.FullName.ToString() == "System.Object")
                              {
                                  object o = Activator.CreateInstance(t);
          
                                  if (o != null)
                                  {
                                      MethodInfo m = o.GetType().GetMethod("ToString");
          
                                      Console.WriteLine(m.Invoke(o, null));
                                  }
                              }
          
                              if (t.FullName.ToString() == "ClassLibrary1.Class1")// namespace+classname
                              {
                                  object o = Activator.CreateInstance(t);
          
                                  if (o != null)
                                  {
                                      MethodInfo m = o.GetType().GetMethod("my");// funtion: messagebox.show("Hi")
          
                                      m.Invoke(o, null);
                                  }
                              }
                          }
                      }

          Comment

          Working...