[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 626
  • Last Modified:

how to use AppDomain.CreateDomain with AssemblyResolve?

i want to load My Assemblies from wcf by using Memory. Every thing is working good WHEN:
   AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
        Assembly[] assBefore = AppDomain.CurrentDomain.GetAssemblies();
        foreach (byte[] binary in deCompressBinaries)
            loadedAssembly = AppDomain.CurrentDomain.Load(binary);

Open in new window


but i want to use AppDomain.CreateDomain not current domain:
     protected void LoadApplication()
    {
        this.ApplicationHost = AppDomain.CreateDomain("TestService", null, new AppDomainSetup
        {
            ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase
        });

        ApplicationHost.AssemblyResolve += new ResolveEventHandler(OnAssemblyResolve);
        foreach (AssemblyName asmbly in System.Reflection.Assembly.GetExecutingAssembly().GetReferencedAssemblies())
        {
            ApplicationHost.Load(asmbly);
        }
        List<byte[]> deCompressBinaries = new List<byte[]>();
        foreach (var item in AppPackage.Item.AssemblyPackage)
            deCompressBinaries.Add(item.Buffer);
        var decompressvalues =  DeCompress(deCompressBinaries);
        deCompressBinaries.Clear();
        deCompressBinaries = decompressvalues.ToList();

        foreach (byte[] binary in deCompressBinaries)
            ApplicationHost.Load(binary);

        Assembly[] assAfter = AppDomain.CurrentDomain.GetAssemblies();
    }
   Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
    {
        return Assembly.Load(args.Name);
    }

Open in new window

i have 2 ClassLibraries. ClassLibrary1 and ClassLibrary2 using below:
    namespace ClassLibrary2
{
    public class Class1 : MarshalByRefObject
    {
        public Class1()
        {

        }

        public int GetSum(int a , int b)
        {
            try
            {
                ClassLibrary1.Class1 ctx = new ClassLibrary1.Class1();
                return ctx.Sum(a, b);
            }
            catch
            {
                return -1;
            }

        }
        public int GetMultiply(int a, int b)
        {
            return a * b;
        }
    }
}

Open in new window

Classlibrary2 depends on ClassLibrary1. So i am using assemblyresolver. But Error on ApplicationHost.Load(binary);

Error: Could not load file or assembly 'ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

Also NOT FIRING ASSEMBLYRESOLVER. ny cursor is not goin to Assemblyresolver method. How to use AppDomain.CreateDomain with resolve method?
0
programmerist
Asked:
programmerist
  • 3
1 Solution
 
programmeristAuthor Commented:
why dont experts answer my questions? i spend money . i want to see value for my money.
0
 
Bob LearnedCommented:
Well, I can give it a go.  Let me say that sometimes, people are disinterested, or don't want to have to dig through a lot of detailed words, code dumps, etc.  I prefer not to have too much information up front, as it only clouds the question, and makes it difficult to understand your problem enough to help.

(Getting down off my "soap box" now)...

Have you looked into Fusion log, which helps with assembly binding issues?

Fuslogvw.exe (Assembly Binding Log Viewer)
http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.100).aspx
0
 
programmeristAuthor Commented:
@TheLearhedOne: thanks alot! but if you lokk my question title . my request is too simple. look this link . what is the diffuculty of look this ques.

is it too complex?
0
 
programmeristAuthor Commented:
you are too boring!!!!!!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now