ExtensibleStorage Field of value type string[]

ExtensibleStorage Field of value type string[]

Anonymous
Not applicable
1,551 Views
8 Replies
Message 1 of 9

ExtensibleStorage Field of value type string[]

Anonymous
Not applicable

Hi all,

 

I've encountered a problem when I'm trying to store an array of string to a field in a schema using ExtensibleStorage. It throws an InvalidOperationExcpetion on myEntity.Set(myFieldName, myStringArray) saying "Unsupported type: System.String[]"

 

Pseudocode:

var schemaBuilder = new SchemaBuilder(myGuid);
schemaBuilder.AddArrayField("myFieldName", typeof(string));
var mySchema = schemaBuilder.Finish();

var myField = mySchema.GetField("myFieldName");
var myEntity = newEntity(mySchema);

myEntity.Set(myField, new string[] {"string1", "string2"});
//throws InvalidOperationException: Unsupported type: System.String[]"

Any one have an idea of what I'm doing wrong?

 

 

Cheers,

Eirik

0 Likes
Accepted solutions (1)
1,552 Views
8 Replies
Replies (8)
Message 2 of 9

jeremytammik
Autodesk
Autodesk

Dear Eirik,

 

Yes, absolutely. 

 

Please take a close look at the exact function signature of 

 

myEntity.Set(myField,...

 

You will immediately see that it does not take a system array argument, but a generic list, templated to contain strings.

 

myEntity.Set(myField,new List<string>(...

 

Please also consult the extensive list of extensible storage samples provided by The Building Coder:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.23

 

It covers this topic and many others as well.

 

I hope this helps.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 9

Revitalizer
Advisor
Advisor
Accepted solution

Hi,

 

what about setting an IList<string> instead of string[] ?

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 4 of 9

Anonymous
Not applicable

Jeremy, 

 

Thank you for your answer.

 

When i try to use a generic list (List<string>) the following Exception is thrown

 

Unsupported type: System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]

I do think the method expects an Array, because in another function we have, we use an array of ElementIds (like new List<ElementId>{myElementId1, myElementId2}.ToArray(), which works like a charm. But a string array is not accepted.

 

 

Cheers,

Eirik

0 Likes
Message 5 of 9

Revitalizer
Advisor
Advisor

Hi,

 

try to use an IList instead of a List. Note the leading "I" 😉

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 6 of 9

jeremytammik
Autodesk
Autodesk

Thank you for your appreciation, and many thanks to Revitalizer for providing the more accurate answers!

 

Revitalizer is right.

 

As a computer programmer, we cannot ignore little details like that leading 'I'.

 

Also, please, in future do look at the samples provided.

 

This issue has been discussed before and is included in The Building Coder discussions as well.

 

Thank you!

 

Cheers,

 

Jeremy 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 7 of 9

Anonymous
Not applicable

An IList worked perfectly 🙂

 

Thank you very much Revitalizer and Jeremy!

 

 

Cheers,

Eirik

 

 

PS: Out of curiosity: Why wouldn't a List<T> work, when an IList<T> does work? (Maybe not the right forum, I know)

0 Likes
Message 8 of 9

Revitalizer
Advisor
Advisor

Hi eirik,

 

no idea why we need to use an IList.

 

But it says in the RevitAPI.chm:

 

"The types for containers are IList for arrays and IDictionary for maps"

 

It's on each of the pages of the Entity.Set() method overloads, see "Remarks".

So it's nearly an RTFM question 🙂

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 9 of 9

Anonymous
Not applicable

Revitalizer,

 

It is definitley a RTFM question. My bad. In hindseight.

 

 

Btw, I really love when a manual is needed. And sarcarsm always works well on forums.

 

 

 

Cheers,

Eirik