This documentation is archived and is not being maintained.

Compiler Error CS1708 

Error Message

Fixed size buffers can only be accessed through locals or fields

A new feature in C# 2.0 is the ability to define an in-line array inside of a struct. Such arrays can only be accessed via local variables or fields, and may not be referenced as intermediate values on the left-hand side of an expression. Also, the arrays cannot be accessed by fields that are static or readonly.

To resolve this error, define an array variable, and assign the in-line array to the variable. Or, remove the static or readonly modifier from the field representing the in-line array.

Example

The following sample generates CS1708.

// CS1708.cs
// compile with: /unsafe
using System;

unsafe public struct Foo
{
    public fixed char name[10];
}

public unsafe class C
{
    public Foo UnsafeMethod()
    {
        Foo myFoo = new Foo();
        return myFoo;
    }

    static void Main()
    {
        C myC = new C();
        myC.UnsafeMethod().name[3] = 'a';  // CS1708
        // Uncomment the following 2 lines to resolve:
        // Foo myFoo = myC.UnsafeMethod();
        // myFoo.name[3] = 'a';

        // The field cannot be static.
        C._foo1.name[3] = 'a';  // CS1708

        // The field cannot be readonly.
        myC._foo2.name[3] = 'a';  // CS1708
    }

    static readonly Foo _foo1;
    public readonly Foo _foo2;
}
Show: