2011-11-15 42 views
20

tôi nhận được ngoại lệ sau khi xây dựng một dự án trang web trong VS 2010:ActivationManager Ngoại lệ trong quá trình xây dựng?

The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation..  

Làm thế nào để tôi đi về gỡ lỗi này? Nó xảy ra khi tôi xây dựng trong VS.NET và từ dòng lệnh (ví dụ, thông qua NAnt/MSBuild).

+0

Có bất kỳ câu trả lời nào phù hợp với bạn không? –

Trả lời

2

Tăng mức độ chi tiết của tác vụ msbuild hoặc dòng lệnh để nhận thông báo lỗi chi tiết hơn.

Ví dụ: sử dụng /verbosity:detailed.

Xem http://msdn.microsoft.com/en-us/library/ms164311.aspx

Bạn đang sử dụng Ninject?
Nếu có, hãy xem điều này: http://groups.google.com/group/ninject/browse_thread/thread/1934e9260ba07ecd?pli=1 và điều này: http://www.techques.com/question/1-6173194/Strange-behaviour-when-using-Ninject-to-resolve-a-service-within-a-controller-factory

Bạn đang sử dụng RavenDB?
Nếu vậy, thấy điều này: http://groups.google.com/group/ravendb/browse_thread/thread/437738caf4760ce1/b7e92fd6cfeaaa17?#b7e92fd6cfeaaa17

23

Để giải quyết việc này, bạn cần phải cung cấp các luận cứ -errorstack đến aspnetcompiler. Sau đó, khi nó không thành công, bạn sẽ nhận được không chỉ dấu vết ngăn xếp của ngoại lệ mà bạn đang nhìn thấy bây giờ, mà còn là InnerException mà nó gói. Ví dụ, đây là đầu ra khi lỗi xây dựng là do một vấn đề với một Cassette dll không được nạp:

error ASPRUNTIME: The pre-application start initialization method Run on type We 
bActivator.ActivationManager threw an exception with the following error message 
: Exception has been thrown by the target of an invocation.. 

[TypeLoadException]: Could not load type 'Cassette.Configuration.ICassetteConfig 
uration' from assembly 'Cassette, Version=0.8.1.0, Culture=neutral, PublicKeyTok 
en=null'. 
    at Cassette.Web.StartUp..cctor() 

[TypeInitializationException]: The type initializer for 'Cassette.Web.StartUp' t 
hrew an exception. 
    at Cassette.Web.StartUp.PreApplicationStart() 

[TargetInvocationException]: Exception has been thrown by the target of an invoc 
ation. 
    at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Ob 
ject target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAt 
tributes, RuntimeType typeOwner) 
    at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Obj 
ect target, Object[] arguments, Signature sig, MethodAttributes methodAttributes 
, RuntimeType typeOwner) 
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invoke 
Attr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisib 
ilityChecks) 
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invoke 
Attr, Binder binder, Object[] parameters, CultureInfo culture) 
    at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) 
    at WebActivator.BaseActivationMethodAttribute.InvokeMethod() 
    at WebActivator.ActivationManager.RunActivationMethods[T]() 
    at WebActivator.ActivationManager.RunPreStartMethods() 
    at WebActivator.ActivationManager.Run() 

[InvalidOperationException]: The pre-application start initialization method Run 
on type WebActivator.ActivationManager threw an exception with the following er 
ror message: Exception has been thrown by the target of an invocation.. 
    at System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection` 
1 methods) 
    at System.Web.Compilation.BuildManager.CallPreStartInitMethods() 
    at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appMan 
ager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, Host 
ingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception a 
ppDomainCreationException) 

[HttpException]: The pre-application start initialization method Run on type Web 
Activator.ActivationManager threw an exception with the following error message: 
Exception has been thrown by the target of an invocation.. 
    at System.Web.Compilation.ClientBuildManager.EnsureHostCreated() 
    at System.Web.Compilation.ClientBuildManager.PrecompileApplication(ClientBuil 
dManagerCallback callback, Boolean forceCleanBuild) 
    at System.Web.Compilation.Precompiler.Main(String[] args) 
+16

Để lưu những người tìm kiếm trong tương lai, bạn có thể thực hiện điều này bằng cách chạy 'aspnet_compiler.exe -errorstack -p C: \ physical \ path \ đến \ MyApp -v MyApp' – neontapir

+2

vị trí aspnet_compiler.exe:' C \ Windows \ microsoft.net \ framework \ \ aspnet_compiler.exe' –

+0

Thông tin thêm về tham số dòng lệnh: https://msdn.microsoft.com/en-us/library/ms229863(v=vs.140).aspx –

5

Tôi muốn up-phiếu trả lời Xoltar, nhưng đây là đóng góp đầu tiên của tôi để SO vì vậy Tôi không có đại diện!

Tôi đã có một vấn đề rất tương tự như trên chúng tôi xây dựng-server (TeamCity), đây là một đoạn trích từ các build-log:

[00:10:39]: (MvcBuildViews target) -> 
[00:10:39]: error ASPRUNTIME : The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation.. [C:\TeamCity\buildAgent\work\1ee8c94c32e676ad\source\Project.Site\Project.Site.csproj] 
[00:10:39]:  0 Warning(s) 
[00:10:39]:  1 Error(s) 
[00:10:39]: Time Elapsed 00:00:27.93 

Để chẩn đoán vấn đề tôi chạy ASPNET_COMPILER, sử dụng -errorstack đối số dựa trên những gì MSBUILD đã tạo cho trang web. Trong trường hợp này:

C:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_compiler -p "C:\TeamCity\buildAgent\work\1ee8c94c32e676ad\source\Project.Site" -v anything -errorstack 

Utility to precompile an ASP.NET application 
Copyright (C) Microsoft Corporation. All rights reserved. 

error ASPRUNTIME: The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message : Exception has been thrown by the target of an invocation.. 

[FileNotFoundException]: Could not load file or assembly 'msshrtmi, Version=1.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. 
    at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeEnvironment() 
    at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment..cctor() 

error ASPRUNTIME: The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message : Exception has been thrown by the target of an invocation.. 

Trong trường hợp của tôi, phụ thuộc vào một trong các cụm Azure (không được cài đặt trên máy chủ xây dựng) là gốc của sự cố.

1

Trong trường hợp của tôi, tôi đã nhìn thấy thông báo [AspNetCompiler] error ASPRUNTIME error message: Value cannot be null. trong TeamCity.

Trong xây dựng đầy đủ các bản ghi, thông điệp hữu ích hơn ở phía dưới là:

error ASPRUNTIME : The pre-application start initialization method InitializePreStart on type MyApplication.MvcApplication threw an exception with the following error message: Value cannot be null. 

Khi nó quay ra tôi đã có một ngoại lệ được ném bởi một phương pháp tôi đã định nghĩa sử dụng PreApplicationStartMethod:

[assembly: System.Web.PreApplicationStartMethod(typeof(MyApp.MvcApplication), "InitializePreStart")] 

namespace PrintFleet.PFE.RestService 
{ 
    public class MvcApplication : System.Web.HttpApplication 
    { 
     //.... 
     public static void InitializePreStart() 
     { 
      // exception thrown here 
     } 
    } 
} 

Nguyên nhân trong trường hợp của tôi là phương pháp prestart của tôi đang tải cài đặt từ sổ đăng ký và chúng không tồn tại trên máy chủ xây dựng (nhưng đã làm trên máy của tôi, vì vậy nó hoạt động khi tôi xây dựng nó). Tôi không biết tại sao các dự án webdeployment chạy mã này.

Tôi đã bọc toàn bộ nội dung trong một lần thử ..bắt được nhật ký một thông báo gây tử vong (trong ứng dụng của tôi, chuyển đến cả tệp nhật ký và nhật ký sự kiện cửa sổ). Trong xây dựng, tôi không thực sự quan tâm nếu nó không thành công vì nó không cần phải làm bất cứ điều gì. Trong cài đặt thực tế, nếu cài đặt bị thiếu, ứng dụng sẽ không hoạt động (và vì vậy nhật ký sẽ giải thích lý do).


Bây giờ, đối với OP, sự cố có vẻ như trong trình kích hoạt web. Tôi sẽ không ngạc nhiên nếu có một phương pháp sử dụng webactivor trong thư mục App_Start mà là ném lỗi, mà làm cho nó trông giống như nó đến từ WebActivator. Kiểm tra có đầu tiên, bọc những thứ trong try..catch nếu cần thiết. Nó cũng có thể có một lỗi trong webactivator chính nó.


Vì vậy, vì tôi đã xem qua bài đăng này trong khi nghiên cứu vấn đề, hy vọng thông tin này hữu ích cho ít nhất một người khác.

TL; DR: Dự án triển khai web chạy các phương thức ApplicationPreStart khi chúng biên dịch. Đảm bảo rằng bạn đã thử các khối lệnh xung quanh bất kỳ mã nào chạy ở thời gian prestart hoặc có thể xử lý tình huống nơi mã được thực hiện trong thời gian biên dịch trên (các) máy chủ xây dựng của bạn, bên ngoài môi trường IIS/lưu trữ.

Các vấn đề liên quan