C# 无法解析PreApplicationStartMethod
我尝试在web应用程序中使用,但没有成功。根据文档,我在AssemblyInfo.cs中放置了以下行,以告知运行时在应用程序启动之前调用一个方法:C# 无法解析PreApplicationStartMethod,c#,asp.net,webforms,unity-container,C#,Asp.net,Webforms,Unity Container,我尝试在web应用程序中使用,但没有成功。根据文档,我在AssemblyInfo.cs中放置了以下行,以告知运行时在应用程序启动之前调用一个方法: [assembly: PreApplicationStartMethod(typeof(Unity.WebForms.PreApplicationStart), "PreStart")] 我得到的错误是: 程序集上的PreApplicationStartMethodAttribute指定的方法。。。无法解决 这是保存方法的类(在App_Start文
[assembly: PreApplicationStartMethod(typeof(Unity.WebForms.PreApplicationStart), "PreStart")]
我得到的错误是:
程序集上的PreApplicationStartMethodAttribute指定的方法。。。无法解决
这是保存方法的类(在App_Start文件夹中):
我有什么遗漏或误解吗
感谢使用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));
}
}
}
}
以及:
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")]