【问题标题】:Regarding Silverlight and prism关于 Silverlight 和 prism
【发布时间】:2011-11-16 10:24:28
【问题描述】:

我正在使用 silverlight5 和 prism4 开发示例。当我运行我的应用程序时,我得到了以下异常

“重写成员时违反了继承安全规则:'System.Exception.get_InnerException()'。重写方法的安全可访问性必须与被重写方法的安全可访问性相匹配。”

堆栈跟踪如下

在 System.ComponentModel.Composition.Hosting.ImportEngine.PartManager.TryOnComposed() 在 System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportsStateMachine(PartManager partManager,ComposablePart 部分) 在 System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImports(PartManager partManager,ComposablePart 部分,布尔 shouldTrackImports) 在 System.ComponentModel.Composition.Hosting.ImportEngine.SatisfyImports(ComposablePart 部分) 在 System.ComponentModel.Composition.Hosting.ComposablePartExportProvider.c_DisplayClass2.b_0() 在 System.ComponentModel.Composition.Hosting.CompositionServices.TryInvoke(动作动作) 在 System.ComponentModel.Composition.Hosting.ComposablePartExportProvider.Compose(CompositionBatch 批处理) 在 System.ComponentModel.Composition.Hosting.CompositionContainer.Compose(CompositionBatch 批处理) 在 System.ComponentModel.Composition.AttributedModelServices.ComposeExportedValue[T](CompositionContainer 容器,T 导出值) 在 Microsoft.Practices.Prism.MefExtensions.MefBootstrapper.RegisterBootstrapperProvidedTypes() 在 Microsoft.Practices.Prism.MefExtensions.MefBootstrapper.ConfigureContainer() 在 Microsoft.Practices.Prism.MefExtensions.MefBootstrapper.Run(布尔 runWithDefaultConfiguration) 在 Microsoft.Practices.Prism.Bootstrapper.Run() 在 Honeywell.CIU888.Shell.App.Application_Startup(对象发送者,StartupEventArgs e) 在 MS.Internal.CoreInvokeHandler.InvokeEventHandler(UInt32 typeIndex,委托 handlerDelegate,对象发送者,对象参数) 在 MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj,IntPtr unmanagedObjArgs,Int32 argsTypeIndex,Int32 actualArgsTypeIndex,字符串 eventName,UInt32 标志)

任何人都可以帮忙。

下面是我的代码,

BootStrapper.cs

public class BootStrapper : MefBootstrapper
{

    protected override void InitializeShell()
    {
        base.InitializeShell();

        Application.Current.RootVisual = (UIElement)Shell;
    }

    protected override DependencyObject  CreateShell()
    {
        return Container.GetExportedValue<MainPage>();           
    }                    

    protected override void ConfigureAggregateCatalog()
    {            
        base.ConfigureAggregateCatalog();

        AggregateCatalog.Catalogs.Add(new AssemblyCatalog(this.GetType().Assembly));                    
    }

    protected override IModuleCatalog CreateModuleCatalog()
    {

    }
}

app.xaml.cs

公共部分类应用程序:应用程序 {

    public App()
    {
        this.Startup += this.Application_Startup;
        this.Exit += this.Application_Exit;
        this.UnhandledException += this.Application_UnhandledException;

        InitializeComponent();
    }

    private void Application_Startup(object sender, StartupEventArgs e)
    {
        //this.RootVisual = new MainPage();
        (new BootStrapper()).Run();
    }

    private void Application_Exit(object sender, EventArgs e)
    {

    }

    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)
        {
        }
    }
}

如果我调用 bootsrapper.run(),就会出现上述异常。

我也在“在浏览器中运行时提升信任”模式下运行我的项目并签署了 xap 文件。

【问题讨论】:

    标签: silverlight prism


    【解决方案1】:

    "Security attributes need to be re-applied on types that derive from other types that also have security attributes"

    基本上,如果您从应用了安全属性的类派生(例如[SecurityCritical],则必须在任何覆盖成员/方法上重复这些属性。

    如果你能提供相关的代码会更容易解释,但你总是可以使用DotPeek 来检查基类的代码(如果你手边没有源代码),因为它会显示属性。

    【讨论】:

    • @Muthu:我注意到你所有的覆盖都是protected。您应该始终确保覆盖与父类相同,否则您可能会隐藏 Prism 需要公开访问的内容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-10
    • 2011-10-06
    • 1970-01-01
    • 1970-01-01
    • 2011-09-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多