컴파일러 오류 CS0765

업데이트: 2007년 11월

오류 메시지

정의 선언만 있는 부분 메서드(Partial Method) 또는 제거된 조건부 메서드는 식 트리에 사용할 수 없습니다.
Partial methods with only a defining declaration or removed conditional methods cannot be used in expression trees

제거된 부분 메서드에 대한 호출도 식이지만 식 트리에서 액세스할 수 있는 식이 아닙니다.

이 오류를 해결하려면

  • 부분 메서드에 대한 구현 선언을 추가하거나 컴파일에서 조건부 메서드를 제외시키는 코드를 제거합니다.

예제

다음 코드의 두 위치에서는 CS0765 오류가 발생하는 경우를 보여 줍니다.

// cs0765.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;

public delegate void dele();

public class ConClass
{
    [Conditional("CONDITION")]
    public static void TestMethod() { }
}

public partial class PartClass : IEnumerable
{
    List<object> list = new List<object>();

    partial void Add(int x);

    public IEnumerator GetEnumerator()
    {
        for (int i = 0; i < list.Count; i++)
            yield return list[i];
    }

    static void Main()
    {
        Expression<Func<PartClass>> testExpr1 = () => new PartClass { 1, 2 }; // CS0765
        Expression<dele> testExpr2 = () => ConClass.TestMethod(); // CS0765
    }
}

참고 항목

개념

식 트리

참조

Partial 클래스 및 메서드(C# 프로그래밍 가이드)