빌드 시에 정상 작동되는 프로그램이 Publish를 하게 되면 문제가 생깁니다.

빌드 시에는 정상적으로 작동하고 문제 없이 실행이 됩니다.
Bin 폴더 안에 있는 exe를 실행해도 동작하고요

현재 환경으로는
.net core 3.1 을 사용하고 있으며 서브 모듈로
.net standard 2.0 프로젝트를 프로젝트 참조로 하여 사용하고 있습니다.

오류 메세지로는

Exception has been thrown by the target of an invocation.

라고 나오게 되며 예외의 StackTrace를 찍어 보았을 때
다른 프로젝트의 메서드들이 뜨는 것으로 보아 프로젝트 참조 쪽에 문제가 있는 것으로 보입니다.

.pdb 파일을 생성하지 않고 publish 할 때와 .pdb 파일을 생성하고 publish 할 때 등
다양한 빌드 상황으로 테스트 해보아도 동일한 증상이 나타납니다.

어떻게 해결 할 수 있을까요?
추가적인 정보가 필요하다면 댓글로 작성하겠습니다. 감사합니다.

2개의 좋아요

그 stack trace를 올려보시면 도움이 되지 않을까 합니다.

2개의 좋아요

확실히 크래쉬로 인해 프로그램이 죽었다면 윈도우즈의 이벤트에 기록에 남습니다.
여기 들어가서 로그 찾아보면 2개가 찍혀있을텐데 그 중 하나에 Stacktrace를 포함한 Exception 정보가 들어있습니다.

윈도우 키 누르신 다음 “이벤트 뷰어”로 검색해서 확인해보시겠어요?

3개의 좋아요

답변 늦어서 죄송합니다.
Stack trace 로그는 프로젝트 명 등을 바꿔서 내보내었습니다.

프로그램에서 반환 된 StackTrace
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& hasNoDefaultCtor)
   at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
   at System.Activator.CreateInstance[T]()
   at CoreProject.Component.ComponentsContainer.AddComponent[T]()
   at CoreProject.Component.Component.AddComponent[T]()
   at Project.MainComponent.A.AComponent.OnStart()
   at CoreProject.Component.ComponentsContainer.Attach(Component pComponent)
   at CoreProject.Component.ComponentsContainer.AddComponent[T]()
   at CoreProject.Component.Component.AddComponent[T]()
   at Project.MainComponent.MainOPComponent.OnStart()
   at CoreProject.Component.ComponentsContainer.Attach(Component pComponent)
   at CoreProject.Component.ComponentsContainer.AddComponent[T]()
   at CoreProject.Component.Component.AddComponent[T]()
   at Project.Components.AComponent.OnStart()
   at CoreProject.Component.ComponentsContainer.Attach(Component pComponent)
   at CoreProject.Component.ComponentsContainer.AddComponent[T]()
   at Project.MainWindow..ctor()

Project가 .Net core 3.1을 기반으로 하는 WPF 메인 프로젝트이고
CoreProject가 .NetStandard 2.0을 기반으로 하는 클래스 라이브러리 프로젝트입니다.

@level120 님이 말씀해 주신 이벤트 뷰어로 확인해 본 결과 매우 긴 StackTrace가 있었는데요

이벤트 뷰어 StackTrace
Application: Project.exe
CoreCLR Version: 4.700.19.56402
.NET Core Version: 3.1.0
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at GMap.NET.MapProviders.MBTilesMapProvider..ctor(String dbpath)
   at Project.Components.AMap.AMapComponent..ctor()
   --- End of inner exception stack trace ---
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& hasNoDefaultCtor)
   at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
   at System.Activator.CreateInstance[T]()
   at CoreProject.Component.ComponentsContainer.AddComponent[T]()
   at CoreProject.Component.Component.AddComponent[T]()
   at Project.MainComponent.A.AComponent.OnStart()
   at CoreProject.Component.ComponentsContainer.Attach(Component pComponent)
   at CoreProject.Component.ComponentsContainer.AddComponent[T]()
   at CoreProject.Component.Component.AddComponent[T]()
   at Project.MainComponent.MainOPComponent.OnStart()
   at CoreProject.Component.ComponentsContainer.Attach(Component pComponent)
   at CoreProject.Component.ComponentsContainer.AddComponent[T]()
   at CoreProject.Component.Component.AddComponent[T]()
   at Project.Components.BAComponent.OnStart()
   at CoreProject.Component.ComponentsContainer.Attach(Component pComponent)
   at CoreProject.Component.ComponentsContainer.AddComponent[T]()
   at Project.MainWindow..ctor()
   --- End of inner exception stack trace ---
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& hasNoDefaultCtor)
   at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, Object[] args)
   at System.Xaml.Schema.SafeReflectionInvoker.CreateInstanceCritical(Type type, Object[] arguments)
   at System.Xaml.Schema.XamlTypeInvoker.CreateInstance(Object[] arguments)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstanceWithCtor(XamlType xamlType, Object[] args)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(XamlType xamlType, Object[] args)
   at System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx)
   at System.Xaml.XamlObjectWriter.WriteStartMember(XamlMember property)
   at System.Xaml.XamlWriter.WriteNode(XamlReader reader)
   at System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector)
   at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
   at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
   at System.Windows.Application.DoStartup()
   at System.Windows.Application.<.ctor>b__1_0(Object unused)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run()
   at Project.App.Main()

또한 또 다른 오류에서 KERNELBASE.dll의 오류라고 나와있어 이것이 의심 됩니다.
컴퓨터에서 지워졌다거나 하는 문제는 아닌것으로 확인 되었고
현재는 인터넷에서 검색으로 KERNELBASE 관련을 조사하고 있습니다.

2개의 좋아요
Exception Info: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at GMap.NET.MapProviders.MBTilesMapProvider..ctor(String dbpath)
   at Project.Components.AMap.AMapComponent..ctor()
   --- End of inner exception stack trace ---
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& hasNoDefaultCtor)
   at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
   at System.Activator.CreateInstance[T]()
   at CoreProject.Component.ComponentsContainer.AddComponent[T]()

여기 올려주신 로그를 보면
CoreProject.Component 위치에서 ComponentsContainer에 컴포넌트를 추가할 때 GMap.NET 라이브러리를 못 만들어서 죽어버린 것 같아요.
순서가 잘못되었거나 GMap.NET으로 사용하는 컴포넌트를 올바르게 사용하고 있는지 보셔야 할 것 같아요.

그래도 오류가 계속되거나 못 찾겠다면 GMap.NET쪽에 문의해보셔야 할 것 같습니다.

3개의 좋아요

아하! 넵 알겠습니다. 감사합니다!

1개의 좋아요