Ticket T108751
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

Class is not registered in unit tests

Upgrade from 12.2 to 13.2 Issue: class is not registered within the business model

created 11 years ago

After upgrading my project from 12.2 to 13.2, and doing some required changes for the upgrade ( mostly related to  Validator.RuleSet.Validate to include the object space).

I got the following error in my asp.net project when trying to execute the "Validator.RuleSet.Validate" :
"An exception occurred while validating an object:
Exception: 'The "GoldenHills.FastBird.Module.BusinessObjects.Orders.Order" class is not registered within the business model. To avoid this error, use the Module Designer (http://documentation.devexpress.com/#Xaf/CustomDocument2828)) to include the specified class into the module's AdditionalExportedTypes collection or manually register it via the XafTypesInfo.Instance.RegisterEntity(Type) method.'
Rule Id: 'DevExpress.Persistent.Validation.RuleUniqueValue_GoldenHills.FastBird.Module.BusinessObjects.Orders.Order_FBDNumber'
Rule Type: 'DevExpress.Persistent.Validation.RuleUniqueValue'
Target Object: '2014-18'"

The below is done in asp.net project that reference my XAF module:

using (var uow = ConnectionHelper.CreateObjectSpace())
            {
                try
                {
                    Session session = ((XPObjectSpace)uow).Session;
                    GeneralSettings generalSettings = session.FindObject<GeneralSettings>(CriteriaOperator.Parse(String.Empty));
   order = DataAccessHelper.GetObjectByKey<Order>(orderId, session);
   order.OrderDate = orderDateEdit.Date;
                    order.ApprovalStatus = approvalStatus;
   .
   .
   .
   .
   .
 Validator.RuleSet.Validate(uow,order, "Save"); // RAISE AN ERROR

order.Save();

uow.CommitChanges();

return order;

}
                catch (ValidationException vEx)
                {
                    ShowError(vEx.Message, "Validation Error");
                    return null;
                }
                catch (Exception ex)
                {
                    uow.Rollback();
                    ShowError(ex);
                    return null;
                }
}

Answers approved by DevExpress Support

created 11 years ago (modified 11 years ago)

Hello Adnan.

It looks like you are using the Validation Module outside the XAF application. If so, you need to pass XAF type information containing all the necessary classes in the XPObjectSpace or XPObjectSpaceProvider constructor.

    Show previous comments (5)
    DevExpress Support Team 11 years ago

      Modify your ConnectionHelper class as follows:

      C#
      public static class ConnectionHelper { public static Session GetNewSession() { return new Session(DataLayer); } public static UnitOfWork GetNewUnitOfWork() { return new UnitOfWork(DataLayer); } private readonly static object lockObject = new object(); static volatile IDataLayer fDataLayer; static IDataLayer DataLayer { get { if (fDataLayer == null) { lock (lockObject) { if (fDataLayer == null) { fDataLayer = GetDataLayer(); } } } return fDataLayer; } } private static string ConnectionString { get { return System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; } } private static IDataLayer GetDataLayer() { ModuleBase module = new UpgradeIssue.Module.UpgradeIssueModule(); foreach (Type type in module.GetExportedTypes()) { XafTypesInfo.Instance.RegisterEntity(type); } XPDictionary dict = XpoTypesInfoHelper.GetXpoTypeInfoSource().XPDictionary; IDataStore store = XpoDefault.GetConnectionProvider(ConnectionString, AutoCreateOption.SchemaAlreadyExists); IDataLayer dl = new ThreadSafeDataLayer(dict, store); return dl; } public static IObjectSpace CreateObjectSpace() { IDataLayer dal = DataLayer; IObjectSpace os = new XPObjectSpace(XafTypesInfo.Instance, XpoTypesInfoHelper.GetXpoTypeInfoSource(), new CreateUnitOfWorkHandler(delegate() { return new UnitOfWork(dal); })); return os; } }

      Note, there's no need to use the ConnectionHelper.Connect method at all.

        It worked! thanks for your amazing support!

        DevExpress Support Team 11 years ago

          You are welcome. Should you have any additional questions, please let me know.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.