ASP.NET View Component Fails to Load in Linux - c#

My web application runs perfectly fine in Windows. I even have it running in production on a Linux server for years without issue.
Now that I try to open the solution on a Linux desktop with JetBrains Rider IDE, the project fails to load at all. I boot up the Windows VM and the very same project runs.
First of all, what is to blame, JetBrains Rider, ASP.NET, or my installation? I've been developing desktop apps without any issue.
I created a new web application to see whether ASP.NET runs and it does. I started copying everything over file by file.
I got Pages/Shared/Components that contains ProductBox.cs and ProductBoxModel.cs and it runs fine. I add the file Pages/Shared/Components/ProductBox/Default.cshtml and it fails to load. There is no error or anything.
Running it simply opens a blank page in Firefox. In Chrome, it will give a 404 error after a security warning. I delete that one specific file and the application starts again.
I found this issue: View Component Loading Issue on Production ASP.NET Core
Moved Pages/Shared/Components/ to Views/Shared/Components. The problem persists.
The View Component breaks the application in Linux, even if the View Component is not being reference at all.
How can I solve this? (other than opening it in Windows)
I got .NET 6 installed, and I'm testing this from a clean project created from template.
OS: Garuda Linux (arch-based)
IDE: JetBrains Rider
Components/ProductBox.cs contains
public class ProductBox : ViewComponent
{
public IViewComponentResult Invoke() => View();
}
Components/ProductBox/Default.cshtml is completely empty

After flipping back-and-forth between the base project, a first blank project template with files copied over, and a 2nd blank project with files copied over... the View Component started to work somewhere along the lines. Got no clue where. There'sFOUND THE PROBLEM after having another problem preventing from bootingpushing the main project in Linux thoughbuild to production.
But then WebApplication1 would boot with all the same times. Started paying attention to any hidden files, likeIn Properties/launchSettingsappsettings.json. In the end; The entire application runs in WebApplication1 with all the same files, and original one still doesn't run, even after deleting obj/bin folders. Just renamed WebApplication1 to the main project name
I was facing 2 problems though. One with View Components giving a blank page, and one with failed connection.
Found the 2nd problem after having another problem pushing the build to production.
In appsettings.json
"Kestrel": {
"EndPoints": {
"Http": {
"Url": "http://localhost:5003"
}
}
}
If that configuration is present, it works in Visual Studio but fails in JetBrains Rider!
Without it; it fails to run on the server.
The solution is to move it to appsettings.Production.json.

Related

MVC Project published in third party hosting - throws error

I created an App in VS 2017. It has a SQL Database (Entity Framework connected) and other MVC components. in the local IIS it works without any trouble.
Assume the Project is in folder (of local machine) : MVCPrj
I have a website and it has a particular folder, in which there is a Web Forms project and that runs in the site without any trouble as well.
Assume the Project is in Folder : BaseFolderInMySite\WebFormsPrj
The following works without any trouble
http://www.mySite/WebFormsPrj/default.aspx
For testing purposes, I need to create a separate folder inside BaseFolderInMySite and I want to place the MVC project inside it.
I created that folder and published the app. I can see the files properly placed in the directory. But that site gives an error page. The old one works.
If I summarize:
The Webforms app in BaseFolderInMySite\WebFormsPrj works for http://www.mySite/WebFormsPrj/default.aspx
The MVC app in BaseFolderInMySite\MVCPrj doesn't works for http://www.mySite/MVCPrj
Here is the error message
enter image description here
Since it is saying the web,config file has the issue, I checked it. It is the line with
<authentication mode="None" />
I googled, checked thoroughly in SO and tried to get it fixed by various means and failed.
I removed the <system.web> thinking that it conflicts with the main app, which is running.
Changed the mode to Windows, Forms, ... no luck.
My question is how do I fix this.

Did not find new element in the hierarchy for item

I am trying to create a simple page for a Xamarin app but am completely unable to proceed with the most basic of steps. I check out the branch from the project repo, and attempt to add a new file. When I do so (Right clicking on folder, Add-> New Item->Content Page) I get this error:
It does actually create the .xaml file but not the .xaml.cs file to go with it. I first tried to manually create the cs file and associate it but ran into increasingly mysterious errors. Today I created them outside of VS before booting it up and both files are now present but with the dotted icon instead of a regular one and the cs file is not nested beneath the xaml file.
If I try to open my projitems file inside VS to make the association I am given the error "Specified method is not supported". If I choose to 'Open With', no screen ever pops up allowing me to choose. After this I closed down VS and edited the projitems file in notepad again and linked the xaml and cs file. This looked as though it worked but when I add it to the main TabbedPage with a simple Children.Add(new MyReviews()); it is not recognized -> The type or namespace name 'MyReviews' could not be found.
These error happen if I make my own branch based on the master or try to add a new file to the master directly. No one else in the project is having these errors.
The only thing I really did differently from the rest is try to get the emulator working for android which apparently has a lot of compatibility issues and requires older versions of the xamarin plugins. I was not able to do this and ended up uninstalling and reinstalling everything twice since I didn't touch the installer software the first time and everything stuck.
Is anyone able to help me debug these issues or know why I am encountering so many at every turn?
I've been in the exact same situation. As it turned out, the rest of my team had added Universal Windows Platform (UWP) support to their VS2017 install, and I hadn't. Running the Visual Studio Installer and adding UWP fixed this issue completely.
Of course, you might not need or want to include UWP support in any of your Xamarin apps (I didn't). It seems most likely that it's just one or two support assemblies that are mssing or wrong without the UWP support, but I haven't found the time or energy to figure out any more details.

Getting error from ASP.NET MVC 5 on Visual Studio 2017 Enterprise constantly for 'cannot move file to bin Rosalyn'

I get an error like this:
Unable to copy file "C:\GitSource\CheckRegister\packages\Microsoft.Net.Compilers.2.1.0\tools\System.Diagnostics.FileVersionInfo.dll" to "bin\roslyn\System.Diagnostics.FileVersionInfo.dll". Access to the path 'bin\roslyn\System.Diagnostics.FileVersionInfo.dll' is denied. AspNetMVCCheckRegister'
with eight errors that are similar when I am merely updating an API Controller to save a file to a location. It runs and builds fine when testing with say Fiddler and then I make changes try to build and it blows up. It is so very very strange as if I kill 'VBCSCompiler.exe' under Task Manager that will fix it.
But that is like blowing up a car to get down a road. I just am curious how or why this could be happening. I am using GitHub for a repo and wondering if it's a remnant of an item under source control that should not be. But I would not think so as most of my bin files are not under source control.
Going in as Administrator doesn't seem to fix it. It is happening when doing an ASP.NET MVC5 template with Web API or starting from scratch and adding an API. The version of my VS is 15.3.5.

Getting "The type name or alias FooController could not be resolved" on different server

Does anyone have any tips on how I might track down the root cause of this error:
The type name or alias FooController could not be resolved
I have an ASP.net MVC web application using Unity. My application runs fine locally. However, when I publish the site to a remote server, I get the error above.
I tried on two different remote servers and got the same error. However, when I published the site to a different directory on my local dev box, it works just fine. So, I copied the local working copy to the remote server(s). I get the same exact error. I re-arranged the order of the controllers in the Unity config file and the error will always show the first controller in the file. That is, if I move the type registration for BarController above FooController, the error will show:
The type name or alias BarController could not be resolved
So it appears that anytime a controller is encountered in the Unity configuration file, it fails, but only on the remote servers. It problem doesn't seam to be tied to a specified controller.
Therefore, it seams the problem is environmental. Perhaps the remote servers are missing something in the GAC, that I have on my local dev box. I ran though the references and didn't see anything new added since our last release, but I could be missing something.
Does anyone have any tips on how I can track down the root cause of this problem? The error message doesn't tell me much. I need to know why the FooController could not be resolved.
I solved the problem. I setup a development environment on one of the remote servers. I noticed a problem with one of the references in the web project. The MVC assembly needed to be fixed. So I removed and re-added it. Worked like a charm.
Looking at the change this made, here's what I saw:
The code on the left is my local dev box. It was referencing version 3.0.0.1 and the code on the right is after I fixed the reference on the remote server. It is referencing version 3.0.0.0.
It seams my local dev box had some strange version of ASP.net MVC installed. So I uninstalled it, and reinstalled from the latest published version and republished the code from the local dev build and it worked fine.
After look into this even further, this appears to be the root cause of the problem to begin with:
Windows update caused MVC3 and MVC4 stop working

Parser Error Message: Could not load type 'webmarketing'

After finishing the web application and publishing it online no matter I try I keep getting the following error, keep in mind that it runs locally as it should...
Parser Error Message: Could not load type 'webmarketing'.
I ran through that solution though supposedly I'm doing the same as the solution, yet I'm still facing the same issue...
ASP.NET Parser Error Cannot load code behind
Here is the code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace webmarketing
{
public partial class Masterpage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
string admin = (string)Session["Admin"];
if (string.IsNullOrEmpty(admin))
{
logout.Visible = false;
}
else
{
}
}
}
}
I had same problem before i just change CodeBehind to CodeFile and it worked.I remember it works in local but i had this problem after uploading.
This is normally happening when you copy files from a Web application projects to Website Project.
When you create a Web Application the Page directive is CodeBehind for the web pages.
If you create your application as Website then the Page directive is CodeFile
So if you copy from a Web application to Website the Namespace as well as the page directive will not change automatically, you should do this manually to rectify this error.
I had this error message. The problem was my .cs and aspx files were not added to the project. They were in the folder, but were not added. I solved it by adding them to the project (right click, Add). And then after I built the project, it was compiled into a dll in the bin folder. There was no need to change the text from CodeBehind to CodeFile.
what i did to solve my problem giving the same message was to go to IIS and check if it is configured as an Application or simply as a virtual directory. The App icon was just a folder icon. So i right clicked it and Manage Virtual directory > Advanced Settings > convert to Application changed the icon of virtual directory to a green earth icon. Of course the app was targeting framework 4.5, so changed App pool to 4.0 from default app pool, which was there earlier. This solved the issue for me.
But some things i did not say, 1. I am running it locally on IIS 6.1. 2. I am accessing with domain credential and not with 'pass through' authentication. Hope this helps
regarding the Inherits is should reflect the full name space with class name such as x.y.webmarketing, not the class name or the file name. to wrap it up it should look like below
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="MasterPage.Master.cs" Inherits="Lync_Billing.ui.MasterPage" %>
If your application works in your local but fails when deployed to the server, then this issue is most likely related to your IIS settings.
To resolve this, Make sure the “Enable 32-Bit application” property of the target Application pool in IIS is set to “TRUE”.
It WORKS!
I think you find the problem is you need to update the files in the BIN folder.
When you run the app it recompiles the files in the BIN folder too. Copy those up to the WEB site and that should fix the problem, it did for me. This is especially true if you create a new page that was not already there which was my case.
In case you encounter this during debugging on your Visual Studio running on a 64-bit operating system, and your application is a 32-bit, set your configuration manager to x86 (32 bit). This agrees to the previous answer to the set IIS to enable 32-bit application on 64-bit.
If you are facing this error after Hosting your Website on server make sure that you create the directory And/Or go to Hosting server -> Site Manager -> Application Starting Point ,select the proper path or folder of your uploaded Published Folder.
It resolve my same problem , I hope it will help you also.
Using VS2015, I checked "Delete all existing files prior to publish" under File Publish Options within the "Publish Web" right-click menu option and this problem went away.
For me, I rebuild the individual projects and then rebuild the entire solution.
That worked for me somehow.
Simply building the solution may not work.
I think when you "Clean" the solutions that will fix the issue.
I'm using "Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version 1.0.8. When rebuilding there was a warning about not being able to copy files into bin\roslyn. So I stopped IISExpress, deleted the bin folder and rebuild the project. There were no build warnings and the application worked fine.
Non of the mentioned answers worked for me.
My error was the same but I made the mistake and published the Debug version and not release, so make sure before Publishing your project, switch to Release, Clean and Rebuild the solution and the build!
Note: I was compiling my WebForms pages at build time.
I had aspx files not referenced in the project but were on disk and that was causing the build errors.

Categories

Resources