• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:

  • You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
  • You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
  • If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.

Previously on ".NET dynamically loading assembly"

Collapse

  • ASB
    replied
    Originally posted by Jaws View Post
    Using reflection you should be able to find the type in the assembly and use the type to invoke the method.

    So something like [NB code is not tested - and you are likely to need some null tests due to reflection almost always returning null and not throwing when types etc not found]

    Code:
    Assembly assembly = Assembly.LoadFile("... assembly path ..");
    Type methodHostType = assembly.GetType("... type name ...");
    MethodInfo method = methodHostType.GetMethod("... MethodName ...", BindingFlags.Public | BindingFlags.Static);
    
    object result = method.Invoke(null, ... params ...);
    You may also want to look at loading this assembly into a separate app domain.

    Hopefully that will point you in the right direction.
    I know I could do it with reflection, but that's always a last resort for me.

    I think I've probably done the best I simply can. But thanks.

    Leave a comment:


  • Jaws
    replied
    Using reflection you should be able to find the type in the assembly and use the type to invoke the method.

    So something like [NB code is not tested - and you are likely to need some null tests due to reflection almost always returning null and not throwing when types etc not found]

    Code:
    Assembly assembly = Assembly.LoadFile("... assembly path ..");
    Type methodHostType = assembly.GetType("... type name ...");
    MethodInfo method = methodHostType.GetMethod("... MethodName ...", BindingFlags.Public | BindingFlags.Static);
    
    object result = method.Invoke(null, ... params ...);
    You may also want to look at loading this assembly into a separate app domain.

    Hopefully that will point you in the right direction.

    Leave a comment:


  • ASB
    replied
    Originally posted by jmo21 View Post
    Sounds like a lot of fannying around, is there really no way to address the real issue of not getting the dll on your machine?

    If not, why not?
    No. It's licence and environment related. It accesses the whole world and requires assorted servers set up in a specific test configuration and all sorts of things.

    So, I've dealt with it by producing a wrapper which makes the decisions so the main code can be the same and it is switchable by configuration.

    My alternative was, in effect, to produce a DLL with the same types etc (which is what I wanted to do) but I couldn't figure a way of dynamiclly loading "real" or "simuator" thus this would only have been configurable at build time.

    Leave a comment:


  • jmo21
    replied
    Sounds like a lot of fannying around, is there really no way to address the real issue of not getting the dll on your machine?

    If not, why not?

    Leave a comment:


  • ASB
    started a topic .NET dynamically loading assembly

    .NET dynamically loading assembly

    I have a 3rd party assembly I need to use. However I can't install it on my development machine for a variety of reasons.

    What I was going to do was reference it but, for development, use activator.createinstance to create the types from a simulator I was planning to produce. They would obviously have the same signature.

    Now I'm a bit stumped. A number of the methods are static and I haven't got a clue how to emulate these.

    I would have a reference to the 3rd party DLL and my simulator and was planning to write something like:-

    dim typeToUse as 3rdParty.Type

    typeToUse = activator.createInstance"myEmulator.Type"

    Problem is that a number of the methods I need to access are static.

    e.g.

    result = 3rdParty.Type.DoSomething

    Any suggestions ??

    Basically I just want to create an assembly with the same objects, methods (both static and instance) and load it dynamically to get access to the types.
Working...
X