I'm currently trying ASP.NET Core 1.0 RC2. I've created it as a .NET Framework project (as opposed to a .NET Core project) and added references to our Models
library, using .NET Framework 4.5, via a project reference:
"frameworks": {
"net46": {
"dependencies": {
"Project.Core": {
"target": "project"
},
"Project.DataAccess": {
"target": "project"
},
"Project.Encryption": {
"target": "project"
},
"Project.Models": {
"target": "project"
},
"Project.Resources": {
"target": "project"
}
}
}
},
Now when adding a model directive to my view, the following error occurs:
@model System.Collections.Generic.List<Project.Models.User>
The type or namespace name 'Project' could not be found (are you missing a using directive or an assembly reference?)
public class _Views_Home_Index_cshtml : Microsoft.AspNetCore.Mvc.Razor.RazorPage<System.Collections.Generic.List<Project.Models.User>>
The type or namespace name 'Project' could not be found (are you missing a using directive or an assembly reference?)
public Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<System.Collections.Generic.List<Project.Models.User>> Html { get; private set; }
It also displays in intellisense: Cannot resolve tag 'Project.Models.User' and Cannot resolve symbol 'model'
I have added a project reference, added a using statement... Still this error occurs. Why is that?
This is a bug in RC2 with an open issue. A workaround in the issue discussion that works for me is:
services.AddMvc()
.AddRazorOptions(options =>
{
var previous = options.CompilationCallback;
options.CompilationCallback = context =>
{
previous?.Invoke(context);
context.Compilation = context.Compilation.AddReferences(MetadataReference.CreateFromFile(typeof(MyClass).Assembly.Location));
};
});
In your example, you'd need to do this for Project.Models.User
.
Not sure whether 4.6.1 and Update 2 is needed for both projects, I've only tried with that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With