How to add an assembly to another assembly?

I have a dll called Test.dll in which I have an ABC class that has a FindTYpe method. Now I have a TestB project, and I added the Test.dll link to TestB. Now, if I'm trying to find the type XYZ in TestB, from Test.ABC.FindTYpe(), it throws an exception TypeNotLaoded Exception.

Please take a look at the problem and tell me how to solve it.

+3
source share
3 answers

You will need to publish your code for FindType (). I assume you are doing something like:

System.Reflection.Assembly.GetExecutingAssembly().GetTypes()

to find the list of types to search, and the type in TestB.dll is missing in Test.dll, so the element was not found.

Instead, you can try something like this:

/// <summary>
/// Returns all types in the current AppDomain
/// </summary>
public static IEnumerable<Type> LoadedType()
{
    return AppDomain
        .CurrentDomain
        .GetAssemblies()
        .SelectMany(assembly => assembly.GetTypes());
}

, , , appdomains, , .

, , .

+2

, , XYZ, , , . Test.dll ABC , Test.dll.

0

FindType? , (), "assembly qualified", "local".

eg. to get the type you are going to create:

Type testB = Type.GetType("TestB.XYZ, TestB");

but not

Type testB = Type.GetType("TestB");

Can you give more detailed information, for example, some code fragments?

0
source

Source: https://habr.com/ru/post/1712092/


All Articles