0

我有一个奇怪的问题,在我的 App.xaml 中创建派生自 Caliburn.Micro.Autofac.AutofacBootstrapper 的类失败并出现构建错误:

XML 命名空间“clr-namespace:TestProject”中不存在标签“Bootstrapper”

但是,如果我只是在 App.xaml.cs 中创建引导程序,那么一切正常。

下面的代码显示了我可以做些什么来使事情正常进行。如果我取消注释 App.xaml 中的引导程序并注释掉 App.xaml.cs 中的引导程序,我会收到构建错误。

两者有什么不同?

Intellisense 对 App.xaml 中的引导程序很满意,我只在构建时收到错误消息。

这是我的 App.xaml

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:local="clr-namespace:TestProject"
         x:Class="TestProject.App"
         >
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary>
                <!--
                <local:Bootstrapper x:Key="Bootstrapper"/>
                -->
            </ResourceDictionary>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

这是我的 App.xaml.cs

namespace TestProject
{
    public partial class App : Application
    {

        public App()
        {
            new Bootstrapper();

            this.UnhandledException += this.Application_UnhandledException;

            InitializeComponent();
        }

        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
        {
            // If the app is running outside of the debugger then report the exception using
            // the browser's exception mechanism. On IE this will display it a yellow alert 
            // icon in the status bar and Firefox will display a script error.
            if (!System.Diagnostics.Debugger.IsAttached)
            {

                // NOTE: This will allow the application to continue running after an exception has been thrown
                // but not handled. 
                // For production applications this error handling should be replaced with something that will 
                // report the error to the website and stop the application.
                e.Handled = true;
                Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
            }
        }

        private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
        {
            try
            {
                string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
                errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");

                System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");
            }
            catch (Exception)
            {
            }
        }
    }
}

这是 Bootsteapper.cs

namespace TestProject
{
    public class Bootstrapper : AutofacBootstrapper<MainPageViewModel>
    {
        public Bootstrapper()
        {
            base.ConfigureBootstrapper();
            EnforceNamespaceConvention = false;
            ViewModelBaseType = typeof(IShell);
        }

        protected override void ConfigureContainer(Autofac.ContainerBuilder builder)
        {
            builder.RegisterType<MainPageViewModel>();

            base.ConfigureContainer(builder);
        }
    }
}
4

1 回答 1

0

您是否尝试将引导程序设置为 MergedDictionaries 之外?

<Application.Resources>
    <ResourceDictionary>
        <local:Bootstrapper x:Key="Bootstrapper" />
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Assembly;component/OtherResource.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>
于 2013-07-23T10:21:05.637 回答