Nancy.ViewEngines.ViewNotFoundException: Unable to locate view 'Index' - c#

I know this question was asked month before but was never answered.
My program starts normally but after returning View["Index", blogPost] it could not find the Index.cshtml and raises an exception.
Get["/"] = parameters =>
{
var blogPost = new BlogPost
{
Id = 1,
Title = "Test",
Content = "Lorem ipsum...",
Tags = { "c#", "aspnetmvc", "nancy" }
};
return View["Index", blogPost];
};
Exception:
Nancy.RequestExecutionException: Oh noes! ---> Nancy.ViewEngines.ViewNotFoundException: Unable to locate view 'Index'
Currently available view engine extensions: sshtml,html,htm,cshtml,vbhtml
Locations inspected: views/Home/Index-de-DE,views/Home/Index,Home/Index-de-DE,Home/Index,views/Index-de-DE,views/Index,Index-de-DE,Index`

If the answer giving my Christian doesn't help you like it didn't help me there is a alternative issue/solution. The alternative is to make sure that the file you created is being copied to the output directory at compile time. You can check it under the properties tab like shown bellow

The exception message tells you where Nancy tried to look for the view:
Locations inspected: views/Home/Index-de-DE,views/Home/Index,Home/Index-de-DE,Home/Index,views/Index-de-DE,views/Index,Index-de-DE,Index
The exception also tells you which file extensions Nancy tried to look for:
Currently available view engine extensions: sshtml,html,htm,cshtml,vbhtml
That is Nancy looks for a file in one of the listed locations with one of the listed extensions.
So the question is if your index.cshtml is in one the listed folders. If not you can either move it there or set up a view location convention.

We ran into this error and noticed the .cshtml file it was complaining about was not getting copied to the server. The solution was in Visual Studio, in the file's properties, we changed the Build Action to Content. This forces it to get included in the build artifacts that are deployed to the server. Similarly you could change the Copy to Output Directory to Always as others have mentioned; either works, but I find setting the file as Content a bit more informative.
In your case, I'm guessing you have an Index.cshtml file which you need to set this property on.

Related

AirConsole View Manager is not defined after uploading for testing

I'm currently building a game, when I tried uploading it to AirConsole the game gives me a error in the preview.
Has anyone had this problem before?
"Uncaught ReferenceError: AirConsoleViewManager is not defined".
var airconsole = new AirConsole({ "orientation": "landscape", "device_motion": 10 });
var vm = null;
window.onload = start;
airconsole.onReady = function () {
//THE LINE UNDER CRASHES
vm = new AirConsoleViewManager(airconsole);
};
ReferenceError: AirConsoleViewManager is not defined
at AirConsole.airconsole.onReady (https://storage.googleapis.com/XXX.xxxxxxx.xxxx.cdn.airconsole.com/2018-05-24-16-33-25/controller.html:125:22)
at AirConsole.onPostMessage_ (https://www.airconsole.com/api/airconsole-latest.js:1053:8)
at https://www.airconsole.com/api/airconsole-latest.js:969:8
Thank you very much :)
I assume you got the information about AirConsoleViewManager from here (GitHub).
I can't tell for sure because you haven't linked the entire file, but you need to download the airconsole-view-manager.js and include that in your controller script.
The example from the previously linked GitHub example is kind of weird because it doesn't include the JS file in it. Most likely the reason for this is that they assume (which you should never do as a developer) people know it already.
EDIT: Actually, they do include the file but it's not done in JS file, it's in HTML file:
<script type="text/javascript" src="airconsole-view-manager.js"></script>
I do not know what the problem was, but after cleaning the build and transfering code over to another project, then uploading again it worked!

MVC using VS2017: The name 'Model' does not exist... and other errors when I create a new controller

Hello to everybody at Stack Overflow and please pardon me if I am missing anything here!
I am studying ASP.NET to prepare myself for an internship. To this end, I am following along with a Microsoft Virtual Academy course entitled "Introduction to ASP.NET Core with Visual Studio 2017".
Specifically, I am watching the video "Routing and MVC", and am now at where Scott H. adds a new folder "Tickets" to "Views" (at the 21:20 minute mark). I have been following his instructions exactly up to this point, and the new index.cshtml file was created under Views/Tickets (which I will explain shortly). However, as this screenshot shows, there is a red squiggly line under ViewData with the associated error
The name 'ViewData' does not exist in the current context
The image shows a total of 8 errors, but I have not made any changes to the file. Neither has Scott in the video up to this point and he is not getting any error with ViewData. What's more, he was able to rename View.cshtml to index.cshtml but it does not work for me (hence I used this name when I created my file, and find that renaming to any other string is discarded without any error except those in the error list).
My situation is similar to the one described in this post in that it is already there by default without needing to do anything, so I suspect it could be attributed to how VS2017 has been set up.
UPDATE!!!
I have continued with the video, seeing no runtime error, and am now nearing the end. By 32:20, Scott H. had added this code to the TicketController class:
public IActionResult Index()
{
// GO TO THE DATABASE!
// GET SOME MODELS (STUFF)
var s = new Seat() { Location = "Orchestra" , Price = 300.00 };
return View();
}
public string Index2()
{
return "Hello from Tickets!";
}
Then he modified index.cshtml to reference using #Model as such:
#model WebApplication3.Models.Seat
#{
ViewData["Title"] = "index";
}
<h2>My New Tickets View</h2>
#Model.Location for only #Model.Price!
When I enter the same code into my editor the squiggly lines appear under #Model with the same error as ViewData:
The name 'Model' does not exist in the current context
Executing the code and navigating to the /tix page does not show Orchestra for only 300! on the webpage as shown in the video, but on my side I get this Internal Server Error instead. As before, I have checked my code and it matches what I see in the video.
You are missing to pass the model to View. Please pass the 'Seat' model object as shown below.
public IActionResult Index()
{
// GO TO THE DATABASE!
// GET SOME MODELS (STUFF)
var s = new Seat() { Location = "Orchestra" , Price = 300.00 };
return View(s);
}

WebApi - How to include relative paths for included App_Data XML files?

Question Background:
I have a WebApi controller who's logic code relies on reading data contained in a number of XML files. These XML files have been included in the App_Data folder of the WebApi project.
The Issue:
I'm trying to use the relative path of the XML files in the following way:
[System.Web.Http.HttpGet]
public string CallerOne()
{
string docOne = #"~\AppData\DocOne.xml";
string poll = #"~\AppData\Poll.xml";
var response = _Caller.CallService(docOne, poll);
return ConvertXmlToJson(response);
}
When running the WebApi code and calling the Url to the CallerOne method I receive the following error:
An exception of type 'System.IO.DirectoryNotFoundException'
occurred in System.Xml.dll but was not handled in user code
Additional information: Could not find a part of the path
'C:\Program Files (x86)\IIS Express\~\AppData\FPS.xml'.
I also want to eventually publish this to Azure and include these files.
How can I use the relative path to read in the XML files in the App_Data folder?
Ended up finding the answer.
The following is needed to read the relative paths in a WebApi project:
var fullPath = System.Web.Hosting.HostingEnvironment.MapPath(#"~/App_Data/yourXmlFile.xml");
As jdweng inferred several months back, Environment.GetEnvironmentVariable("AppData") would seem to be the preferred method. The OP's auto-accepted answer and that give quite different results. For example, using both of those in my project, I get:
C:\\Projects\\PlatypusReports\\PlatypusReports\\App_Data\\yourXmlFile.xml
...for the OP's long-winded code, namely this:
var fullPath = System.Web.Hosting.HostingEnvironment.MapPath(#"~/App_Data/yourXmlFile.xml");
...and this:
C:\\Users\\cshannon\\AppData\\Roaming
...for jdweng's code, to wit:
string appData = Environment.GetEnvironmentVariable("AppData");
OTOH, this code:
string appDataFolder = HttpContext.Current.Server.MapPath("~/App_Data/");
returns:
C:\\Projects\\PlatypusReports\\PlatypusReports\App_Data\
So it's very similar in results (if not methodology) to the first example above. I actually got it from a question I asked almost two years ago, which I had forgotten about.
I'm not positive if jdweng's approach would work as expected once the app is deployed on a server, but I have much more confidence in it than the other approaches.
Can anyone verify?
UPDATE
The accepted answer here has 237 upvotes at time of typing, so seems pretty reliable, albeit 6 years old (42 in dog years, which may be a good sign).
Your approach is fine. You just had some tpying error,
You wrote
string docOne = #"~\AppData\DocOne.xml";
But it should have been
string docOne = #"~\App_Data\DocOne.xml";

Continued MVC Area 404 error. At wit's end

[EDITED] Code and solution edited as per suggestions from forum members. I've corrected the name of the controller. It was incorrect. The corrected name is shown in the updated solution file snapshot. I'm getting a new error. The new error is shown in the updated snapshot. It's still a 404-typpe error.
As for the "post your routing edits" type of comments, please note the original statement that Visual Studio has done all the wireup for me. It's my understanding that if I'm right-clicking and adding controllers, views, etc. from the IDE that I do not need to go in and do additional wireup behind the scenes. This seems to defeat the whole purpose of an easy-to-implement interface. Please correct me if I misunderstand. Thanks.[END EDIT]
I asked for help with this problem earlier and nobody was able to solve. I've retooled the solution, deleting everything involved and starting over, in hopes it would relieve the problem. I'm still stuck. This is a very simple thing according to all I've read on MVC but I have been dead in the water for over a week. Would appreciate help on this. My retooled code appears below. I've looked at similar errors reported in these forums and found no help.
Please note that all the wireup was done completely by Visual Studio: I have not modified any generated code behind the scenes other than adding an Action method to the controller. In other words, everything was generated by right-clicking in VS and selecting "Add" and following the prompts for views, controllers, etc.
I have a view in one area, "UserAccount", that uses Html.ActionLink() to generate a link to a view in another area, "DocumentUploaderNew". A screen snapshot of the markup is below. When I click the rendered button in IE though, I get an error that seems like a "404" error. The view IS there though.
This has GOT to be an embarrassingly easy answer. I'm ready to eat humble pie. What is it???
That's because your controller is actually named FileUpload, yet you're trying to use the controller name FileUploaderNew (looks like you're getting confused with your action and controller names).
Try this:
#Html.ActionLink("Upload New", "FileUploaderNew", new { controller = "FileUpload", area = "DocumentUploaderNew" }, new { #class = "btn btn-info" })
The reason this is failing is because your view FileUploaderNew.cshtml is at the root of the Views folder and not in a folder itself (either one with the name of the controller or the shared view folder). If you look at the paths that MVC is checking in your error screenshot, you can see it never checks the path ~/Areas/DocumentUploaderNew/Views/FileUploaderNew.cshtml
There are numerous fixes you can do to fix this problem (choose one, not all three).
Create a folder in your Views folder called FileUploaderNew and move your FileUploaderNew.cshtml file into that folder (basically, you create a subfolder in the views folder with the name of a matching controller. The view engine will look for that folder when returning Views from that controller).
Move the FileUploaderNew.cshtml file into the Shared folder inside the Views folder (you can see it in your screenshot).
Specify exactly where your view is when you call Return View():
return View("~/Areas/DocumentUploaderNew/Views/FileUploaderNew.cshtml");
Depending on what your route is, it'll either be
#Html.ActionLink("Upload New", "FileUploaderNew", new { controller = "FileUpload/FileUploaderNew"}, new { #class = "btn btn-info" })
or
#Html.ActionLink("Upload New", "FileUploaderNew", new { controller = "DocumentUploader/Controllers/FileUpload/FileUploaderNew"}, new { #class = "btn btn-info" })
The jist is you have to post to the controller's path (not name) and when you don't it can't find it & you get a 404. In a default MVC file structure, I believe this is automated (controllers in the controllers directory auto map without paths), but that's not your file structure.
Also, I'm answering this never having used areas, not sure if those factor into the equation, but a quick read seems to indicate they're more for locking down paths than finding them.

BizTalk Dynamic Disassembler Problems - The body part is NULL

I started with the solution here http://social.technet.microsoft.com/wiki/contents/articles/20547.biztalk-server-dynamic-schema-resolver-real-scenario.aspx
which matches my scenario perfectly except for the send port, but that isn't necessary. I need the receive port to choose the file and apply a schema to disassemble. From their the orchestration does the mapping, some of it custom, etc.
I've done everything in the tutorial but I keep getting the following error.
"There was a failure executing the receive pipeline... The body part is NULL"
The things I don't get from the tutorial but don't believe they should be an issue are:
I created a new solution and project to make the custompipeline component (reference figure 19) and thus the dll file. Meaning it is on it's own namespace. However, it looks like from the tutorial they created the project within the main biztalk solution (ie the one with the pipeline and the orchestration) and thus the namespace has "TechNetWiki.SchemaResolver." in it. Should I make the custompipeline component have the namespace of my main solution? I'm assuming this shouldn't matter because I should be able to use this component in other solutions as it is meant to be generic to the business rules that are associated with the biztalk application.
The other piece I don't have is Figure 15 under the "THEN Action" they have it equal the destination schema they would like to disassemble to but then they put #Src1 at the end of "http://TechNetWiki.SchemaResolver.Schemas.SRC1_FF#Src1". What is the #Src1 for?
In the sample you've linked to, the probe method of the pipeline component is pushing the first 4 characters from the filename into a typed message that is then passed into the rules engine. Its those 4 characters that match the "SRC1" in the example.
string srcFileName = pInMsg.Context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties This link is external to TechNet Wiki. It will open in a new window. ").ToString();
srcFileName = Path.GetFileName(srcFileName);
//Substring the first four digits to take source code to use to call BRE API
string customerCode = srcFileName.Substring(0, 4);
//create an instance of the XML object
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(string.Format(#"<ns0:Root xmlns:ns0='http://TechNetWiki.SchemaResolver.Schemas.SchemaResolverBRE This link is external to TechNet Wiki. It will open in a new window. '>
<SrcCode>{0}</SrcCode>
<MessageType></MessageType>
</ns0:Root>", customerCode));
//retreive source code in case in our cache dictionary
if (cachedSources.ContainsKey(customerCode))
{
messageType = cachedSources[customerCode];
}
else
{
TypedXmlDocument typedXmlDocument = new TypedXmlDocument("TechNetWiki.SchemaResolver.Schemas.SchemaResolverBRE", xmlDoc);
Microsoft.RuleEngine.Policy policy = new Microsoft.RuleEngine.Policy("SchemaResolverPolicy");
policy.Execute(typedXmlDocument);
So the matching rule is based on the 1st 4 characters of the filename. If one isn't matched, the probe returns a false - i.e. unrecognised.
The final part is that the message type is pushed into the returned message - this is made up of the namespace and the root schema node with a # separator - so your #src1 is the root node.
You need to implement IProbeMessage near to class
I forgot to add IProbeMessage in the code of article. It is updated now.
but it is there in sample source code
Src1 is the the root node name of schema. I mentioned that in article that message type is TargetNamespace#Root
I recommend to download the sample code
I hope this will help you

Categories

Resources