none
Assembly.LoadFrom and Activator.CreateInstance RRS feed

  • Question

  • I'm puzzled.

    I am testing some simple code.

    I load an assembly from it's pathname using Assembly.LoadFrom, it loads and I can see that it has in the debugger output window.

    Having done this, I call Activator.CreateInstance using the full name of the assembly (which I have noted from elsewhere) and a type in the assembly.

    But the latter fails with file not found.

    If I setup a resolve handler for my AppDomain it calls it.

    Why?

    I was under the impression that if the assembly was already loaded, then it would be aware of this and not fail or cause the resolve handler to run?

    The name of the assembly I use is the full name, with Version= and all that stuff, it is a local .DLL in some other test project.

    Even if I create a Type variable using Type.GetType(<asm qualified name>) I get probs and it returns null and is unable to create the type, yet the assembly IS loaded.

    I have tried LoadFile and LoadFrom too.

    What is the explanation here?

    Thx
    H
    • Edited by Captain Kernel Friday, August 1, 2008 4:16 PM fixed errors
    Friday, August 1, 2008 3:52 PM

Answers

All replies

  • You are dealing with the LoadFrom context.  There's some information about this in this MSDN library article.  Also check Suzanne Cook's blog.

    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Thursday, August 7, 2008 2:18 PM
    Friday, August 1, 2008 6:28 PM
    Moderator
  • Thanks Hans

    This is certainly noteworthy, especially as it refers to casting exceptions (some similar tests were getting odd typecast errors with remoting).

    I get the same problems with LoadFile though, not just LoadFrom, is LoadFile also likely to misbehave?

    Thx
    H
    Friday, August 1, 2008 7:06 PM