Follow

What is CS1922?

Symptoms

When trying to enter play mode, I am receiving the error below:

error CS1922: A field or property `___' cannot be initialized with a collection object initializer because type `___' does not implement `___' interface

Cause

The CS1922 error is caused when a collection object initializer is used incorrectly. The collection object initializer can be used as a shorthand way of initializing multiple variables in the same line or assigning multiple values to an array at once.

In the following example we have recreated the CS1922 error by using the collection object initializer on a Vector3.

Errors displayed in this example:

error CS1922: A field or property `UnityEngine.Vector3' cannot be initialized with a collection object initializer because type `UnityEngine.Vector3' does not implement `System.Collections.IEnumerable' interface

Resolution

To fix the CS1922 error you will need to find the section of code that incorrectly uses the collection object initializer. Double clicking the error in the console can take you directly to the line of code that causes the error.

You will need to correct the code by altering it to avoid using the collection object initializer. In this example we have changed the curly braces for parentheses.

More Information

https://msdn.microsoft.com/en-us/library/bb384150(v=vs.90).aspx

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.