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 또는 컴퓨터 설정의 사본이 있어야합니다. 다른 버전의 프로그램을 실행하고, 재부팅하고, 백업에서 프로그램을 복원하는 등의 작업을 시도하지 않았습니다.
아무도 아이디어가 있습니까? 감사.
'TypeInitiializationException'은 정적 생성자 또는 정적 필드 초기화에 실패했음을 의미합니다. 이유를 찾으려면 코드를 디버깅해야합니다. –