Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 类型为';的未处理异常;Microsoft.Practices.Unity.ResolutionFailedException';发生在Microsoft.Practices.Unity.dll中_C# - Fatal编程技术网

C# 类型为';的未处理异常;Microsoft.Practices.Unity.ResolutionFailedException';发生在Microsoft.Practices.Unity.dll中

C# 类型为';的未处理异常;Microsoft.Practices.Unity.ResolutionFailedException';发生在Microsoft.Practices.Unity.dll中,c#,C#,不知是否有人能帮我? 我从一个不在这里的开发人员那里得到了一个项目,我需要重建他的一个应用程序 应用程序将成功生成,但如果我尝试运行它,则会出现以下错误: 类型的未处理异常 中出现“Microsoft.Practices.Unity.ResolutionFailedException” Microsoft.Practices.Unity.dll 其他信息:依赖项解析失败,类型= “App.MainForm”,name=“(无)” 程序在此行中断: _mainForm = container.Re

不知是否有人能帮我? 我从一个不在这里的开发人员那里得到了一个项目,我需要重建他的一个应用程序

应用程序将成功生成,但如果我尝试运行它,则会出现以下错误:

类型的未处理异常 中出现“Microsoft.Practices.Unity.ResolutionFailedException” Microsoft.Practices.Unity.dll

其他信息:依赖项解析失败,类型= “App.MainForm”,name=“(无)”

程序在此行中断:

_mainForm = container.Resolve<MainForm>();
\u mainForm=container.Resolve();
我拥有的全部代码如下:

    namespace Refunds
{
    internal class RefundApplicationContext : ApplicationContext
    {
        private TerritoryForm _territoryForm;
        private MainForm _mainForm;
        private IRefundProcessorConfig _config;

        public RefundApplicationContext()
        {
            using (IUnityContainer container = new UnityContainer())
            using (ContainerControlledLifetimeManager manager = new ContainerControlledLifetimeManager())
            {
                container
                    .AddNewExtension<BuildTracking>()
                    .AddNewExtension<LogCreation>()
                    .RegisterType<MainForm>()
                    .RegisterType<IRefundProcessor, RefundProcessor>()
                    .RegisterType<IRefundCollection, RefundCollection>()
                    .RegisterType<ISepaValidation, SepaValidation>()
                    .RegisterType<IBankValidationConfig, BankValidationConfig>()
                    .RegisterType<IBankValidation, BankValidation>()
                    .RegisterType<IRefundProcessorConfig, RefundProcessorConfig>(manager)
                    .RegisterType<ISalesLedgerBrokerFacade, SalesLedgerBrokerFacade>()
                    .RegisterType<IPurchaseLedgerRestClientHelper, PurchaseLedgerRestClientHelper>()
                    .RegisterType<ISystemKeyRestClientHelper, SystemKeyRestClientHelper>()
                    .RegisterType<ISepaRestClientHelper, SepaRestClientHelper>()
                    .RegisterType<IPaymentHelper, PaymentHelper>()
                    .RegisterType<IPdfDocument, PdfDocument>()
                    .RegisterType<IStringCipher, StringCipher>()
                    .RegisterType<IRefundFactory, RefundFactory>()
                    .RegisterType<IFileHelperEngine<Refunds.Implementation.Csv.Refund>, FileHelperEngine<Refunds.Implementation.Csv.Refund>>(new InjectionConstructor())
                    .RegisterType<IDirectDebitBusinessServiceFacade, DirectDebitBusinessServiceFacade>();

                _territoryForm = container.Resolve<TerritoryForm>();
                _mainForm = container.Resolve<MainForm>();
                _config = container.Resolve<IRefundProcessorConfig>();
            }


            _territoryForm.FormClosed += new FormClosedEventHandler(_territoryForm_FormClosed);
            _mainForm.FormClosed += new FormClosedEventHandler(_mainForm_FormClosed);

            _territoryForm.Show();

            _mainForm.Show();
        }

        private void _territoryForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (_territoryForm.DialogResult == DialogResult.OK)
            {
                _config.Territory = _territoryForm.Territory;

                _mainForm.Show();
            }
            else
                ExitThread();
        }

        private void _mainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            ExitThread();
        }
    }
}
名称空间退款
{
内部类:ApplicationContext:ApplicationContext
{
私人地域形式(u TerritoryForm);;
私有主窗体_MainForm;
专用IRefundProcessorConfig\u配置;
公共应用程序上下文()
{
使用(IUnityContainer container=new UnityContainer())
使用(ContainerControlledLifetimeManager=new ContainerControlledLifetimeManager())
{
容器
.AddNewExtension()
.AddNewExtension()
.RegisterType()
.RegisterType()
.RegisterType()
.RegisterType()
.RegisterType()
.RegisterType()
.RegisterType(管理器)
.RegisterType()
.RegisterType()
.RegisterType()
.RegisterType()
.RegisterType()
.RegisterType()
.RegisterType()
.RegisterType()
.RegisterType(新注入构造函数())
.RegisterType();
_territoryForm=container.Resolve();
_mainForm=container.Resolve();
_config=container.Resolve();
}
_territoryForm.FormClosed+=新FormClosedEventHandler(\u territoryForm\u FormClosed);
_mainForm.FormClosed+=新的FormClosedEventHandler(\u mainForm\u FormClosed);
_territoryForm.Show();
_mainForm.Show();
}
私有void\u territoryForm\u FormClosed(对象发送方,FormClosedEventArgs e)
{
if(_territoryForm.DialogResult==DialogResult.OK)
{
_config.Territory=\u territoryForm.Territory;
_mainForm.Show();
}
其他的
ExitThread();
}
私有void\u mainForm\u FormClosed(对象发送方,FormClosedEventArgs e)
{
ExitThread();
}
}
}

只是猜测而已,但MainForm()是否有空构造函数?仔细看我们看不到的代码,“MainForm”很特别,因为它应该只有一个实例。你通过使构造函数私有来实现的那种东西。我已经在帖子中添加了所有的代码,这样你就可以看到所有的东西。我希望这有帮助。