Adding Collection property into class which is not persisted into database

Nov 20, 2013 at 4:38 PM
Hi,

I've added one collection property into a class which has [NotPersisted] on it. When the object of class is displayed on the UI, I can see the collection property on it. But when I tried to expand the list of collection property by clicking it, it gave me the exception below. Any suggestion on that please?



The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.


__Source Error:


Line 56: public override ActionResult EditObject(ObjectAndControlData controlData, FormCollection form)
Line 57: {
Line 58: var actionResult = base.EditObject(controlData, form);
Line 59: AuditService.Audit(actionResult, controlData, form, "EditObject", Request);
Line 60: return actionResult;

Source File: c:\SDM_DEV\Trunk\Code\DELIVERY\business4\Sdm.App\Sdm.App\Controllers\GenericController.cs Line: 58

Stack Trace:


[FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. ]
System.Convert.FromBase64_ComputeResultLength(Char* inputPtr, Int32 inputLength) +10581781
System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength) +71
System.Convert.FromBase64String(String s) +41
NakedObjects.Web.Mvc.Helpers.SimpleEncryptDecrypt.Decrypt(HttpSessionStateBase session, String toDecrypt) +80
NakedObjects.Web.Mvc.Helpers.SimpleEncryptDecrypt.Decrypt(HttpSessionStateBase session, NameValueCollection collection) +419
NakedObjects.Web.Mvc.Controllers.NakedObjectsController.Decrypt(FormCollection form) +120
NakedObjects.Web.Mvc.Controllers.GenericControllerImpl.EditObject(ObjectAndControlData controlData, FormCollection form) +81
Sdm.App.NF5.Controllers.GenericController.EditObject(ObjectAndControlData controlData, FormCollection form) in c:\SDM_DEV\Trunk\Code\DELIVERY\business4\Sdm.App\Sdm.App\Controllers\GenericController.cs:58
lambda_method(Closure , ControllerBase , Object[] ) +246
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +211
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
2 parameters) +27
System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +28
System.Web.Mvc.Async.<>c__DisplayClass81.<BeginSynchronous>b__7(IAsyncResult _) +10
System.Web.Mvc.Async.WrappedAsyncResult
1.End() +57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +48
System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +57
System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +223
System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResult1.End() +57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +48
System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +24
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +102
System.Web.Mvc.Async.WrappedAsyncResult
1.End() +57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +43
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult1.End() +62
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +57
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult
1.End() +62
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +47
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +47
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9628972
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
__
Coordinator
Nov 20, 2013 at 5:03 PM
Edited Nov 20, 2013 at 5:04 PM
[NotPersisted] (as applied to a whole class) was what we had to use before we had ViewModels; one of the limitations of the former was that you could not have collections on it. The reason is that when you click on the collection, it is going back to the server and needs to pass in the 'Oid' for the object to get the collection; a [NotPersisted] Object (like a transient object) has no Oid.

A viewmodel does have an Oid - using the keys specified by the DeriveKeys() method - it behaves exactly the same (from the point of view of client-server interactions) as a persisted object.

So, short answer: remove the NotPersisted and make your class implement IViewModel. (And don't forget that you need to created it using Container.NewViewModel() - instead of Container.NewTransientInstance).