*Experts* Merrion Posted August 30, 2004 *Experts* Posted August 30, 2004 (edited) [PLAIN][resolved] System.TypeLoadException dynamically loading classes from DLLs[/PLAIN] OK - I am writing an application that allows you to add plug-ins DLLs that implement a specific license. So in the .config file I hagve something like:- <dataSchemaProvidors> <!-- The plug in providors that implement the DataSchemabase classes to write out the DDL for creating the database objects on the target database platform Key= The unique name that the providor is known by ImplementingAssembly = The assembly that holds the providor ImplementingClassType = The class that implements the providor --> <dataSchemaProvidor Key="SQL Server" ImplementingAssembly="SQLServerDataSchema.dll" ImplementingClassType="SQLServerDatasource"/> </dataSchemaProvidors> Then in a totally seperate project I create a DLL called "SQLServerDataSchema.dll" and it exports a public class "SQLServerDatasource". My container program is supposed to instantiate it by:- #Region "Instance" Public ReadOnly Property Instance() As Object Get If _Instance Is Nothing Then _Instance = Activator.CreateInstanceFrom(_ImplementingAssembly, _ImplementingClassType) End If Return _Instance End Get End Property #End Region Where _ImplementingAssembly holds the DLL name and _ImplementingClassType the class name in that DLL. However I am getting an exception: Additional information: Could not load type SQLServerDatasource from assembly SQLServerDataSchema, Version=1.0.1700.16719, Culture=neutral, PublicKeyToken=null. Resolution Ity turns out that even though no namespace was specified the DLL name was used as a default namespace so the config file should have held:- <dataSchemaProvidor Key="SQL Server" ImplementingAssembly="SQLServerDataSchema.dll" ImplementingClassType="SQLServerDataSchema.SQLServerDatasource"/> Edited August 30, 2004 by Merrion Quote Printer Monitor for .NET? - see Merrion Computing Ltd for details
Arch4ngel Posted August 30, 2004 Posted August 30, 2004 Which value did you try for _ImplementingAssembly and _ImplementingClassType ? Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
Administrators PlausiblyDamp Posted August 30, 2004 Administrators Posted August 30, 2004 Are you qualifying the class names with a namespace? If so you will also need to include that as part of the _ImplementingClassType's value. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
*Experts* Merrion Posted August 30, 2004 Author *Experts* Posted August 30, 2004 There's no namespace and the values _ImplementingAssembly and _ImplementingClassType are being read from the .config file OK. Strangely when I do this:- #Region "Instance" Public ReadOnly Property Instance() As Object Get If _Instance Is Nothing Then Try ' Dim hdlSample As ObjectHandle hdlSample = Activator.CreateInstanceFrom(_ImplementingAssembly, _ImplementingClassType) _Instance = hdlSample.Unwrap Catch ex1 As System.TypeLoadException Console.Write(ex1.GetBaseException.ToString) 'Try to find the class yourself... Dim assyPlugIn As System.Reflection.Assembly Dim fiAssy As New System.IO.FileInfo(_ImplementingAssembly) If fiAssy.Exists Then Try assyPlugIn = AppDomain.CurrentDomain.Load(_ImplementingAssembly) Catch fnf As System.IO.FileNotFoundException Console.WriteLine("Could not find " & fnf.FileName) Exit Property End Try Else Exit Property End If Dim typThis As Type For Each typThis In assyPlugIn.GetTypes Console.WriteLine(typThis.Name) If Not typThis.GetInterface("IDataSource", True) Is Nothing Then Console.WriteLine("Gotcha") End If Next End Try End If Return _Instance End Get End Property #End Region It gets to the line Console.WriteLine("Could not find " & fnf.FileName) which means that the FileInfo class sees the file but the CurrentDomain.Load() doesn't. Very strange... Quote Printer Monitor for .NET? - see Merrion Computing Ltd for details
Administrators PlausiblyDamp Posted August 30, 2004 Administrators Posted August 30, 2004 Hmm, have you tried using Assembly.LoadFile - just to see if that works, just curious if Appdomain does odd things with the path. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Arch4ngel Posted August 30, 2004 Posted August 30, 2004 I knew that an "Expert" would resolve this by his own. :p Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
*Experts* Merrion Posted September 1, 2004 Author *Experts* Posted September 1, 2004 The work in progress is up on GotDotNet Quote Printer Monitor for .NET? - see Merrion Computing Ltd for details
Administrators PlausiblyDamp Posted September 2, 2004 Administrators Posted September 2, 2004 Getting an access denied.... Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.