CSLA .NET

From Rockford Lhotka's Expert C# 2008 and VB 2008 Business Objects books

Silverlight inheritance

rated by 0 users
Not Answered This post has 0 verified answers | 7 Replies | 2 Followers

Top 500 Contributor
28 Posts
Calin posted on Sat, Feb 6 2010 5:25 AM

Hi, I am using CSLA for silverlight in a 3 tier scenario, all communication is done throw the WcfPortal. I have a base business class declared like this: public class BaseBussinesObject : BusinessBase where TBussinesObject : BaseBussinesObject witch has some common properties like Id my business classes use this like this: public partial class User : BaseBussinesObject The issue I have is that when I try to access from User properties that are in the base class I get a exception: "The type initializer for 'Business.Bos.BaseBussinesObject`1' threw an exception." What am I missing here ? Thank you,

All Replies

Top 10 Contributor
7,309 Posts

I'd have to see more complete code to help.

Rocky

Not Ranked
9 Posts

I am not sure if this will solve the problem but I remember a similar situation where the error was due to the static properties not being correctly registered.

 

Top 200 Contributor
35 Posts

I thought that there was code in the CSLA base classes to initialize the static PropertyInfo stuff now?  We have experienced the same symptom but did not dig deep to find the cause.  We simply adjusted our debuging strategy to solve the problem.  I would love to track down and fix the underlying cause but can't seem to find the time these days.

Top 10 Contributor
7,309 Posts

In .NET that's true always.

In SL that's true only if the PropertyInfo<T> fields are declared public - that's due to a private reflection limitation of SL.

But of course the base class generic type and RegisterProperty() calls still have to be done correctly or the registration won't be correct even if it does run.

Rocky

Top 500 Contributor
28 Posts
Calin replied on Mon, Feb 8 2010 12:19 AM

Hi All,

 This is my base class:

 

public abstract class BaseBussinesObject<TBussinesObject> : BusinessBase<TBussinesObject>

            where TBussinesObject : BaseBussinesObject<TBussinesObject>

    {      

        public static PropertyInfo<int> IdProperty = RegisterProperty<int>(x => x.Id);

        public int Id

        {

            get { return GetProperty(IdProperty); }

            set { SetProperty(IdProperty, value); }

        }

}

 

And here is a implemenation:

public partial class User : BaseBussinesObject <User>

    {

}

 

Accessing User.Id from the silvelight application throws the exception from the first post.

Hope this makes thinks more clear.

 

Regards,

 

Top 10 Contributor
7,309 Posts

You create the object by calling DataPortal.Create() right?

Rocky

Top 500 Contributor
28 Posts
Calin replied on Tue, Feb 9 2010 12:09 AM

Hi,

 

 I am actually using this to get the entity

 

public static void Get(EventHandler<DataPortalResult<User>> callback, int id)

        {

            var dp = new DataPortal<User>();

            dp.FetchCompleted += callback;

            dp.BeginFetch(new SingleCriteria<User, int>(id));

        }

 

Regards,

Page 1 of 1 (8 items) | RSS

Please contact Magenic for your .NET consulting
and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems