This topic describes what to do if your application does not find a Persistent Class definition.
The enhanced classes have a static constructor that registers all the necessary information in a global data structure. This structure must be filled when the first Database.Get call is used because OpenAccess builds up meta information at this point in time. Microsoft’s assembly load strategy loads an assembly at the time when the first type out of the assembly is used. Because of this OpenAccess applications must instantiate one object from each assembly with persistent classes before the first Database.Get call, to be sure all necessary OpenAccess information is computed.
To test if everything is correct, you can execute the code below directly before your first Database.Get call. The code prints out all the loaded assemblies, the enhanced status and all the loaded persistent classes.
| C# |
Copy Code |
|
// Get all assemblies loaded in the current domain. System.Text.StringBuilder strbuf = new System.Text.StringBuilder(); System.Reflection.Assembly[] assemblies = System.AppDomain.CurrentDomain.GetAssemblies();
foreach ( System.Reflection.Assembly assembly in assemblies ) { string name = assembly.FullName; strbuf.Append( name ).Append( "\r\n" );
// Check if the current assembly // is marked with the EnhancedExAttribute. object[] customAttributes = assembly.GetCustomAttributes(typeof (Telerik.OpenAccess.RT.EnhancedExAttribute), false);
if ( customAttributes.Length == 1 ) { strbuf.Append( " Enhanced!\r\n" ); // Print all persistent capable classes in the assembly. foreach ( Type t in assembly.GetTypes() ) if ( typeof( Telerik.OpenAccess.SPI.dataobjects.PersistenceCapable ) .IsAssignableFrom( t ) ) strbuf.Append( " Persistent Type: " ) .Append( t.FullName ).Append( "\r\n" ); } } System.Console.WriteLine( strbuf.ToString() ); |
| VB .NET |
Copy Code |
|
Dim strbuf As New System.Text.StringBuilder() Dim assemblies() As System.Reflection.Assembly = System.AppDomain.CurrentDomain.GetAssemblies()
For Each [assembly] As System.Reflection.Assembly In assemblies Dim name As String = [assembly].FullName strbuf.Append(name).Append(vbCrLf)
Dim customAttributes() As Object = [assembly].GetCustomAttributes(GetType(Telerik.OpenAccess.RT.EnhancedExAttribute), False)
If customAttributes.Length = 1 Then strbuf.Append(" Enhanced!" & vbCrLf) For Each t As Type In [assembly].GetTypes() If GetType(Telerik.OpenAccess.SPI.dataobjects.PersistenceCapable).IsAssignableFrom(t) Then strbuf.Append(" Persistent Type: ").Append(t.FullName).Append(vbCrLf) End If Next t End If Next [assembly]
System.Console.WriteLine(strbuf.ToString())
|
If you can see that your assemblies are enhanced and all your persistent types are printed out this part is correct. If not, please create an instance of the missing Persistent Class above the code. For example:
| C# |
Copy Code |
|
Category category = new Category(); |
| VB.NET |
Copy Code |
|
Dim _category As New Category() |