Nancy: Razor View Engine #using IntelliSense not working - razor

I have an IntelliSense problem with Nancy and the Razor View Engine.
I try to use the functionality of an (self-made) external library inside my razor view. Therefore I reference the dll and try to put an #using and the namespace on top of the view to get some IntelliSense-Support.
But it doesn't work. The #using can't find the dll or rather the namespace I have to put behind it.
The VS-Error I get is: "The type or namespace name 'type/namespace' could not be found (are you missing a using directive or an assembly reference?)"
It just seems to be an IntelliSense problem because the engine is able to render the view if I use the correct #using on top of the view and ignore the error message or if I have a class inside my project which inherits from IRazorConfiguration and returns the needed namespace.
Notes:
Hosting: Self-Host and/or OWIN
It works if the library is part of the same solution
This happens with with Nancy 0.22.2 as well as 0.23 and the corresponding Razor packages.
Steps to reproduce (or better: things I did):
Create a new Console Application
Install the Nancy Razor View Engine package
Reference an external dll (namespace: External)
Reference a dll which is part of the same solution (namespace: Same)
Create a new Razor View
Try: #using External -> not working
Try: #using Same -> working
I hope someone can help me even if It is not a real problem since razor is able to render the view but it's annoying :(

OK, I finally found a solution. The following answer led me to it:
https://stackoverflow.com/a/19653760/1761291
I tried it and it worked but instead of doing this its ok to only copy the external dll into the bin folder.

Related

can I use Kendo UI Grid with Nuget package Telerik.UI.for.AspNet.Core?

I am running into a strange issue. I built an ASP.net Razor project with a Kendo UI Grid. When I first built it, I made a direct reference to the Kendo.Mvc.dll, and all was good. But I need it to be referenced by a NuGet package. However, when I switch the reference, it no longer recognizes Html.Kendo().Grid. I have tried moving the namespace reference from the Views/Web.config to the main web.config as well, but no luck. The error message I get is:
Compiler Error Message: CS1061: 'HtmlHelper' does not contain a definition for 'Kendo' and no extension method 'Kendo' accepting a first argument of type 'HtmlHelper' could be found (are you missing a using directive or an assembly reference?)
Is it possible that something in the larger NuGet Telerik.UI.for.AspNet.Core package is overriding something in the base Kendo.Mvc.dll? Or does my namespace need to be moved somewhere else? Any help would be appreciated.
Kendo UI Core does not include certain widgets, the Grid being one of them, nor does it include the server side wrappers so the Razor helpers such as Html.Kendo().Grid will not work. Hence using the Core package available via NuGet cannot be used for what you need. So the simple answer to your question is, unfortunately, no.

ServiceStack Razor Intellisense not working in SelfHost

I have ServiceStack.Razor referenced.
Following razor file works great:
#model ServiceStack.Host.Operation
#Model.Name
but IntelliSense (and R# code analysis) shows error: "Cannot resolve symbol 'model'"
Referencing Microsoft.AspNet.Mvc makes Intellisense work, but Razor pages are not compiled.
This is because ServiceStack.Razor contains System.Web.Razor assembly version 3.0.0 and Microsoft.AspNet.Mvc requires a 3.2.3, one is overwritten by other and assembly load exceptions occur.
Tried to follow this answer:
ServiceStack turn on Razor intellisense support without MVC
and add Web.config but this gives me different error:
"Cannot access private field 'model' here"
How to make Intellisense work without breaking application?
Unfortunately VS.NET 2015 designer doesn't properly support editing Razor pages in Self-Host (i.e. non ASP.NET Projects) so you wont be able to get rid of all the designer errors, although you can minimize the issues by first adding a Web.config with the Razor configuration, here's a Web.config template you can use, you'll need to replace $safeprojectname$ with the namespace of your project. The Web.config have no effect to the behavior of non Web projects, it's just use to provide hints to VS.NET intellisense which is coupled to ASP.NET Web projects.
Instead of #model you'll want to use the more explicit:
#inherits ViewPage<ServiceStack.Host.Operation>
These both do the same thing, but the designer is happier with the explicit #inherits.

Xamarin razor template inherit breaks Intellisense in editor

When using #inherits in a razor template view in portable library for a Xamarin-based hybrid app, the intellisense is broken such that it red-underlines the functions provided by the base view class such as "#Model". I have a fresh update of the Xamarin tools (4.1.0.530).
The first fix here doesn't apply: Xamarin WebView - No Intellisense in razor
I'm not sure if this is related, but the RazorTemplateProcessor doesn't seem to be reading my web.config such that I also have to reference class names fully qualified, or the generated code-behind file will have a compile error. How to get it to support web.config?

Razor “The type or namespace name 'x' could not be found” Error. Compile Only

I have run into an issue with my razor templates.
In the the template I am using it has two using references at the top of the file.
#using Framework;
#using Bundler;
Both of these reference internal namespaces in my project that are both included as refs in the project that is compiling the template. However the bundler reference fails with the classic.
Unable to compile template. The type or namespace name 'Bundler' could not be found (are you missing a using directive or an assembly reference?)
This to me is a bit weird because if I parse the template instead it works fine.
So it is really only a performance issue but as it doesn't effect the site from running correctly.
Is there any reason why compiling (Razor.Compile(content, Name);) fails when parsing (Razor.Parse(content, model, this.Name)) Doesn't?
Thanks for the help :)
So I found a solution.
If I call a method in the namespace before the razor.Compile it seems to fix the issue.
I created a method called helloDll anywhere inside of the namespace that is failing.
public static void helloDll(){}
I call this before my compile
Bundler.cvStyleBundle.helloDll();
Razor.Compile(content, Name);
No more error :)
I think it has something to do with just in time dll loading and the fact that the dll is not loaded at the time of compile and because the compile happens in some weird lovely funky way it doesnt load the dll rather it just grabs all existing ones from the project :)

Found conflicts between different versions of the same dependent assembly.MVC3 -> MVC4 / EF4 -> EF5

The question is how to resolve conflicts between versions of assemblies in my project that was upgraded to MVC4 and EF5?
The problem is manifest in the fact that my controllers and models can include System.Data.Objects, but now my views.
I am using MVC 4, my project was upgraded from MVC 3.
Entity Framework is version 5.
I have a controller that is able to use objectcontext from System.Data.Objects.
My Usings:
using System.Data.Objects;
using System.Data.Entity;
When I try to include the using in the view form System.Data.Objects, I get :
CS0234: The type or namespace name 'Objects' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
I am targeting .net 4.5
My Build Displays this message:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1561,5): warning MSB3247: Found conflicts between different versions of the same dependent assembly.
You can build your solution in diagnostic mode to get more detailed information about the error.
Open the VS Options dialog (Tools > Options), navigate to the "Projects and Solutions" node and select "Build and Run". Change the MS Build project build output verbosity to Diagnostic.
Have a look here.
If you look at the build message, it states the 4.0 version of the .net framework is referenced... Is there a setting in your project file or web/app.config specifying a conflicting version of the .net framework?
Are you familiar with fuslog? you can set it up to log all assembly bindings that .net is doing while running your application. You should then be able to see detailed information on what is getting bound when. If you still can't figure it out, you can always do a binding redirect on that .dll in the web.config.
http://msdn.microsoft.com/en-us/library/eftw1fys.aspx -- binding redirects
http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.71).aspx -- fusion log viewer
Set up fusion logger and take a look at what the output is. If you don't get an answer from that, try the binding redirect (which would give you at least a temporary solution).
In the directory I was publishing to, there was a folder named aspnet_client. I moved it (instead of deleting it), republished, and it worked. I'm not sure why that folder decided to give me trouble out of the blue.