thanks everyone.. I should have been more precice in my problem description. Sorry!
I can debug in Visual Studio right upto the the Member m = Member.GetCurrent(); and can see that member object has been loaded.
I know which user I am testing and can see the Property PreferdUserName with a value in the admin / members dialog. So this is what is really confusing
Here the code I've been using to narrow down the problem. (Member has definetly been loaded..)
public override void Transfer(umbraco.cms.businesslogic.member.Member m) { //PropertyType.GetPropertyType();
this.UserName = m.LoginName; //PropertyType pt = new PropertyType(); try { Property displayNameProp = m.getProperties.First(p => p.PropertyType.Alias == "PreferdUserName"); string bla = "123"; } catch (Exception ex) // no occurence found exception (because getProperties has a count of zero) { string e = ex.ToString(); }
try { Property s = m.getProperty("PreferdUserName"); string bla = s.Value.toString(); } catch (Exception ex) // Null reference exception { string e = ex.ToString(); }
I tried your code and mine and bahm ran into the same error. After a littel bit of debugging moving the code to other places it suddenly worked even in the place where i got the error!
So there are two mor questions for me: 1. are you running in MediumTrust Environment? 2. Where does the call happen (some kind of handler/module, aspx page or usercontrol)?
I'm running the code from a REST WCF service which is running in the same website as umbraco. As mentioned above I can use other Umbraco API objects perfectly well. But that could be the issue.. I'll try and move the code into a "normal" user and report
I moved the code into a user control and debugged it and it is still giving me errors. Strangely enough it worked once in the immeadiate window:
? m.getProperty("PreferdUserName") w3wp.exe Information: 0 : 122. RecordsReader created by CMSNode.setupNode. Open Data Readers: 2 w3wp.exe Information: 0 : 122. RecordsReader closed. Open Data Readers: 1 w3wp.exe Information: 0 : 123. RecordsReader created by ContentType.setupContentType. Open Data Readers: 2 w3wp.exe Information: 0 : 123. RecordsReader closed. Open Data Readers: 1 w3wp.exe Information: 0 : 124. RecordsReader created by ContentType.<get_PropertyTypes>b__0. Open Data Readers: 2 w3wp.exe Information: 0 : 124. RecordsReader closed. Open Data Readers: 1 {umbraco.cms.businesslogic.property.Property} _data: {umbraco.cms.businesslogic.datatype.DefaultData} _id: 169 _pt: {umbraco.cms.businesslogic.propertytype.PropertyType} Id: 169 PropertyType: {umbraco.cms.businesslogic.propertytype.PropertyType} Value: "kg123" VersionId: {2f038821-cf46-49d0-9397-2147ee1c462c}
Later attempts even after an IISreset only produce this in the immediate window:
? m.getProperty("PreferdUserName") w3wp.exe Information: 0 : 75. RecordsReader created by Content.get_Version. Open Data Readers: 1 w3wp.exe Information: 0 : 75. RecordsReader closed. Open Data Readers: 0 w3wp.exe Information: 0 : 76. RecordsReader created by CMSNode.setupNode. Open Data Readers: 1 w3wp.exe Information: 0 : 76. RecordsReader closed. Open Data Readers: 0 w3wp.exe Information: 0 : 77. RecordsReader created by DataTypeDefinition.setupDataTypeDefinition. Open Data Readers: 1 w3wp.exe Information: 0 : 77. RecordsReader closed. Open Data Readers: 0 w3wp.exe Information: 0 : 78. RecordsReader created by Document.GetDocumentsForRelease. Open Data Readers: 1 w3wp.exe Information: 0 : 78. RecordsReader closed. Open Data Readers: 0 w3wp.exe Information: 0 : 79. RecordsReader created by Document.GetDocumentsForExpiration. Open Data Readers: 1 w3wp.exe Information: 0 : 79. RecordsReader closed. Open Data Readers: 0 w3wp.exe Information: 0 : 80. RecordsReader created by Document.GetDocumentsForRelease. Open Data Readers: 1 w3wp.exe Information: 0 : 80. RecordsReader closed. Open Data Readers: 0 w3wp.exe Information: 0 : 81. RecordsReader created by Document.GetDocumentsForExpiration. Open Data Readers: 1 w3wp.exe Information: 0 : 81. RecordsReader closed. Open Data Readers: 0
I read somewhere else that this getProperty Method will deprecated in the near future, (can't find the link now). Is there an alternative of doing this.. It should be so simple..
Get Properties from Member in Umbraco programmatically
I thought this would be really simple but ..
We've create a user and a member type with various properties When we try to access the properties via the member object we got nothing.
//Member m is current User
eg. Property s = m.getProperty("PreferdUserName"); is null
m.getProperties has a count of Zero..
have we missed something obvious?
Hi Karsten,
I think you have missed the .value property on the end.
So basically your code should read:
string username = m.getProperty("PreferdUserName").Value.ToString();
Hope this helps.
Cheers,
Neil
Neil,
thanks for your reply. I've tried that as well. Wenn accessing the the property that way I get a "object not set to a .. " error...
Karsten
Try hard coding the memberId in(just as a test) and getting the member that way i.e Member m = new Member(1234);
Then test to see if you can access the specific member property.
It could be that the member is coming back null, when you are calling Member m = Member.GetCurrent();
Cheers,
Neil
You should check if the property is not DBNull.Value
Property localeProperty = m.getProperty("memberProfileCustomerLocale");
String locale = (localeProperty.Value != DBNull.Value && (String)localeProperty.Value != "") ? (String)localeProperty.Value : "en-GB";
thanks everyone.. I should have been more precice in my problem description. Sorry!
I can debug in Visual Studio right upto the the Member m = Member.GetCurrent(); and can see that member object has been loaded.
I know which user I am testing and can see the Property PreferdUserName with a value in the admin / members dialog. So this is what is really confusing
Here the code I've been using to narrow down the problem. (Member has definetly been loaded..)
Hello Karsten,
did you try using the GenericProperties Proterty? Like this:
this worked for me :)
Toby
When accessing GenericProperties I get:
"The type initializer for 'umbraco.cms.businesslogic.datatype.controls.Factory' threw an exception."
?
This is totally strang!
I tried your code and mine and bahm ran into the same error. After a littel bit of debugging moving the code to other places it suddenly worked even in the place where i got the error!
So there are two mor questions for me: 1. are you running in MediumTrust Environment? 2. Where does the call happen (some kind of handler/module, aspx page or usercontrol)?
Maybe this could get us closer to an answer...
I'm running the code from a REST WCF service which is running in the same website as umbraco. As mentioned above I can use other Umbraco API objects perfectly well. But that could be the issue.. I'll try and move the code into a "normal" user and report
I moved the code into a user control and debugged it and it is still giving me errors. Strangely enough it worked once in the immeadiate window:
Later attempts even after an IISreset only produce this in the immediate window:
I read somewhere else that this getProperty Method will deprecated in the near future, (can't find the link now). Is there an alternative of doing this.. It should be so simple..
is working on a reply...