2016-12-02 1 views
0

Visual Studio 15 .NET Framework 4.5.2에서 C# 프로그램을 실행하고 있습니다. AutoMapper 4.1.1을 사용합니다. 수년간 계속 달리고 있습니다. (나는 다른 누군가로부터 그것을 상속 받았다.) 최근에는 "AutoMappings.AutoMappings.CreateMaps();"라인에서 오류가 발생하기 시작했다. 다음은 관련 코드입니다.C# TypeInitiializationException

using System; 
using System.Windows.Forms; 
using IVGOffice.UserInterface; 
using System.Net; 
using System.Net.Security; 

namespace IVGOffice 
{ 
    static class Program 
    { 
     /// <summary> 
     /// The main entry point for the application. 
     /// </summary> 
     [STAThread] 
     static void Main() 
     { 
      // Assign certification callback to allow for self-signed certs on the services 
      ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(IVG.Common.Certificate.ValidateRemoteCertificate); 
      AutoMappings.AutoMappings.CreateMaps(); // <----- Errors out here 

내부 오류 "구성 시스템을 초기화하지 못했습니다."와 함께 System.TypeInitiializationException이 발생합니다. 그것은 결코 실제로 AutoMappings 클래스로 진입하지, 그래서 문제가 클래스에 관련되어 생각하지 않는다, 그러나 여기 어쨌든 그것의 시작에 :

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using IVG.Common; 
using IVG; 

namespace IVGOffice.AutoMappings 
{ 
    public static class AutoMappings 
    { 
     private static bool mapsCreated = false; 
     private static Utilities2.Services services = new Utilities2.Services(); 

     public static void CreateMaps() 
     { 
      // AutoMapper CreateMap should only be called once in an application domain. If we call this twice, check and just leave the second time 
      if (mapsCreated) 
       return; 

      // For every IAutomappedObject 
      System.Reflection.Assembly assm =  System.Reflection.Assembly.GetCallingAssembly(); 
      var interfaceTypes = assm.GetTypes(); 
      var automappedTypes = interfaceTypes.Where(type => typeof(IAutomappedObject).IsAssignableFrom(type) 
       && !type.IsAbstract 
       && !type.IsInterface); 
      foreach (var type in automappedTypes) 
       ... 

내 동료가 자신의 노트북과에서 동일한 코드를 실행하려고 잘 작동했기 때문에 Visual Studio 또는 컴퓨터 설정의 사본이 있어야합니다. 다른 버전의 프로그램을 실행하고, 재부팅하고, 백업에서 프로그램을 복원하는 등의 작업을 시도하지 않았습니다.

아무도 아이디어가 있습니까? 감사.

+0

'TypeInitiializationException'은 정적 생성자 또는 정적 필드 초기화에 실패했음을 의미합니다. 이유를 찾으려면 코드를 디버깅해야합니다. –

답변

0

내 app.config 파일의 configSections 앞에 appSettings를 배치했기 때문에 오늘 당장 치게되었습니다.

오류는 구성 파일에 잘못된 구문/레이아웃이 포함되어 있음을 나타낼 수 있습니다. 거기에서 수사를 시작하겠습니다.

0

구성에 문제가 있지만 app.config에 문제가 없습니다. 창 상태, 위치 및 크기를 저장하고 복원하는 코드를 추가했습니다. 이러한 설정은 새 user.config 파일에 저장되었습니다. 문제는 새로운 git repo에이 코드를 추가했다는 것입니다. 내 상사가 마스터 레포에 병합하기 전에 변경 사항을 승인해야했습니다. 그동안 나는 새 프로젝트를 시작하기 위해 주인에게 돌아갔다. 마스터에 새 코드가 없지만 새로운 user.config 파일이 아직 남아 있습니다. 웬일인지, 그것은 프로그램을 혼란시키는 것처럼 보인다. 상사가 마침내 새 코드를 병합하고 마스터 복사본을 업데이트하면 문제가 사라졌습니다. 귀하의 의견에 감사드립니다.