Hi and thanks Nicholas,
I am not sure I understand the solution you propose?
Plus the entire purpose of the exercise for me, is to dynamically
create assembly AFTER the active record initialization and to register
it after it's been compiled on the fly.
Note that I have tried to explicitly add the class to the solution in
order to test the following code:
ActiveRecordStarter.RegisterTypes(typeof(iTradeType1));
iTradeType1 it = new iTradeType1();
it.Identifier = "DummyId";
it.Col2 = DateTime.Now;
it.Save();
and it works.
So it's definitely something to do with AC or NH beeing unhappy with
the assembly I have compiled. I am trying to check the assembly
manifest, without much luck.
Any other suggestions are welcomed.
On Jun 10, 11:24 am, Nicholas Kilian <[email protected]>
wrote:
> I actually had this same problem the other day, eventually found an obscure
> reference to the actual error in an NH bug report.
>
> You need to handle the AppDomain.CurrentDomain.AssemblyResolve event and
> return your compiled assembly - do this before initialising ActiveRecord.
>
> -----Original Message-----
> From: [email protected]
>
> [mailto:[email protected]] On Behalf Of Regis Dubois
> Sent: 10 June 2011 12:00 PM
> To: Castle Project Users
> Subject: Problem saving an object created dynamically with reflection
>
> Hi, I am trying to get the following to work without much success:
>
> This class is read from file and compiled in memory:
>
> using System;
> using Castle.ActiveRecord;
> using iTradeStorage.ValueObjects;
> namespace iTradeStorage.ValueObjects
> {
> [ActiveRecord]
> public class iTradeType1 : ActiveRecordBase
> {
> [PrimaryKey]
> public string Identifier { get; set; }
> [Property]
> public String Col1 { get; set; }
> [Property]
> public DateTime Col2 { get; set; }
> }
> }
>
> A table existe in the db that matches this class. (created using
> UpdateSchema())
>
> I then try to save an object, the following way:
>
> Type type = _typeManager.GetType(typeVo); //return the type
> iTradeType1
> object theObject = Activator.CreateInstance(type);
> PropertyInfo[] pis = type.GetProperties();
> Dictionary<string, PropertyInfo> propertyInfosPerName = new
> Dictionary<string, PropertyInfo>();
> foreach (PropertyInfo propertyInfo in pis)
> {
> //PropertyAttributes pas = propertyInfo.Attributes;
> propertyInfosPerName.Add(propertyInfo.Name,
> propertyInfo);
> }
> string id = "thisisatest";
> propertyInfosPerName["Identifier"].SetValue(theObject, id,
> null);
> propertyInfosPerName["Col1"].SetValue(theObject,
> "col1ValTest", null);
> propertyInfosPerName["Col2"].SetValue(theObject,
> DateTime.Now, null);
>
> ((ActiveRecordBase)theObject).Save();
>
> and get the following exception:
>
> {"Could not perform Save for iTradeType1"} Inner ex: {"Exception occurred
> getter of Rbs.Gbm.Sgi.iTradeStorage.ValueObjects.iTradeType1.Identifier"}
> Innder ex: {"Object does not match target type."}
>
> at Castle.ActiveRecord.ActiveRecordBase.InternalSave(Object
> instance, Boolean flush) in c:\TeamCity\buildAgent\work
> \e41ee5ead2eba140\src\Castle.ActiveRecord\Framework
> \ActiveRecordBase.cs:line 601
> at Castle.ActiveRecord.ActiveRecordBase.Save(Object instance) in c:
> \TeamCity\buildAgent\work\e41ee5ead2eba140\src\Castle.ActiveRecord
> \Framework\ActiveRecordBase.cs:line 510
> at Castle.ActiveRecord.ActiveRecordBase.Save() in c:\TeamCity
> \buildAgent\work\e41ee5ead2eba140\src\Castle.ActiveRecord\Framework
> \ActiveRecordBase.cs:line 1547
> at
> Rbs.Gbm.Sgi.iTradeStorage.ObjectManagement.ObjectManager.StoreObject(String
> objectXml) in C:\Development\Rbs.Gbm.Sgi\iTradeStorage\ObjectManagement
> \ObjectManager.cs:line 58
> at ObjectManagementTests.ObjectManagerTests.StoreObjectTest() in C:
> \Development\Rbs.Gbm.Sgi\iTradeStorage\Tests\ObjectManagementTests
> \ObjectManagerTests.cs:line 78
>
> Can somebody kindly help?
>
> I'd like to try and debug the active record source code but can't seem to
> find it. Where canI get ahold of it?
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Castle Project Users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group
> athttp://groups.google.com/group/castle-project-users?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en.