This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi Guys, I'm alittle confused about the following error message when creating a lightspeed object and then trying to read back from that object without saving it to the database and the retreiving it from the db: Unable to use automatic property name detection for type 'object name' because multiple properties refer to field '_propertyName'. Change all property setters to use the Set overload which takes a property name. |
|
|
When you set a property in LightSpeed, LightSpeed needs to raise the PropertyChanged event for that property. To do this, it needs to know the property name. In order to save you the typing and maintenance hassle, LightSpeed provides a Set overload which tries to work out the name: Set(ref T field, T value) The way this tries to work out the name is by inspecting the compiled code of the class to see which property refers to the field at hand. However, if multiple properties refer to the field at hand, LightSpeed can't pick one name to put in the PropertyChanged event, so it asks you to help it out by using the following overload instead: Set(ref T field, T value, string propertyName) (Designer generated code always uses the second overload because typing and maintenance aren't issues when the designer is generating the setter.) So you need to find which of your properties refer to the _propertyName field, and change them to use the second overload. It's also possible for this error to occur on property getters (yes, the error message is misleading). If that's the case, the solution is similar -- call the Get overload which includes a property name. However, we currently have an issue where the designer does not generate property names into getters, so if you're using designer-generated code and you're getting this error in a getter, the fix is a little more complicated. Let us know if this is the case and we'll post the necessary instructions. |
|
|
unfortunatly i'm using straight designed code and i'm getting this error :-) |
|
|
In a getter or setter? Could you post the stack trace? |
|
|
in the getter, the _propertyName has the correct value assigned to it, however when trying to read it, i'm getting the following error, I'm assuming it's not as easy as changing the get code in the models code behind. The only way i can think to get around this issue is to pull the property out into a partial class? at Mindscape.LightSpeed.LightSpeedException.(Exception , String , Object[] ) ect......
|
|
|
. |
|
|
Hmm, looking at the change logs, it looks like we actually fixed the designer just after 2.2 RTM to generate the 'safe' Get code. So if you're on RTM then could you upgrade to the nightly and see if that fixes the problem? (If you're already on a nightly then something's awry -- let us know.) If you can't upgrade to the nightly, then yes, unfortunately you will need to pull the property out into a partial class. You can leave the field as designer-generated, i.e. set Generation to FieldOnly. Then implement the setter using the usual pattern: Set(ref _propertyName, value, "PropertyName"); For the getter, if the field is NOT lazy-loaded (i.e. does not have the EagerLoadAttribute on it), implement the getter to just return the field value: return _propertyName; If the field may be lazy-loaded, implement the getter with the name overload: return Get(ref _propertyName, "PropertyName"); |
|
|
I'm running v2.0.50727. |
|
|
2.0.50727 the CLR version number, not the LightSpeed version number. Check Mindscape.LightSpeed.dll -- if the last part of the version number is 10525 or higher, you should have the fix; if it's 10524 or lower, we'd suggest upgrading to the nightly. (If you do upgrade, then please note the warning about manually uninstalling RTM first, otherwise you are likely to see weird errors in the designer.) |
|
|
my bad, sorry, i'm using version, 2.2.1290.12172, so it appears i have the fix. When i look at the generated code however, the setter passed the caller but the getter does not, is there a property i need to set somewhere? Eg: public string ModifiedBy |
|
|
Strange, you should have the fix as far as I can see, and you shouldn't need to make any specific setting to enable it. You're not using custom templates by any chance? If you are, you need to merge the fix into them, by replacing the existing getter line with: get { return Get(ref _$Inflector.CamelCase($field), "$field.Name"); } If you're not using custom templates, you can insert this fix into the templates yourself. To do this: Shut down Visual Studio. Go to the install directory and look under Tools > Designer > Templates > C#. Open FieldProperties.vm in a text editor and replace the first line that looks like this: get { return Get(ref _$Inflector.CamelCase($field)); } with the line above. (You might want to take a backup first!) You don't need to modify any subsequent Get lines. Then make a change to your model (e.g. move a shape slightly and then move it back) and you should see this change in the generated code. Alternatively, if you don't want to muck around with the templates, you can apply the partial class solution we discussed above -- it's a one-off fix but avoids the risk of messing up the templates! |
|
|
Yeah don't really want to be hacking around with partial classes, and my template looks like this already
If someone else made a change with an older version of light speed and then commited the change, perhaps this error could occur?
|
|
|
Aha! Yes, that would certainly cause it. |
|
|
yeah, i just forced the model to regenerate and it's working again now :-) |
|