0

First, my apologies - I am not a C# or asp developer, but I know enough to be dangerous. I inherited a couple of aspx pages on our website that were developed by people no longer with the company. These pages have worked for years running in IIS 7.5 on Windows 2012 and ASP .NET 4.5. We recently upgraded to IIS 10, Windows 2016, and ASP .NET 4.7.2. These two pages work just as before except when they hit LINQ calls. If I comment that code out, the pages work (as much as they can without the LINQ functions).

What I'm trying to understand is what is missing that would cause these to fail. I do not have access to Visual Studio due to corporate restrictions, so remote debugging is not an option. I have been trying to figure this out the old fashion way by commenting stuff out to narrow down the problem. As soon as I uncomment the LINQ calls, it fails. Based on the stack trace below, it looks something is missing that causes it to not compile. As best I can tell, I have all the DLLs that I had before. I have searched other threads, but they all seem to talk about updating the VS project. I don't have VS, just an aspx page, again that worked in earlier incarnations of IIS and ASP .NET.

Exception information: 
    Exception type: HttpCompileException 
    Exception message: c:\inetpub\wwwroot\STPUserComapre.aspx(187): error CS0012: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
   at System.Web.Compilation.AssemblyBuilder.Compile()
   at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
   at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
   at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound)
   at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp)
   at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
   at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
RSteiner
  • 1
  • 1
  • Include some code. This will increase your chances of getting help. Anyway, check that in your .cshtml/.aspx files, which contain LINQ expressions, there is an import of the namespace "System.Linq;", like this at the top of your view: (@using System.Linq;) Or: (<%@ Import namespace="System.Linq" %>) for .aspx. – Silvair L. Soares Jul 20 '20 at 17:14
  • This can also be useful for you: https://stackoverflow.com/questions/1697169/is-it-possible-to-use-the-using-statement-in-my-aspx-views-asp-net-mvc – Silvair L. Soares Jul 20 '20 at 17:23
  • The aspx contains the following: `<%@ Import Namespace = "System.Linq"%>.` Again, all the piece parts should be there since this worked in IIS8 and ASPX .Net 4.5. A sample bit of code that won't compile is this: `var y = usrxml.Split('=').Where(e => e.Contains('^')).Select(e => e.Split('^').First());` – RSteiner Jul 20 '20 at 20:03
  • first, try to install the .net framework Developer Pack based on your required version on your machine. add this code in your web.conifg file: ` ` – Jalpa Panchal Jul 21 '20 at 09:22
  • I believe that the answers to this question, have some interesting things for you to try: https://stackoverflow.com/questions/22822406/build-error-you-must-add-a-reference-to-system-runtime – Silvair L. Soares Jul 21 '20 at 11:41
  • Apparently, this is a problem already known and even cataloged by Microsoft: https://support.microsoft.com/en-us/help/2971005/error-message-when-you-compile-applications-to-target-the-net-framewor – Silvair L. Soares Jul 21 '20 at 11:49
  • That MS note is for 4.5.2, which is the old version that we were successfully using. I have not been able to find anything similar for 4.7.2, which is where we are currently stuck. – RSteiner Jul 21 '20 at 17:12
  • rebuild your application using the command and again publish in iis. [link1](https://learn.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/command-line-deployment), [link2](https://stackoverflow.com/questions/24063305/build-and-publish-c-sharp-net-web-app-via-command-line/24063993) – Jalpa Panchal Jul 29 '20 at 09:46
  • @JalpaPanchal It turns out that your response on Jul 21 with the config file change was the correct one. Once I added that assembly to the config, everything worked. No need to install anything new. As to your most recent comment, I do not have access to Visual Studio, so there is no publishing. I just update the aspx code, cross my fingers, and hope. – RSteiner Jul 30 '20 at 14:14

0 Answers0