문제

이 xamlparseexception은 나를 미치게합니다 !! Visual Studio 1020에서 .NET 3.5를 사용하고 있습니다. 이것은 내 XAML입니다.

<Window x:Class="WinformsHost.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Advanced Notepad" Height="350" Width="525" Loaded="Window_Loaded">
<DockPanel>
    <Menu DockPanel.Dock="Top">

        <MenuItem Header="File">
            <MenuItem Header="_New" />
            <MenuItem Header="_Open..." />
            <MenuItem Header="_Save" />
            <MenuItem Header="S_ave As..." />
            <Separator />
            <MenuItem Header="Page Setup" />
            <MenuItem Header="Print" />
            <Separator />
            <MenuItem Header="Exit" />
        </MenuItem>

        <MenuItem Header="Edit">
            <MenuItem Header="Undo" />
            <MenuItem Header="Redo" />
            <Separator />
            <MenuItem Header="Cut" />
            <MenuItem Header="Copy" />
            <MenuItem Header="Paste" />
            <MenuItem Header="Delete"  />
            <Separator />
            <MenuItem Header="Time/Date" />
            <Separator />
            <MenuItem Header="Preferences" />
        </MenuItem>

        <MenuItem Header="Format">
            <MenuItem Header="Word Wrap" IsCheckable="True" />
            <MenuItem Header="Font..." />
        </MenuItem>

        <MenuItem Header="View">
            <MenuItem Header="Status Bar" IsCheckable="True" />
        </MenuItem>

        <MenuItem Header="Language">
            <RadioButton x:Name="rbtCmake" Checked="rbtCmake_Checked" Content="Cmake" />
            <RadioButton x:Name="rbtCSharp" Content="C#" />
            <RadioButton x:Name="rbtHTML" Content="HTML" />
            <RadioButton x:Name="rbtPython" Content="Python" />
            <Separator />
            <RadioButton x:Name="rbtText" IsChecked="True" Content="Text" />
        </MenuItem>

        <MenuItem Header="Help">
            <MenuItem Header="View Help" />
            <Separator />
            <MenuItem Header="About Notepad" />
        </MenuItem>

    </Menu>
    <StatusBar x:Name="stbStatus" DockPanel.Dock="Bottom" Visibility="Collapsed">
        <TextBlock x:Name="txtStatus" Text="Status" />
    </StatusBar>
</DockPanel>
</Window>

그렇다면 다시 내 코드일까요? 예외는 다음과 같습니다.
System.Windows.Markup.XamlParseException was unhandled Message=Cannot create instance of 'MainWindow' defined in assembly 'Notepad, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'MainWindow.xaml' Line 1 Position 9. Source=PresentationFramework LineNumber=1 LinePosition=9 StackTrace: 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 WinformsHost.App.Main() in C:\Users\Mohit\Documents\Visual Studio 2010\Projects\Notepad\Notepad\obj\x86\Debug\App.g.cs:line 0 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: System.Reflection.TargetInvocationException Message=Exception has been thrown by the target of an invocation. Source=mscorlib StackTrace: at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Windows.Markup.BamlRecordReader.CreateInstanceFromType(Type type, Int16 typeId, Boolean throwOnFail) InnerException: NLog.Config.NLogConfigurationException Message=Exception occured when loading configuration from 'C:\Users\Mohit\Documents\Visual Studio 2010\Projects\Notepad\Notepad\bin\Debug\NLog.config' Source=NLog StackTrace: at NLog.Config.XmlLoggingConfiguration..ctor(String fileName, Boolean ignoreErrors) at NLog.Config.XmlLoggingConfiguration..ctor(String fileName) at NLog.LogFactory.get_Configuration() at NLog.LogFactory.GetLogger(LoggerCacheKey cacheKey) at NLog.LogFactory.GetLogger(String name) at NLog.LogManager.GetCurrentClassLogger() at WinformsHost.MainWindow..ctor() in C:\Users\Mohit\Documents\Visual Studio 2010\Projects\Notepad\Notepad\MainWindow.xaml.cs:line 15 InnerException: NLog.Config.NLogConfigurationException Message=Target console not found. Source=NLog StackTrace: at NLog.Config.XmlLoggingConfiguration.ConfigureRulesFromElement(LoggingConfiguration config, LoggingRuleCollection rules, XmlElement element) at NLog.Config.XmlLoggingConfiguration.ConfigureFromXmlElement(XmlElement configElement, String baseDirectory) at NLog.Config.XmlLoggingConfiguration.ConfigureFromFile(String fileName) at NLog.Config.XmlLoggingConfiguration..ctor(String fileName, Boolean ignoreErrors) InnerException:

도움이 되었습니까?

해결책

나는 이것이 실제로 xamlparseexception에 싸인 TargetInvocationException이라고 생각하지 않습니다. 궁극적 인 내부 예외를 살펴보십시오.

nlog.config.nlogconfigurationException 메시지 = 예외는 'c : user mohit documents Visual Studio 2010 notepad notepad bin debug nlog.config'에서 구성을로드 할 때 발생합니다.

유효하지 않은 XML 또는 좀 더 구체적인 이유 때문에 Borked 구성 파일이있는 것 같습니다.

신비한 xamlparseexception을 얻을 때입니다 언제나 TargetInvocationException의 innerexception을 확인하는 것이 좋습니다 (및 하나가있는 경우 드릴링). 예, 매우 혼란스럽고 오도합니다!

다른 팁

나는 이것이 오래된 질문이라는 것을 알고 있지만 희망적으로 이것은 누군가에게 도움이 될 것입니다.

비즈니스 객체 인 메인 창의 속성이있었습니다. 따라서 창이 초기화되면 비즈니스 객체가 초기화하려고 시도했지만 데이터 액세스 계층이 설정되지 않았으므로 오류가 발생했습니다. .

그래서 C#은 너무 일찍 발생했기 때문에 XML 구문 분석 오류라고 불렀습니다. 실제로 코드에 던져졌습니다.

EXE 파일과 동일한 폴더에 참조 된 DLL 및 구성 파일을 포함하여 동일한 문제를 해결했습니다. EXE를 단독으로 실행하려고하면 Windows 레벨 예외가 발생합니다.

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