1

我有一个关于 Microsoft.Practices.Unity.ResolutionFailedException 的问题。

如果我手动启动,它工作正常。

但是当我尝试通过 Windows 任务调度程序启动时,

它说

'ResolutionFailedException 未处理'

依赖项解析失败,type = "MainPresenter",name = "(none)"。发生异常时:调用构造函数 XX.Main()。例外是:FormatException - 输入字符串的格式不正确。

这是我的代码:

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
using (IUnityContainer container = new UnityContainer())
{
  container.RegisterType<IMainView, Main>();
  MainPresenter presenter = container.Resolve<MainPresenter>();
  Application.Run((Form)presenter.View);
}

主要代码:

public partial class Main : Form, IMainView
{
    public Main()
    {
    }
}

IMainView 代码:

public interface IMainView
{
}

MainPresenter 代码:

public class MainPresenter
{
    public MainPresenter( IMainView view )
    {
        this.view = view;
    }
    public IMainView View
    {
        get { return view; }
    }
    private readonly IMainView view;
}

程序代码:

static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        /// 

        [STAThread]
        static void Main()
        {

            bool bNew;
            Mutex mutex = new Mutex(true, "XX", out bNew);

            if (bNew)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                using (IUnityContainer container = new UnityContainer())
                {
                    container.RegisterType<IMainView, Main>();
                    MainPresenter presenter = container.Resolve<MainPresenter>();
                    Application.Run((Form)presenter.View);
                }
            }
            else
            {
                Application.Exit();
            }
        }
    }

谢谢。

4

0 回答 0