ASP.NET 3.5 precompilation [NullReferenceException] - asp.net

I'm getting a null reference for an asp.net application while running precompile using aspnet_compiler. There's no specific error however i have this in the build log.
[NullReferenceException]: Object reference not set to an instance of an object.
at System.Web.Compilation.BuildManager.CopyPrecompiledFile(VirtualFile vfile, String destPhysicalPath)
at System.Web.Compilation.BuildManager.CopyStaticFilesRecursive(VirtualDirectory sourceVdir, String destPhysicalDir, Boolean topLevel)
at System.Web.Compilation.BuildManager.CopyStaticFilesRecursive(VirtualDirectory sourceVdir, String destPhysicalDir, Boolean topLevel)
at System.Web.Compilation.BuildManager.PrecompileAppInternal(VirtualPath startingVirtualDir)
at System.Web.Compilation.BuildManager.PrecompileApp(VirtualPath startingVirtualDir)
at System.Web.Compilation.BuildManager.PrecompileApp(ClientBuildManagerCallback callback)
at System.Web.Compilation.BuildManagerHost.PrecompileApp(ClientBuildManagerCallback callback)
at System.Web.Compilation.BuildManagerHost.PrecompileApp(ClientBuildManagerCallback callback)
at System.Web.Compilation.ClientBuildManager.PrecompileApplication(ClientBuildManagerCallback callback, Boolean forceCleanBuild)
at System.Web.Compilation.ClientBuildManager.PrecompileApplication(ClientBuildManagerCallback callback)
at System.Web.Compilation.Precompiler.Main(String[] args)
Things i've tried so far,
Clearing temp
Assigning permissions to folders
Checked for folder compression
Checked for *.compiled files in bin
Deleted *.ddl refresh dlls in bin
I'm running build from command line with the following,
c:\windows\Microsoft.NET\Framework\v3.5\MSBuild.exe Build.xml /target:Precompile > log\Precompile.txt
This is the target definition in the build xml
<Target Name="Precompile">
<Exec
Command=""C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler" -v Web -p E:\Src\Web -u -f -d -fixednames E:\Output -errorstack"
WorkingDirectory="."
ContinueOnError="false"/>
</Target>
So far nothing has helped, i've taken this up from a colleague who says it was working fine the other day, how do i go about troubleshooting this? Build is running and the exit happens only towards the end, another thing is its running ok from visual studio, only the command line build is breaking, any pointers ? thanks

Related

Problem when running Azure function locally using Azure Functions Core Tools

I am developing a durable Azure function. I am using .NET Core 3.1. It is an HTTP-triggered function. When I debug it from Visual Studio and then trigger it by calling the endpoint everything works.
On the same machine I installed Azure Functions Core Tools (4.0.3971). I run the storage emulator:
C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe start
Then go to the directory where my function resides and type:
func start
Everything works the same as previously, so I trigger my function by making a request to the endpoint. It starts doing its work, but then throws the following error:
[2021-12-03T14:25:51.081Z] Executed 'MyFunction_Process' (Failed, Id=f709e4c0-f74e-4303-a68b-6d5d55f0f7e5, Duration=2182ms)
[2021-12-03T14:25:51.086Z] System.Private.CoreLib: Exception while executing function: MyFunctionIntegration_Process. Microsoft.EntityFrameworkCore: The type initializer for 'Microsoft.EntityFrameworkCore.EnumerableMethods' threw an exception. System.Linq: Sequence contains more than one matching element.
[2021-12-03T14:25:51.101Z] myfunctionsingleinstance: Function 'MyFunction_Process (Activity)' failed with an error. Reason: System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.EnumerableMethods' threw an exception.
[2021-12-03T14:25:51.106Z] ---> System.InvalidOperationException: Sequence contains more than one matching element
[2021-12-03T14:25:51.110Z] at System.Linq.ThrowHelper.ThrowMoreThanOneMatchException()
[2021-12-03T14:25:51.112Z] at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
[2021-12-03T14:25:51.113Z] at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
[2021-12-03T14:25:51.115Z] at Microsoft.EntityFrameworkCore.EnumerableMethods..cctor()
[2021-12-03T14:25:51.116Z] --- End of inner exception stack trace ---
[2021-12-03T14:25:51.117Z] at Microsoft.EntityFrameworkCore.EnumerableMethods.get_AnyWithPredicate()
[2021-12-03T14:25:51.119Z] at Microsoft.EntityFrameworkCore.Query.Internal.AllAnyToContainsRewritingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
[2021-12-03T14:25:51.121Z] at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
[2021-12-03T14:25:51.124Z] at Microsoft.EntityFrameworkCore.Query.QueryTranslationPreprocessor.Process(Expression query)
[2021-12-03T14:25:51.126Z] at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
[2021-12-03T14:25:51.128Z] at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
[2021-12-03T14:25:51.129Z] at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
[2021-12-03T14:25:51.131Z] at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_0`1.<Execute>b__0()
[2021-12-03T14:25:51.133Z] at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
[2021-12-03T14:25:51.134Z] at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
[2021-12-03T14:25:51.136Z] at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
[2021-12-03T14:25:51.140Z] at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
[2021-12-03T14:25:51.141Z] at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetEnumerator()
[2021-12-03T14:25:51.143Z] at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.IncludableQueryable`2.GetEnumerator()
[2021-12-03T14:25:51.144Z] at System.Linq.Enumerable.ToDictionary[TSource,TKey](IEnumerable`1 source, Func`2 keySelector, IEqualityComparer`1 comparer)
[2021-12-03T14:25:51.146Z] at System.Linq.Enumerable.ToDictionary[TSource,TKey](IEnumerable`1 source, Func`2 keySelector)
[2021-12-03T14:25:51.148Z] at Logistics.Infrastructure.MyFunctionIntegration.Integration.GetDbRows(ILogger log) in C:\Users\Michal\source\repos\Logistics\src\backend\src\infrastructure\Logistics.Infrastructure.MyFunctionIntegration\Integration.cs:line 103
...
The line 103 is:
var dbEntities = _dbContext.Carriers.IgnoreQueryFilters().Include(c => c.CarrierGitd.Address).ToDictionary(c => c.CarrierGitd?.LicenseNumber);
So it happens when I try to fetch data from the database. But it works fine, when I debug in VS. The database is the same. Where's the catch?
The problem went away when I upgraded Microsoft.EntityFrameworkCore to 5.0.0 in SecondLib dependency.
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" Version="5.0.0" />
</ItemGroup>
The TargetFramework wasn't touched
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
Note:
I got the same issue in the Azure Functions core tools version 3. If your Entity framework core version is < 5.x in second lib dependency, upgrade and try once. Or If possible, downgrade Azure Functions Core tools version to 3 and check.
I needed to support both a v3 and v4 functions project so I just took a copy of the V3 tools directory C:\Program Files\Microsoft\Azure Functions Core Tools (then named it something like 'Azure Functions Core Tools v3'), installed V4 and created a batch file to run the correct 'func.exe' in the directory for the old v3 project.

"aspnet_compiler.exe" exited with code 1, tried all the other posts with the same title

Project:
ASP.NET 4.5.2
MVC 5
Visual Studio 2015 (latest)
When building the project, today it mysteriously began erroring out with the error in the title. Now, it is not the build which is failing, but the publish:
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========
Now, I have gone into the temp build folder, at
[path to project]\obj\Release\AspnetCompileMerge\Source
And it seems to have all the files needed to push to the sandbox, but when I do so attempting to reach the site errors out with a massive message (50+ lines). Will append once I have them formatted.
Suggestions?
NOTE: Other projects still compile just fine. This is limited to this project, specifically.
NOTE 2: I have seen several requests to use aspnet_compiler.exe with the -errorstack flag in the commandline, but I have yet to figure out what the -v and -p flags mean, so I am currently unable to provide the output. I have never used the commandline for development before, so details would be appreciated.
UPDATE 1: I actually figured out the command, and this is what I got:
D:\[path to project]>aspnet_compiler.exe -errorstack -v /[project] -p D:\[path to project]\
Microsoft (R) ASP.NET Compilation Tool version 4.0.30319.33440
Utility to precompile an ASP.NET application
Copyright (C) Microsoft Corporation. All rights reserved.
D:\[path to project]\web.config(43): error ASPCONFIG: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
[ConfigurationErrorsException]: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS. (D:\[path to project]\web.config line 43)
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Web.Configuration.RuntimeConfig.GetSectionObject(String sectionName)
at System.Web.Configuration.RuntimeConfig.GetSection(String sectionName, Type type, ResultsIndex index)
at System.Web.Configuration.RuntimeConfig.get_Compilation()
at MTConfigUtil.GetCompilationConfig(String vpath)
at System.Web.Compilation.BuildManager.IsBatchEnabledForDirectory(VirtualPath virtualDir)
at System.Web.Compilation.BuildManager.PrecompileWebDirectoriesRecursive(VirtualDirectory vdir, Boolean topLevel)
at System.Web.Compilation.BuildManager.PrecompileWebDirectoriesRecursive(VirtualDirectory vdir, Boolean topLevel)
at System.Web.Compilation.BuildManager.PrecompileWebDirectoriesRecursive(VirtualDirectory vdir, Boolean topLevel)
at System.Web.Compilation.BuildManager.PrecompileAppInternal(VirtualPath startingVirtualDir, IEnumerable`1 excludedVirtualPaths)
at System.Web.Compilation.BuildManager.PrecompileApp(VirtualPath startingVirtualDir, IEnumerable`1 excludedVirtualPaths)
at System.Web.Compilation.BuildManager.PrecompileApp(ClientBuildManagerCallback callback, IEnumerable`1 excludedVirtualPaths)
at System.Web.Compilation.BuildManagerHost.PrecompileApp(ClientBuildManagerCallback callback, List`1 excludedVirtualPaths)
at System.Web.Compilation.BuildManagerHost.PrecompileApp(ClientBuildManagerCallback callback, List`1 excludedVirtualPaths)
at System.Web.Compilation.ClientBuildManager.PrecompileApplication(ClientBuildManagerCallback callback, Boolean forceCleanBuild)
at System.Web.Compilation.ClientBuildManager.PrecompileApplication(ClientBuildManagerCallback callback)
at System.Web.Compilation.Precompiler.Main(String[] args)
In particular, note:
This error can be caused by a virtual directory not being configured as an application in IIS. (D:\[path to project]\web.config line 43)
Problem is, the only thing in my Web.Config at that line is
<authentication mode="None" />
You see, because the IIS built into VS 2015 crashes every time I stop debugging, I set up IIS on Windows itself and just pointed it toward my project directory. But it was working just fine up until now. Could this be the issue?
EDIT 2: Commenting out line 43 in my Web.Config now throws this:
This error can be caused by a virtual directory not being configured as an application in IIS. (D:\[path to project]\web.config line 46)
Clearly there is something very, very strange. Considering I have published at least twice since I last changed my Web.Config.
Ended up doing a backup of the project, nuking it from orbit, repaving with a new blank project, adding back in all the required NuGet packages and then copying over from the backup all the files I had directly edited. Including all the Migrations files also helped, as it meant I could pick up with the DB right where I left off. The only thing I had to walk through with a fine-toothed comb was the Web.Config -- I wanted to make sure this was set up perfectly, so I hand-edited it like a surgeon doing brain surgery.
FYI, I coped everything over through the file system while the project was unloaded, and then “included into the project” anything I had previously created from scratch.
Not the ideal situation, but hey. This project is still under construction, so I lost just about an hour or two at the most doing the rebuild. The tough part was dumping my Team Services repository, as it wouldn’t accept the new project. I did this after I confirmed the new setup was working 100%, as I wasn’t too concerned about not being able to roll back beyond a certain date.
After refactoring a solution I had a file containing a commented out class, so it only had the using clauses and namespace set. It was using a namespace that was no longer in use by any files but may have been cached somehow so didn't immediately error.
Building didn't pick it up and it caused the aspnet_compiler exited with code 1 error plus a few other unrelated errors that weren't errors. Removing the empty class file fixed it. Also remove any old namespaces from Views/web.config.

What are the valid DNX --watch flag values?

I'm working on my first ASP.NET 5 application. When trying to start the application from the command line by running:
dnx web --watch
I get the following output:
System.FormatException: Value for switch '--watch' is missing.
at Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationProvider.Load()
at Microsoft.Extensions.Configuration.ConfigurationBuilder.Add(IConfigurationProvider provider)
at Microsoft.AspNet.Hosting.WebApplication.Run(Type startupType, String[] args)
at Microsoft.AspNet.Server.Kestrel.Program.Main(String[] args)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
at Microsoft.Dnx.ApplicationHost.Program.<>c__DisplayClass3_0.<ExecuteMain>b__0()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
What are the valid values for the --watch flag? I tried giving it a dummy value of 0 then changed some of my controller code, but the change was not reflected.
Update
To install dnx-watch run the following:
dnu commands install Microsoft.Dnx.Watcher
Then run your application by doing something like:
dnx-watch web
Arguments passed after the command name ("web" in your case) are arguments passed to that command. If you want arguments passed to DNX, pass them before: dnx --watch web
But, --watch will go away. Use dnx-watch instead: https://github.com/aspnet/Announcements/issues/74

Is there shorter way to work with dotnetnuke and SVN

I have one project with a few sub projects in it. A few projects contain dotnetnuke modules. And I have committed this project to SVN repo. But now when I checkout version from SVN I have to manually copy module project to dotnetnuke/desktopModules directory. I am trying to find some shorter way for this :(
I follow solution from this question DotNetNuke and Subversion guidelines , but have no luck. I added nant.build file to my project with dotnetnuke modules. Navigate to it from command line and run 'nant' command, but I got following error :(
Unhandled Exception:
System.TypeInitializationException:
The type initializer fo r
'NAnt.Console.ConsoleStub' threw an
exception. --->
System.Security.SecurityEx ception:
Request for the permission of type
'System.Security.Permissions.FileIOP
ermission, mscorlib, Version=4.0.0.0,
Culture=neutral,
PublicKeyToken=b77a5c5619 34e089'
failed. at
System.Security.CodeAccessSecurityEngine.Check(Object
demand, StackCrawlMa rk& stackMark,
Boolean isPermSet) at
System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission
cap, S tackCrawlMark& stackMark) at
System.Security.CodeAccessPermission.Demand()
at
System.AppDomainSetup.VerifyDir(String
dir, Boolean normalize) at
System.AppDomain.get_BaseDirectory()
at
log4net.Config.XmlConfiguratorAttribute.Configure(Assembly
sourceAssembly, ILoggerRepository
targetRepository) at
log4net.Core.DefaultRepositorySelector.ConfigureRepository(Assembly
assemb ly, ILoggerRepository
repository) at
log4net.Core.DefaultRepositorySelector.CreateRepository(Assembly
repositor yAssembly, Type
repositoryType, String repositoryName,
Boolean readAssemblyAttri butes) at
log4net.Core.DefaultRepositorySelector.CreateRepository(Assembly
repositor yAssembly, Type
repositoryType) at
log4net.Core.DefaultRepositorySelector.GetRepository(Assembly
repositoryAs sembly) at
log4net.Core.LoggerManager.GetLogger(Assembly
repositoryAssembly, String n ame)
at
log4net.LogManager.GetLogger(Assembly
repositoryAssembly, String name) at
log4net.LogManager.GetLogger(Type
type) at
NAnt.Console.ConsoleStub..cctor()
--- End of inner exception stack trace --- at NAnt.Console.ConsoleStub.Main(String[]
args)
To address your first point, if you map your source control repository directly to your website's desktopmodules folder, you won't need to copy it manually after getting latest.
For the second point, you may need to unblock the files being used by NAnt or look into using a different version of NAnt that does not have this issue. Alternatively, you can look into using MSBuild scripts instead of NAnt.

error ASPPARSE: Could not load type

If I run this command on my system
<Exec Command="C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler -v localhost -p $(SourceDir)\wwwroot -u -f projectCompileCode\project -c -errorstack -nologo" />
I get the following error:
error ASPParse: Could not load the type: Projectname:SomeFile.
The project is web application project
This my stack trace:
[HttpException]: Could not load type 'ProjectName.FileName'.
at System.Web.UI.TemplateParser.GetType(String typeName, Boolean ignoreCa
e, Boolean throwOnError)
at System.Web.UI.TemplateParser.ProcessInheritsAttribute(String baseTypeN
me, String codeFileBaseTypeName, String src, Assembly assembly)
at System.Web.UI.TemplateParser.PostProcessMainDirectiveAttributes(IDicti
nary parseData)
[HttpParseException]: Could not load type ''ProjectName.FileName.
at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virt
alPath, Encoding fileEncoding)
at System.Web.UI.TemplateParser.ParseReader(StreamReader reader, VirtualP
th virtualPath)
at System.Web.UI.TemplateParser.ParseFile(String physicalPath, VirtualPat
virtualPath)
at System.Web.UI.TemplateParser.ParseInternal()
at System.Web.UI.TemplateParser.Parse()
at System.Web.Compilation.BaseTemplateBuildProvider.get_CodeCompilerType(
at System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(
uildProvider buildProvider)
at System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders()
at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
at System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResu
t(Boolean isPrecompiledApp)
at System.Web.Compilation.BuildManager.CompileGlobalAsax()
at System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()
at System.Web.Compilation.BuildManager.PrecompileAppInternal(VirtualPath
tartingVirtualDir)
at System.Web.Compilation.BuildManager.PrecompileApp(VirtualPath starting
irtualDir)
at System.Web.Compilation.BuildManager.PrecompileApp(ClientBuildManagerCa
lback callback)
at System.Web.Compilation.BuildManagerHost.PrecompileApp(ClientBuildManag
rCallback callback)
at System.Web.Compilation.BuildManagerHost.PrecompileApp(ClientBuildManag
rCallback callback)
at System.Web.Compilation.ClientBuildManager.PrecompileApplication(Client
uildManagerCallback callback, Boolean forceCleanBuild)
at System.Web.Compilation.ClientBuildManager.PrecompileApplication(Client
uildManagerCallback callback)
at System.Web.Compilation.Precompiler.Main(String[] args)
If I build in v2.0.50727 then still it is giving the same error.
My application is built in with VS 2010, .net frame asp.net frame work 4
Any help is greatly apperciated.
Have you tried:
Checking references
Doing a clean and a build
Checking the Inherits attr in the HTML against the code behind
Creating a new App Pool in IIS for this web site?
I see a similar problem. Works locally from within VS2008, but once published and deployed to the server, I get the same error as described here.
None of the suggestions I have provided worked for me; maybe they will work for you.
I had the same error. When I opened the web site DLL in ILDASM, the Type for a control was completely missing, as if it didn't even get compiled.
As it turns out, the codebehind files got excluded from the project. This is strange considering that the builds on my machine were successful! At any rate, I carefully re-included codebehind files and it all started working.
This often happens because the project file (.csproj or .vbproj) does not contain the necessary references to the files in question. Try cleaning/rebuilding all projects and making sure that the latest project files are moved to the server as well.
Another possibility is that the file was not actually included in your project at all. This allows the builds in Visual Studio to run just fine, but will break when compiling the .NET code (with aspnet_compiler for example) because all .aspx/.ascx/etc. files within the specified folder are compiled - whether they are included in your project or not.

Resources