So I've been working on this idea of consolidating my code a bit more and tightening the inheritance. What I've done is taken my "Factory Methods" and moved them up in the hierarchy so all my objects can use them. This way I don't have to have so much redundant code. The RuleBusinessListBase is working fine until after it grabs the database records and then crashes on populating the RuleBusinessBase object. It throws an error of "The type initializer for "CK.Library.Albumtrack" threw an exception". I'm just using AlbumTrack as an example of the object. This is now happening on all objects and I'm wondering what could be the problem. I've googled already possibilities and came up with the constructor is missing. But unfortunately I have a constructor in all of my objects. I also found it a bit weird that I have to comply with CLSCompiant(False) with the ID and Name encapsulating properties as well in the RuleBusinessBase class. Let me know if you come across any ideas.
The next line crashes here with an error of "The type initializer for "AlbumTrack" threw an exception".
Can you post more information about the exception (stacktrace, innerException, etc?)
I hope this helps.
Exception Details: System.NotSupportedException: Invalid operation - create not allowed
Stack Trace:
[NotSupportedException: Invalid operation - create not allowed]
Csla.BusinessListBase`2.DataPortal_Create() in D:\cslavb 3.6.3\Csla\BusinessListBase.vb:1161
dm(Object , Object[] ) +55
Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in D:\cslavb 3.6.3\Csla\Reflection\MethodCaller.vb:272
[CallMethodException: DataPortal_Create method call failed]
Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in D:\cslavb 3.6.3\Csla\Reflection\MethodCaller.vb:274
Csla.Reflection.MethodCaller.CallMethod(Object obj, String method, Object[] parameters) in D:\cslavb 3.6.3\Csla\Reflection\MethodCaller.vb:201
Csla.Reflection.LateBoundObject.CallMethod(String method) in D:\cslavb 3.6.3\Csla\Reflection\LateBoundObject.vb:75
Csla.Server.SimpleDataPortal.Create(Type objectType, Object criteria, DataPortalContext context) in D:\cslavb 3.6.3\Csla\Server\SimpleDataPortal.vb:47
[DataPortalException: DataPortal.Create failed (System.NotSupportedException: Invalid operation - create not allowed
at Csla.BusinessListBase`2.DataPortal_Create() in D:\cslavb 3.6.3\Csla\BusinessListBase.vb:line 1161
at dm(Object , Object[] )
at Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in D:\cslavb 3.6.3\Csla\Reflection\MethodCaller.vb:line 272)]
Csla.DataPortal.Create(Type objectType, Object criteria) in D:\cslavb 3.6.3\Csla\DataPortal.vb:145
Csla.DataPortal.Create() in D:\cslavb 3.6.3\Csla\DataPortal.vb:78
Csla.RuleBusinessListBase`2.NewList() in D:\cslavb 3.6.3\Csla\Core\RuleBusinessListBase.vb:102
CK.Library.JobCategory..cctor() in D:\CreativeKnights\CK.Library\User\Job.vb:121
[TypeInitializationException: The type initializer for 'CK.Library.JobCategory' threw an exception.]
CK.Library.JobCategory.GetChildItem(JobCategory data) in D:\CreativeKnights\CK.Library\User\Job.vb:270
CK.Library.JobCategoryList.DataPortal_Fetch() in D:\CreativeKnights\CK.Library\User\Job.vb:68
dm(Object , Object[] ) +54
Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in D:\cslavb 3.6.3\Csla\Reflection\MethodCaller.vb:272
[CallMethodException: DataPortal_Fetch method call failed]
Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in D:\cslavb 3.6.3\Csla\Reflection\MethodCaller.vb:274
Csla.Reflection.MethodCaller.CallMethod(Object obj, String method, Object[] parameters) in D:\cslavb 3.6.3\Csla\Reflection\MethodCaller.vb:201
Csla.Reflection.LateBoundObject.CallMethod(String method) in D:\cslavb 3.6.3\Csla\Reflection\LateBoundObject.vb:75
Csla.Server.SimpleDataPortal.Fetch(Type objectType, Object criteria, DataPortalContext context) in D:\cslavb 3.6.3\Csla\Server\SimpleDataPortal.vb:109
[DataPortalException: DataPortal.Fetch failed (The type initializer for 'CK.Library.JobCategory' threw an exception.)]
Csla.DataPortal.Fetch(Type objectType, Object criteria) in D:\cslavb 3.6.3\Csla\DataPortal.vb:255
Csla.DataPortal.Fetch() in D:\cslavb 3.6.3\Csla\DataPortal.vb:179
Csla.RuleBusinessListBase`2.GetList() in D:\cslavb 3.6.3\Csla\Core\RuleBusinessListBase.vb:108
Page_Commerce_Types_Events.BindCategory() in D:\CreativeKnights\Web\Page\Commerce\Types\Events.aspx.vb:18
Page_Commerce_Types_Events.Page_Load(Object sender, EventArgs e) in D:\CreativeKnights\Web\Page\Commerce\Types\Events.aspx.vb:9
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Control.OnLoad(EventArgs e) +132
System.Web.UI.Control.LoadRecursive() +11032399
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428
I fixed it.. Apparently I was missing 3 methods in the RuleBusinessListBase and RuleBusinessbase. It was ...
which meant overloading all over the other methods
#Region "Data Access Create"
<RunLocal()> _
Protected Friend Overloads Sub DataPortal_Create()
End Sub
<RunLocal()> _
Protected Friend Overloads Sub DataPortal_Create(ByVal criteria As SingleCriteria(Of C, Nullable(Of Guid)))
End Sub
#End Region
#Region "Child Data Access"
Protected Friend Sub Child_Fetch()
End Sub
#End Region
The exception seems reasonably clear - you are trying to call DataPortal.Create, and it in turn is calling DataPortal_Create, which isn't implemented.
In 3.6 the default DataPortal_Create implementation throws this exception. In CSLA 4 this no longer throws, it "just works" - which still might or might not be what you want :)
Copyright (c) Marimer LLC