none
Could not load file or assembly RRS feed

  • Question

  • Hi,

     I have developed an application in C#. Now Im 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(AssemblyName 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(String[] args) in C:\Documents and Settings\lasi\My Docum
    ents\Visual Studio 2008\Projects\ConsoleApplication1\ConsoleApplication1\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
    • Edited by Lasida Monday, November 10, 2008 5:28 AM
    • Moved by kenwat Monday, November 10, 2008 11:48 PM not VS2010 CTP related (Moved from Building and Deploying Applications in the Visual Studio 2010 and .NET Framework 4.0 CTP to .NET Base Class Library)
    Monday, November 10, 2008 5:05 AM

Answers

  • You should always be able to load System.Windows.Forms.   There's something wrong with your code, impossible to guess what.  This code worked:

    using System.Reflection;
    ...
        private void button1_Click(object sender, EventArgs e) {
          AssemblyName[] names = Assembly.GetEntryAssembly().GetReferencedAssemblies();
          foreach (AssemblyName name in names) {
            Assembly asm = Assembly.Load(name);
            Console.WriteLine("Loaded {0}, {1} types", name.Name, asm.GetTypes().Length);
          }
        }


    Output:
    Loaded System, 1956 types
    Loaded System.Windows.Forms, 2256 types
    Loaded mscorlib, 2339 types
    Loaded System.Drawing, 298 types


    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Friday, November 14, 2008 10:11 AM
    Tuesday, November 11, 2008 3:48 AM
    Moderator

All replies

  •  Hi - thanks for posting to the MSDN Forums. This forum, however, is for gathering feedback on the Walkthrough scenarios that shipped with the Visual Studio 2010 CTP. If you would like more information about the CTP, please visit http://go.microsoft.com/fwlink/?LinkId=129231.  

    I'm moving your post to the .NET Base Class Library forum.

    Do you have a code fragment illustrating the issue you have?

    thanks,
    Ken Watson
    Visual Studio Platform
    Monday, November 10, 2008 11:48 PM
  • Did you search the GAC?
    MSMVP VC++
    Tuesday, November 11, 2008 1:58 AM
  • You should always be able to load System.Windows.Forms.   There's something wrong with your code, impossible to guess what.  This code worked:

    using System.Reflection;
    ...
        private void button1_Click(object sender, EventArgs e) {
          AssemblyName[] names = Assembly.GetEntryAssembly().GetReferencedAssemblies();
          foreach (AssemblyName name in names) {
            Assembly asm = Assembly.Load(name);
            Console.WriteLine("Loaded {0}, {1} types", name.Name, asm.GetTypes().Length);
          }
        }


    Output:
    Loaded System, 1956 types
    Loaded System.Windows.Forms, 2256 types
    Loaded mscorlib, 2339 types
    Loaded System.Drawing, 298 types


    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Friday, November 14, 2008 10:11 AM
    Tuesday, November 11, 2008 3:48 AM
    Moderator