Reputation: 16545
I have a dll called Test.dll in which I have a class called ABC which has a method FindTYpe.
Now, I have a project called TestB and I have added the reference of Test.dll in TestB.
Now, if I am trying to find a type XYZ in TestB, from Test.ABC.FindTYpe()
, it's throwing an exception, TypeNotLaoded Exception
.
Please have a look at the problem and tell me how can I resolve it.
Upvotes: 3
Views: 174
Reputation: 21470
You'll need to post your code for FindType(). My guess is that you're doing something like;
System.Reflection.Assembly.GetExecutingAssembly().GetTypes()
to find a list of types to search through, and the type in TestB.dll isn't in Test.dll, so the item isn't found.
You might want to try something like this instead;
/// <summary>
/// Returns all types in the current AppDomain
/// </summary>
public static IEnumerable<Type> LoadedType()
{
return AppDomain
.CurrentDomain
.GetAssemblies()
.SelectMany(assembly => assembly.GetTypes());
}
which should give you the all types loaded into the current application domain -- which, unless you're doing anything odd with appdomains, will be the list of all types loaded into your program.
None of the code has been tested, but it should help you find the classes and methods you'll need to use.
Upvotes: 2
Reputation: 41298
What does the code look like in FindType? Assuming you are creating the type from the type name (a string), then you must be sure to supply the "assembly qualified" type name, not just the "local" type name.
e.g. to retrieve the type you are about to create:
Type testB = Type.GetType("TestB.XYZ, TestB");
rather than
Type testB = Type.GetType("TestB");
Can you give some more specifics, like some code snippets?
Upvotes: 0
Reputation: 40497
Mos probably the type XYZ that you are trying to find is not loaded or not present in the paths your app looks for assemblies. The Test.dll and ABC should be present it you added the reference in your project to Test.dll.
Upvotes: 0