PreApplicationStartMethod 无法解析

PreApplicationStartMethod cannot be resolved

我尝试在 Web 应用程序中使用 Unity.Webforms 但没有成功。根据文档,我将以下行放在 AssemblyInfo.cs 中以告诉运行时在应用程序启动之前调用方法:

[assembly: PreApplicationStartMethod(typeof(Unity.WebForms.PreApplicationStart), "PreStart")]

我收到的错误是:

The method specified by the PreApplicationStartMethodAttribute on assembly ... cannot be resolved

这是 class 保存方法(在 App_Start 文件夹中):

using Microsoft.Web.Infrastructure.DynamicModuleHelper;
using System;
using System.Collections.Generic;
using System.Web;

namespace Unity.WebForms
{
    public static class PreApplicationStart
    {
        private static bool _isStarting;

        public static void PreStart()
        {
            if (!_isStarting)
            {
                _isStarting = true;
                DynamicModuleUtility.RegisterModule(typeof(UnityHttpModule));
            }
        }
    }
}

有什么我遗漏或误解的吗?

谢谢

使用 PreApplicationStart 在您的自定义文件中更改 Unity.Webforms 命名空间,因为该命名空间已经存在。

我的解决方案有效:

using Microsoft.Web.Infrastructure.DynamicModuleHelper;

namespace TestApp.WebUi
{
    public static class PreApplicationStart
    {
        private static bool _isStarting;

        public static void PreStart()
        {
            if (!_isStarting)
            {
                _isStarting = true;
                DynamicModuleUtility.RegisterModule(typeof(UnityHttpModule));
            }
        }
    }
}

并且:

[assembly: PreApplicationStartMethod(typeof(TestApp.WebUi.PreApplicationStart), "PreStart")]