开发者

Compiler Error Message: CS0246 in ASP.NET MVC App

I have a new solution that is an ASP.NET MVC 2.0 application. I have added a porject to the solution which is a console application. The console namespace is foo, and it has a data repository called FooDataRepository which is a public class. I also have a public class in the foo namespace called FooLinkList, which is also public.

In the ASP.NET application, in the HomeController, I have added "using Foo" an everything compiles fine.

It's my Index.aspx that has the problem. When I run the app, I get the following error:

Description: An error occurred during the compilation of a resource required to service this request. Pl开发者_如何学编程ease review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0246: The type or namespace name 'TweetLinkTimer' could not be found (are you missing a using directive or an assembly reference?)

Line 1:  <%@ Import Namespace="Foo" %>
Line 2:  <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<FooLinkList>>" %>

I have added a reference to Foo via Visual Studio, and have the "using" directive on the .CS files. I am not sure what else I have to do here. Foo.exe is in the bin directory for my ASP.NET MVC application.

The reason I have done this is because I don't want to have to copy over my data respository, which acts as the model for the MVC application, and that repository was already created for the console application. Any ideas as to what to do?


I have a feeling this isn't "right", but I can get it to work by doing a mixture of what the exception message says and adding an Assembly directive to the View.

<%@ Assembly Name="Foo" %>
<%@ Import Namespace="Foo" %>
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<FooLinkList>>" %>


I can reproduce the problem and I'm looking at the details but I think the issue stems from trying to reference a Console application as a library and the output it generates. Intuitively you'd think it would work.

Solution 1: You can get around the problem by creating a shared "Class Library" application type, storing FooDataRepository and FooLinkedList there, and having both the MVC 2 and Console application reference that project instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜