Solved

how to use AppDomain.CreateDomain with AssemblyResolve?

Posted on 2012-03-15
4
548 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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