ActivationManager Exception during build process? - asp.net

I'm getting the following exception when building a website project in VS 2010:
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..
How do I go about debugging this? It's happening when I build in VS.NET and from the command-line (e.g., via NAnt/MSBuild).

To solve this, you need to supply the -errorstack argument to the aspnetcompiler. Then when it fails, you'll get not only the stack trace of the exception you're seeing now, but also the InnerException that it's wrapping. For instance, here's the output when the build error is caused by a problem with a Cassette dll not being loaded:
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)

I'd like to up-vote Xoltar's answer, but this is my first contribution to SO so I don't have the rep!
I had a very similar problem on our build-server (TeamCity), here's a clip from the 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
To diagnose the problem I ran ASPNET_COMPILER, using the -errorstack argument against what MSBUILD had generated for site. In this case:
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..
In my case a dependency on one of the Azure assemblies (which wasn't installed on the build server) was the root of the problem.

Increase the verbosity level of the msbuild task or command line to get more detailed error messages.
For example, use /verbosity:detailed.
See http://msdn.microsoft.com/en-us/library/ms164311.aspx
Are you using Ninject?
If so, see this: http://groups.google.com/group/ninject/browse_thread/thread/1934e9260ba07ecd?pli=1 and this: http://www.techques.com/question/1-6173194/Strange-behaviour-when-using-Ninject-to-resolve-a-service-within-a-controller-factory
Are you using RavenDB?
If so, see this: http://groups.google.com/group/ravendb/browse_thread/thread/437738caf4760ce1/b7e92fd6cfeaaa17?#b7e92fd6cfeaaa17

In my case, I was seeing the message [AspNetCompiler] error ASPRUNTIME error message: Value cannot be null. in TeamCity.
In the full build logs, the more useful message at the bottom was:
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.
As it turns out I had an exception being thrown by a method I had defined using 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
}
}
}
The cause in my case was my prestart method was loading settings from the registry, and they didn't exist on the build server (but did on my machine, so it worked when I built it). I have no clue why webdeployment projects run this code.
I wrapped the entire thing in a try..catch that logs a fatal message (which in my app, goes to both the log file and windows event log). In builds, I don't really care if it fails since it doesn't need to do anything. In actual installations, if the settings are missing the app won't work (and so the log explains why).
Now, to the OP the problem seems to be in web activator. I would not be surprised if there is a method using webactivor in App_Start folder that is throwing the error, which is making it look like it's coming from WebActivator. Check there first, wrap things in try..catch if needed. It's also possible there is a bug in webactivator itself.
So because I came across this post while researching the problem, hopefully this information is useful to at least someone else.
TL;DR: Web deployment projects run the ApplicationPreStart methods when they compile. Ensure that you have try..catch blocks around any code run at prestart time or can otherwise handle the situation where the code is executed during compile time on your build server(s), outside of the IIS/hosting environment.

Related

Specified Web Pages version "3.0.0.0" could not be found. Update your web.config to specify a different version. Current version: "2.0.0.0"

I found this error after publishing the site on the server.
I tried a lot to solve this problem from my side but nothing works for me.
I have tried to update all those packages with the latest and still does not work for me.
But, it works well when I run a project in Visual Studio without any problems.
I have checked these 2 links to fix my problem but it still doesn't work for me.
Specified Web Pages version “3.0.0.0” could not be found. Update your web.config to specify a different version. Current version: “2.0.0.0”
Update your web.config to specify a different version?
However, I tried to install the downgraded (older) version and I got a 404 error code, the resource could not be found.
Also, I have checked all the web config files where the version has been declared and it seems right for me.
I don't know what I should do with this error message.
It would be nice if someone could help me with this.
Server Error in '/' Application.
Specified Web Pages version "3.0.0.0" could not be found. Update your web.config to specify a different version. Current version: "2.0.0.0".
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Specified Web Pages version "3.0.0.0" could not be found. Update your web.config to specify a different version. Current version: "2.0.0.0".
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: Specified Web Pages version "3.0.0.0" could not be found. Update your web.config to specify a different version. Current version: "2.0.0.0".]
System.Web.WebPages.Deployment.PreApplicationStartCode.StartCore(IFileSystem fileSystem, String appDomainAppPath, String binDirectory, NameValueCollection appSettings, IEnumerable1 loadedAssemblies, IBuildManager buildManager, Action1 loadWebPages, Action registerForChangeNotification, Func`2 getAssemblyNameThunk) +21268
System.Web.WebPages.Deployment.PreApplicationStartCode.StartCore() +245
[InvalidOperationException: The pre-application start initialization method Start on type System.Web.WebPages.Deployment.PreApplicationStartCode threw an exception with the following error message: Specified Web Pages version "3.0.0.0" could not be found. Update your web.config to specify a different version. Current version: "2.0.0.0"..]
System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection1 methods, Func1 setHostingEnvironmentCultures) +890
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +167
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +133
System.Web.Compilation.BuildManager.ExecutePreAppStart() +178
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +746
[HttpException (0x80004005): The pre-application start initialization method Start on type System.Web.WebPages.Deployment.PreApplicationStartCode threw an exception with the following error message: Specified Web Pages version "3.0.0.0" could not be found. Update your web.config to specify a different version. Current version: "2.0.0.0"..]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +552
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +122
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +737
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4261.0

Xamarin Android - Mono.Linker.MarkException when calling a method from another project

I have a Xamarin application which also has a project reference to an adapted version of the https://github.com/XAM-Consulting/TEditor project.
This has previously worked fine when I've used the linker to do a release build, but as I've been gearing up for a second app release, I now get a linker exception:
Severity Code Description Project File Line Suppression State
Error Mono.Linker.MarkException: Error processing method: 'System.Void
Project.ViewModels.ApprovalViewModel/<<get_EditCommand>b__26_0>d::MoveNext()' in assembly: 'Project.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.Void
TEditor.Abstractions.ITEditor::set_PageTitle(System.String)
at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference)
at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
at Mono.Linker.Steps.MarkStep.ProcessQueue()
--- End of inner exception stack trace ---
at Mono.Linker.Steps.MarkStep.ProcessQueue()
at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
at Mono.Linker.Steps.MarkStep.Process()
at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
at MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context)
at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
at Mono.Linker.Pipeline.Process(LinkContext context)
at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context)
at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
at Xamarin.Android.Tasks.LinkAssemblies.RunTask()
at Xamarin.Android.Tasks.AndroidTask.Execute() Project.Droid C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets 632
The setter in question is just a method where I set the property of the object:
_editor.PageTitle = ApproveTitle;
I know that this can be avoided by setting Linking to None but that's not going to help the app in the long run and I want to use the linker.
Any help would be really appreciated!!

Error while remove migration and update database entity framework core Exception while reading from stream

I am working in dotnet core web api using restful service with entity framework code first approach. I am running one migration and when I run the migration using add-migration command then I get build succeeded but then when I try to update-database or rollback the migration using remove-migration I get the below error:
PM> remove-migration
Build started...
Build succeeded.
Npgsql.NpgsqlException (0x80004005): Exception while reading from stream
---> System.IO.EndOfStreamException: Attempted to read past the end of the stream.
at Npgsql.NpgsqlReadBuffer.<>c__DisplayClass34_0.<<Ensure>g__EnsureLong|0>d.MoveNext()
at Npgsql.NpgsqlReadBuffer.<>c__DisplayClass34_0.<<Ensure>g__EnsureLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Npgsql.NpgsqlConnector.Authenticate(String username, NpgsqlTimeout timeout, Boolean async)
at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlConnection.<>c__DisplayClass32_0.<<Open>g__OpenLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Npgsql.NpgsqlConnection.Open()
at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.Exists()
at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.GetAppliedMigrations()
at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.RemoveMigration(String projectDir, String rootNamespace, Boolean force, String language)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.RemoveMigration(String contextType, Boolean force)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigrationImpl(String contextType, Boolean force)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigration.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Exception while reading from stream
This is resolved. I had a Factory class in which the connection string was not updated to my local database. There it was pointing to dev and my secret.json was pointing to localhost.

OrangeBits extension for WebMatrix may have caused a crash and has been disabled

I'm getting the following error every time I open WebMatrix with the OrangeBits extension installed:
The "OrangeBits" extension may have caused a crash and has been disabled. We recommend contacting the extension owner for assistance.
System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. ---> Ionic.Zip.ZipException: The file C:\USERS\NAME\APPDATA\LOCAL\MICROSOFT\WEBMATRIX\EXTENSIONS\30\OrangeBits\Tools\bin\cake already exists.
at Ionic.Zip.ZipEntry.CheckExtractExistingFile(String baseDir, String targetFileName)
at Ionic.Zip.ZipEntry.InternalExtract(String baseDir, Stream outstream, String password)
at Ionic.Zip.ZipEntry.Extract(String baseDirectory)
at OrangeBits.OrangeBits.<>c__DisplayClass17.<UnpackModules>b__15()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of inner exception stack trace ---
---> (Inner Exception #0) Ionic.Zip.ZipException: The file C:\USERS\NAME\APPDATA\LOCAL\MICROSOFT\WEBMATRIX\EXTENSIONS\30\OrangeBits\Tools\bin\cake already exists.
at Ionic.Zip.ZipEntry.CheckExtractExistingFile(String baseDir, String targetFileName)
at Ionic.Zip.ZipEntry.InternalExtract(String baseDir, Stream outstream, String password)
at Ionic.Zip.ZipEntry.Extract(String baseDirectory)
at OrangeBits.OrangeBits.<>c__DisplayClass17.<UnpackModules>b__15()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()<---
Referencing Justin Beckwith's answer here
Resolving this issue was as simple as navigating to:
C:\USERS\NAME\APPDATA\LOCAL\MICROSOFT\WEBMATRIX\EXTENSIONS\30\OrangeBits\Tools
And deleting modules.zip

NMath IIS access denied

I have tried using the NMath library on a
ASP.NET 4 web application hosted in IIS. While it works perfectly o the development machine, on the server it throws this exception:
Unable to load DLL 'nmath_native_x86.dll': Access is denied.
(Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.DllNotFoundException: Unable to load DLL
'nmath_native_x86.dll': Access is denied. (Exception from HRESULT:
0x80070005 (E_ACCESSDENIED))
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[DllNotFoundException: Unable to load DLL 'nmath_native_x86.dll':
Access is denied. (Exception from HRESULT: 0x80070005
(E_ACCESSDENIED))]
CenterSpace.NMath.Kernel.DotNetBlas.ca985db1fb290841a533a3547ace1ae2b(Int32*
ca9e3f1c0641beace93cb8eb4a27060d6, Double*
cf339080161dff75cfd1b46a10c2eec70, Int32*
c757a2154665e6da4d820f8c504ec2601, Double*
c00a69c4fa5b6d809b68a96ca184dcf79, Int32*
c1565590bf448d2c630952a0391360cc3) +0
CenterSpace.NMath.Kernel.DotNetBlas.copy(Int32 n, DoubleDataBlock x,
Int32 xOffset, Int32 incx, DoubleDataBlock y, Int32 yOffset, Int32
incy) +149 CenterSpace.NMath.Core.DoubleVector.set_Item(Slice
slice, DoubleVector value) +165
While i have read around here that it might be related the the
permissions of the AppPool or something similar, I can't seem to point down the problem. What could it be?!
It could be a couple of options.
1) Is the C++ runtime installed? NMath can't load a native dll without it. See the deployment section here: http://centerspace.net/doc/NMath/user/overview-83427.htm#Xoverview-83427
2) Perhaps you're not configuring NMath correctly? You can do NMathConfiguration.NativeLocation to point to a location. More here:
http://centerspace.net/doc/NMathSuite/ref/html/T_CenterSpace_NMath_Core_NMathConfiguration.htm
Finally, please generate log file using NMathConfiguration.LogLocation. The resulting log file will tell you what's wrong.
Trevor

Resources