다음을 통해 공유


방법: 파일이 어셈블리인지 확인(C# 및 Visual Basic)

파일은 관리되는 경우에만 어셈블리가 될 수 있으며 이 경우 해당 메타데이터에 어셈블리 엔트리가 들어 있어야 합니다. 어셈블리와 메타데이터에 대한 자세한 내용은 어셈블리 매니페스트 항목을 참조하십시오.

파일이 어셈블리인지 수동으로 확인하는 방법

  1. Ildasm.exe(IL 디스어셈블러)를 시작합니다.

  2. 테스트하려는 파일을 로드합니다.

  3. ILDASM에서 이 파일이 PE 파일(이식 가능한 실행 파일)이 아닌 것으로 보고되면 이 파일은 어셈블리가 아닙니다. 자세한 내용은 방법: 어셈블리 내용 보기 항목을 참조하십시오.

파일이 어셈블리인지 프로그래밍 방식으로 확인하는 방법

  1. 테스트하려는 파일의 전체 경로와 이름을 전달하여 GetAssemblyName 메서드를 호출합니다.

  2. BadImageFormatException 예외가 throw되면 파일이 어셈블리가 아닙니다.

예제

이 예제에서는 DLL이 어셈블리인지 여부를 확인하기 위한 테스트를 수행합니다.

Module Module1
    Sub Main()
        Try 
            Dim testAssembly As Reflection.AssemblyName =
                                Reflection.AssemblyName.GetAssemblyName("C:\Windows\Microsoft.NET\Framework\v3.5\System.Net.dll")
            Console.WriteLine("Yes, the file is an Assembly.")
        Catch ex As System.IO.FileNotFoundException
            Console.WriteLine("The file cannot be found.")
        Catch ex As System.BadImageFormatException
            Console.WriteLine("The file is not an Assembly.")
        Catch ex As System.IO.FileLoadException
            Console.WriteLine("The Assembly has already been loaded.")
        End Try
        Console.ReadLine()
    End Sub 
End Module 
' Output (with .NET Framework 3.5 installed): 
'        Yes, the file is an Assembly.
class TestAssembly
{
    static void Main()
    {

        try
        {
            System.Reflection.AssemblyName testAssembly =
                System.Reflection.AssemblyName.GetAssemblyName(@"C:\Windows\Microsoft.NET\Framework\v3.5\System.Net.dll");

            System.Console.WriteLine("Yes, the file is an assembly.");
        }

        catch (System.IO.FileNotFoundException)
        {
            System.Console.WriteLine("The file cannot be found.");
        }

        catch (System.BadImageFormatException)
        {
            System.Console.WriteLine("The file is not an assembly.");
        }

        catch (System.IO.FileLoadException)
        {
            System.Console.WriteLine("The assembly has already been loaded.");
        }
    }
}
/* Output (with .NET Framework 3.5 installed):
    Yes, the file is an assembly.
*/

GetAssemblyName 메서드는 테스트 파일을 로드하여 정보를 읽은 다음 이 파일을 해제합니다.

참고 항목

참조

AssemblyName

개념

C# 프로그래밍 가이드

어셈블리와 전역 어셈블리 캐시(C# 및 Visual Basic)

기타 리소스

Visual Basic 프로그래밍 가이드