Solved

how to use AppDomain.CreateDomain with AssemblyResolve?

Posted on 2012-03-15
4
538 Views
Last Modified: 2012-04-08
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
Comment
Question by:programmerist
  • 3
4 Comments
 

Accepted Solution

by:
programmerist earned 0 total points
Comment Utility
why dont experts answer my questions? i spend money . i want to see value for my money.
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
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
 

Author Comment

by:programmerist
Comment Utility
@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
 

Author Closing Comment

by:programmerist
Comment Utility
you are too boring!!!!!!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
asp.net mvc5 3 35
Exception in Log4Net 1 17
Round a string to two digits 12 23
Calling stored proc in EDMX 11 17
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now