Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Using @inherits and @model together gives intellisense errors #3243

Closed
rynowak opened this issue Oct 1, 2015 · 14 comments
Closed

Using @inherits and @model together gives intellisense errors #3243

rynowak opened this issue Oct 1, 2015 · 14 comments
Assignees
Milestone

Comments

@rynowak
Copy link
Member

rynowak commented Oct 1, 2015

Create a 'base' page

    public abstract class BasePage<TModel> : RazorPage<TModel>
    {
        public IHtmlContent DoThings(object thing)
        {
            return new HtmlString(thing.ToString());
        }
    }

Add this to _ViewImports.cshtml

@inherits Beta8.Web.BasePage<TModel>

You'll get squiggles and errors. Eventually the line will stop being colorized by intellisense (try building, and reopening the file).

image

@danroth27
Copy link
Member

@rynowak Where is the @model?

@rynowak
Copy link
Member Author

rynowak commented Oct 2, 2015

In Index.cshml - the page renders corectly, these errors come from intellisense.

@Eilon
Copy link
Member

Eilon commented Oct 5, 2015

I think we intended to ask: what does the @model look like? Just some random POCO class or something esoteric?

@rynowak
Copy link
Member Author

rynowak commented Oct 5, 2015

Just a POCO

@danroth27 danroth27 added this to the 6.0.0-rc1 milestone Oct 5, 2015
@pranavkm
Copy link
Contributor

pranavkm commented Oct 7, 2015

The change made as part of #3185 didn't work because we do a case sensitive comparison to determine if a file is a _ViewImports (https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.Razor.Host/MvcCSharpCodeGenerator.cs#L53-L56). However the file path that is passed in from VS is all lower case. Switching to a case insensitive comparison should be fine since this is a design time scenario that primarily affects VS.

@Eilon
Copy link
Member

Eilon commented Oct 8, 2015

Why is VS changing the case of the file? That doesn't sound right...

@pranavkm
Copy link
Contributor

pranavkm commented Oct 8, 2015

@Eilon confirmed with @ToddGrun - it's intentional behavior.

@Eilon
Copy link
Member

Eilon commented Oct 8, 2015

Umm, that still sounds wrong, no? Intentional or otherwise... The casing of files matters, even on Windows, because NTFS is a case-preserving file system.

@pranavkm
Copy link
Contributor

pranavkm commented Oct 8, 2015

If you say so. @ToddGrun, any chance we could fix this in tooling so that the path casing is preserved?

@ToddGrun
Copy link

ToddGrun commented Oct 8, 2015

We could, it's just a bit of an annoyance as the case we were addressing is due to the git scc provider in VS giving us back the wrong casing. It's surprisingly non-trivial to get the proper case, but we could do that.

@pranavkm
Copy link
Contributor

pranavkm commented Oct 8, 2015

Seeing that this is a design time behavior, I think its ok for us to be case invariant (the fix I made). The worst thing that happens is that you get an extra using TModel = object; in your design time generated code.

@Eilon
Copy link
Member

Eilon commented Oct 8, 2015

I would think that if there's a problem with the git scc provider that the casing stuff could be kept just for that area of the code, no? What is the relationship between code that interacts with scc providers and code use for the design time host?

@ToddGrun
Copy link

ToddGrun commented Oct 8, 2015

We don't interact with it directly. If I'm remembering correctly, the scc provider notifies the diff window of the file name (incorrectly cased). This case is then passed into when our razor document is created and thus we used to just pass this name over directly to the host. We get the project root from a different mechanism which appears to always return back correct casing. I started investigating modifying the path to get the correct case, but at the time (after consulting with Taylor), it was determined that mvc/razor only needed consistent casing for this scenario, not necessarily correct casing.

@hikalkan
Copy link

hikalkan commented Jun 23, 2016

This is still a problem for me. While it's actually working when I run the application, it has some intellisense problems.

I've a base class like that:

    public abstract class MyDemoRazorPage<TModel> : RazorPage<TModel>
    {
        //...some methods...
    }

First intellisense problem is in _ViewImports.cshtml:

inherit-01

TModel is red, as you see.

Second one is in views. It does not regocnize base methods. But it properly works when I run the application.

Do you have an idea? Can that be related to Resharper (I'm using Resharper Ultimate 2016.2 EAP 2, built on 02 July)

Also note that I'm using latest RTM of AspNet Core (from here: https://dotnet.myget.org/gallery/aspnet1) and just upgraded to latest .net cli.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants