내 프로그램이 충돌하지 않고 실행 되려면 "코드 최적화"를 켜야하는 이유는 무엇입니까?

StackOverflow https://stackoverflow.com/questions/2068482

문제

이 WPF 응용 프로그램이 제공되었는데, 디버그 모드에서 프로그램을 실행하려고 할 때 Windows1.xml로 이동하기 전에 충돌이 발생했습니다. 나중에 릴리스 모드에서 실행을 시도했는데 성공적으로 실행되었습니다. 나는 그것을 좁혔다. 나는 그것이 작동하기 위해 "최적화 코드"를 켜야했다.

참고 : 브레이크 포인트, 디버그에서 물러나서 던지기 예외를 중지하는 것은 작동하지 않습니다.

편집하다: 예외는 WPF (매우 인기 있고 도움이되지 않음) 일반적인 예외였습니다.

{ "어셈블리에 정의 된 '메인'의 인스턴스를 생성 할 수 없음 'vcell2, version = 1.0.0.0, culture = neutral, publickeyToken = null'. 호출 대상에 의해 예외가 발생했습니다. 마크 업 파일의 오류 'Window1.xaml'. 라인 1 위치 9. "} 소스 = "PresentationFramework"LineNumber = 1 LinePosition = 9

편집하다: 내부 - 내부 예외 : { "지정된 모듈을 찾을 수 없습니다. (hresult의 예외 : 0x8007007e) : null}

여기에 내가 얻는 스택 추적이있었습니다.

   at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
   at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException)
   at System.Windows.Markup.BamlRecordReader.ThrowExceptionWithLine(String message, Exception innerException)
   at System.Windows.Markup.BamlRecordReader.CreateInstanceFromType(Type type, Int16 typeId, Boolean throwOnFail)
   at System.Windows.Markup.BamlRecordReader.GetElementAndFlags(BamlElementStartRecord bamlElementStartRecord, Object& element, ReaderFlags& flags, Type& delayCreatedType, Int16& delayCreatedTypeId)
   at System.Windows.Markup.BamlRecordReader.BaseReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
   at System.Windows.Markup.BamlRecordReader.ReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
   at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
   at System.Windows.Markup.BamlRecordReader.Read(Boolean singleRecord)
   at System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment()
   at System.Windows.Markup.TreeBuilder.Parse()
   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__0(Object unused)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext 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, Boolean isSingleParameter)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
   at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
   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(Window window)
   at System.Windows.Application.Run()
   at VCell2.App.Main() in C:\Users\wandrus\Documents\Visual Studio 2008\Projects\VCell2\VCell2\obj\Debug\App.g.cs:line 0

편집하다 나는 그것을 실행하려고 시도했다.

ModLoad: 77310000 773b0000   C:\Windows\system32\ADVAPI32.dll
ModLoad: 76a30000 76adc000   C:\Windows\system32\msvcrt.dll
ModLoad: 76c60000 76c79000   C:\Windows\SYSTEM32\sechost.dll
ModLoad: 76ae0000 76b82000   C:\Windows\system32\RPCRT4.dll
ModLoad: 770c0000 77117000   C:\Windows\system32\SHLWAPI.dll
ModLoad: 76940000 7698e000   C:\Windows\system32\GDI32.dll
ModLoad: 76c80000 76d49000   C:\Windows\system32\USER32.dll
ModLoad: 778e0000 778ea000   C:\Windows\system32\LPK.dll
ModLoad: 77120000 771bd000   C:\Windows\system32\USP10.dll
ModLoad: 76ea0000 76ebf000   C:\Windows\system32\IMM32.DLL
ModLoad: 76b90000 76c5c000   C:\Windows\system32\MSCTF.dll
ModLoad: 6c1b0000 6c1b5000   C:\Windows\system32\avgrsstx.dll
ModLoad: 57310000 578a1000   C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
ModLoad: 756a0000 7573b000   C:\Windows\WinSxS\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.4918_none_d089094c442eb5ff\MSVCR80.dll
ModLoad: 75c40000 76886000   C:\Windows\system32\shell32.dll
ModLoad: 773c0000 7751b000   C:\Windows\system32\ole32.dll
ModLoad: 75810000 7581b000   C:\Windows\system32\profapi.dll
ModLoad: 53de0000 548d8000   C:\Windows\assembly\NativeImages_v2.0.50727_32\mscorlib\70603943245265de9397091048337dda\mscorlib.ni.dll
ModLoad: 757a0000 757ac000   C:\Windows\system32\CRYPTBASE.dll
ModLoad: 744f0000 74530000   C:\Windows\system32\uxtheme.dll
ModLoad: 52ea0000 53639000   C:\Windows\assembly\NativeImages_v2.0.50727_32\System\ade9214f5bce88462742bce1278864c0\System.ni.dll
ModLoad: 57ae0000 57e0c000   C:\Windows\assembly\NativeImages_v2.0.50727_32\WindowsBase\c7663f3a74fb6aa480c60108634d285a\WindowsBase.ni.dll
ModLoad: 03eb0000 04a5b000   C:\Windows\assembly\NativeImages_v2.0.50727_32\PresentationCore\c79b7f336e6099b8c94081f975e9411e\PresentationCore.ni.dll
ModLoad: 55240000 55fec000   C:\Windows\assembly\NativeImages_v2.0.50727_32\PresentationFramewo#\7d80b7d912fbf0f7532f1b9adc235646\PresentationFramework.ni.dll
ModLoad: 00e50000 01255000   PresentationCore.dll
ModLoad: 00e50000 01255000   PresentationCore.dll
ModLoad: 539d0000 53b7c000   C:\Windows\Microsoft.NET\Framework\v3.0\WPF\wpfgfx_v0300.dll
ModLoad: 76990000 76a1f000   C:\Windows\system32\OLEAUT32.dll
ModLoad: 51520000 51754000   C:\Windows\assembly\NativeImages_v2.0.50727_32\System.Core\e78709bedd31f237055667ad99b9451f\System.Core.ni.dll
ModLoad: 6cbc0000 6cc1b000   C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll
ModLoad: 637d0000 638c1000   C:\Windows\assembly\NativeImages_v2.0.50727_32\System.Configuration\9c2727d244dcc72fbefcf1ae22660f35\System.Configuration.ni.dll
ModLoad: 57f20000 58456000   C:\Windows\assembly\NativeImages_v2.0.50727_32\System.Xml\93d38ea87365928456313035f8091126\System.Xml.ni.dll
ModLoad: 74130000 74143000   C:\Windows\system32\dwmapi.dll
ModLoad: 60340000 60348000   C:\Windows\Microsoft.NET\Framework\v2.0.50727\culture.dll
(1e2c.738): C++ EH exception - code e06d7363 (first chance)
(1e2c.738): C++ EH exception - code e06d7363 (first chance)
(1e2c.738): C++ EH exception - code e06d7363 (first chance)
(1e2c.738): C++ EH exception - code e06d7363 (first chance)
(1e2c.738): C++ EH exception - code e06d7363 (first chance)
(1e2c.738): C++ EH exception - code e06d7363 (first chance)
(1e2c.738): C++ EH exception - code e06d7363 (first chance)
(1e2c.738): CLR exception - code e0434f4d (first chance)
(1e2c.738): C++ EH exception - code e06d7363 (first chance)
(1e2c.738): CLR exception - code e0434f4d (first chance)
(1e2c.738): CLR exception - code e0434f4d (first chance)
(1e2c.738): CLR exception - code e0434f4d (first chance)
(1e2c.738): CLR exception - code e0434f4d (!!! second chance !!!)
eax=0025e034 ebx=e0434f4d ecx=00000001 edx=00000000 esi=0025e0bc edi=002d66d8
eip=75acb4f4 esp=0025e034 ebp=0025e084 iopl=0         nv up ei pl nz ac po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000212
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\Windows\system32\KERNELBASE.dll - 
KERNELBASE!RaiseException+0x54:
75acb4f4 c9              leave
도움이 되었습니까?

해결책

더 많은 정보를 제공해야합니다. 예외는 무엇입니까? 런타임에 유형을 참조 할 수없는 유형이 참조 될 수 있습니다. 코드를 사용하지 않으면 Optimizer는 JIT에서 생략 할 수 있지만 디버그 모드에서는 유형로드 예외를 트리거 할 수 있습니다. 그래도 누가 알 겠어요. 더 많은 정보가 없으면 말할 수 없습니다.

편집하다 질문의 업데이트에 대한 응답으로 인스턴스 생성자 또는 정적 생성자에서 예외를 던지는 메인이라는 유형이있는 것 같습니다. 이것을 트리거하는 필드 이니셜 라이저 일 수도 있습니다. 예외를 포착 할 수있는 경우 TargetInvocationExceptions에 일반적으로 포함 된 Innerexception을 확인하십시오. 이것은 당신에게 더 많은 정보를 줄 것입니다.

편집하다 내부 예외는 처음에 내가 생각한 어셈블리 로딩 문제임을 나타 냈습니다. 그래서 당신은 어딘가에 참조를 놓치고 있습니다. 특히, 당신은 아마도 찾을 수없는 다른 dll을 참조하는 dll을 참조하고있을 것입니다. 어떤 어셈블리를 해결할 수 없는지 알아 내야합니다. 당신은 사용할 수 있습니다 fuslogvw.exe 어셈블리 바인딩 오류를 볼 수있는 도구.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top