2016-11-05 6 views
0

2 개의 C# 프로젝트가 서로 참조해야하는 경우가 있습니다. 따라서 어셈블리 A는 어셈블리 B를 참조합니다. 어셈블리 B는 리플렉션을 사용하여 A를로드합니다. 명령 행 응용 프로그램에서 훌륭하게 작동합니다. 실행중인 어셈블리를로드 할 수 없습니다.

그러나 내 말 COM 추가 기능에서 나는 다음과 같은 오류가 점점 오전

:

Could not load file or assembly 'WindwardReports, Version=15.0.142.0, Culture=neutral, 
PublicKeyToken=34ffe15f4bbb8e53' or one of its dependencies. 
The system cannot find the file specified. 

FusionLog 

=== Pre-bind state information === 
LOG: DisplayName = WindwardReports, Version=15.0.142.0, Culture=neutral, PublicKeyToken=34ffe15f4bbb8e53 (Fully-specified) 
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Office/Root/Office16/ 
LOG: Initial PrivatePath = NULL Calling assembly : (Unknown). 
=== 
LOG: This bind starts in default load context. 
LOG: Using application configuration file: C:\\Program Files (x86)\\Microsoft Office\\Root\\Office16\\WINWORD.EXE.Config 
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\config\\machine.config. 
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Office/Root/Office16/WindwardReports.DLL. 
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Office/Root/Office16/WindwardReports/WindwardReports.DLL. 
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Office/Root/Office16/WindwardReports.EXE. 
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Office/Root/Office16/WindwardReports/WindwardReports.EXE. 

이 같은 코드는 명령 줄 응용 프로그램에서 잘 작동합니다.

코드 : 다음은 코드입니다. (이 구문은 IKVM을 사용하여 .NET으로 바뀌었지만 실행중인 .NET 코드이므로 Java 코드이므로 약간 이상합니다.)

cli.System.Reflection.Assembly assm; 
    int indexSemi = outputBuilder.indexOf(';'); 
    if (indexSemi != -1) { 
     String dllFilename = outputBuilder.substring (0, indexSemi); 
     outputBuilder = outputBuilder.substring(indexSemi + 1); 
     assm = cli.System.Reflection.Assembly.LoadFile(dllFilename); 
    } 
    else 
     assm = cli.System.Reflection.Assembly.GetExecutingAssembly(); 

    cli.System.Runtime.Remoting.ObjectHandle hdl = cli.System.Activator.CreateInstance(assm.get_FullName(), outputBuilder); 
    return (IOutputBuilderEngine) hdl.Unwrap(); 

System.Activator.CreateInstance()는 예외를 발생시키는 것입니다.

+0

코드를 게시 할 수 있습니까? – Aruna

+0

@Aruna - 죄송합니다. 시작했을 때해야했습니다. 지금 거기. –

+0

어셈블리 (A와 B 모두)는 어떻게 배치됩니까? 파일 시스템에 상주해야 할 위치는 무엇입니까? LoadFile 메서드에 대한 전체 경로를 전달하고 있습니까? – cynic

답변

0

코드가 파일에서 DLL을로드하려고합니다.

당신이 융합 로그에서 볼 수 있듯이

, 그 다음에 포기, 4 개소에 DLL을 찾고 :

  1. C :/프로그램 파일 (x 86)/마이크로 소프트 오피스/루트/Office16는/WindwardReports합니다. DLL
  2. C :/프로그램 파일 (x 86)/마이크로 소프트 오피스/루트/Office16/WindwardReports/WindwardReports.DLL
  3. C :/프로그램 파일 (x 86)/마이크로 소프트 오피스/루트/Office16/WindwardReports.EXE
  4. C :/프로그램 파일 (x86)/Microsoft Office/Root/Office16/WindwardReports/WindwardReports.EXE

DLL과 비슷한 것으로 보입니다. 실제로 디스크에서로드해야하는 경우 올바른 경로가 필요합니다. 실행 어셈블리 인 경우에도 왜 'Assembly.GetExecutingAssembly()을 사용할 수 있습니까?

+0

OfficeOutputBuilder.dll을로드하려고하는 WindwardReports.dll에서 실행 중입니다. 하지만 왜 내가 실행중인 DLL을 찾고 있습니까? –

+0

알 수있는 코드가 충분하지 않습니다. 'outputBuilder'의 값을 조사하십시오. 잘못된 DLL 이름이 들어있는 것 같습니다. –

관련 문제