Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All...
Am developed C# application for creating dll for some functionality,am creating two dll's at a time,for example Dll A and Dll B.
This Dll A is reference of Dll B.
So how to call Dll A from Dll B.
Am using following code for this, but i got error message.

the Code is

C#
public class Proxy : MarshalByRefObject
        {
            public Assembly GetAssembly(string assemblyPath)
            {
                try
                {
                    return Assembly.LoadFile(assemblyPath);
                }
                catch (Exception)
                {
                    return null;
                    // throw new InvalidOperationException(ex);
                }
            }
        } 


C#
string dynamicClassPath = File Path;


            AppDomain domains = AppDomain.CreateDomain("New domain name");
            Type type = typeof(Proxy);
            Proxy myObject = (Proxy)domains.CreateInstanceFromAndUnwrap(dynamicClassPath, type .FullName);


and the error is
Quote:
Could not load type 'FolderName.FileName+Proxy' from assembly 'Dynamic_id, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.

here
Dynamic_id
is a dll.


so pls help me how to do this??
sorry my poor English.



Thanks for your reply Mr.Sergey
But your reply is not helpful for me, now I post my question very clearly,
Dll A and B both are created dynamically.
The Following code in Dll A

C#
using System;

namespace ForTest
{
	public class Dynamic_Val_001
	{
		private string _Prop_Name;

		private string _Prop_Address;

		public virtual string Prop_Name
		{
			get
			{
				return this._Prop_Name;
			}
			set
			{
				this._Prop_Name = value;
			}
		}

		public virtual string Prop_Address
		{
			get
			{
				return this._Prop_Address;
			}
			set
			{
				this._Prop_Address = value;
			}
		}
	}
} 


the Dll B code is

C#
using System;

namespace ForTest
{
	public class Val_001
	{
		public virtual Tuple<bool, string> isValid(Dynamic_Val_001)
		{
			return new Tuple<bool, string>(false, "Success");
		}
	}
}


Now the Dll B have a one tuple bool function with one parameter, In that parameter is Dll A class name,so Dll B is depends on dll A.

So how to Call that Dll A class from Dll B.
Posted
Updated 19-Jan-16 20:43pm
v3

1 solution

I did not check up all your code sample; there is a number of delicate moments in working with application domains; perhaps you will ask separate questions later.

I'll only answer your question. The bug is you Assembly.LoadFile method. You have to use Assembly.LoadFrom:
Assembly.LoadFrom Method (System.Reflection)[^].

Blame not yourself but Microsoft naming and documentation; on this topic, it's not clear.

And the path should be correct. If this is a simple name, it can create a problem. First priority would be loading from a current working directory, but this directory could be anything; it depends on how the user starts the application. So you better should use, say, executable path or a path relative to it. Please see my past answers:
How to find my programs directory (executable directory),
How to find my programs directory (current directory, "special folders").

Just keep this path issue in mind.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900