Solved

how to use AppDomain.CreateDomain with AssemblyResolve?

Posted on 2012-03-15
4
539 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
ID: 37728225
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
ID: 37729001
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
ID: 37746911
@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
ID: 37820799
you are too boring!!!!!!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

930 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

12 Experts available now in Live!

Get 1:1 Help Now