【发布时间】:2013-07-09 09:39:31
【问题描述】:
组装 1
这是我的项目结构(我从嵌入式资源中提供内容):
Common_Assembly.dll
Css
Common.css
Views
Shared
_Layout.cshtml
这也有一个名为 Model.cs 的类,它本质上只是:
public class Model
{
public string Title {get; set; }
}
_Layout.cshtml
@model MyNameSpace.Model
<html>
<head>
<script language="javascript" href="css/common.css"></script>
<title>@Model.Title</title>
</head>
<body>
@RenderBody
</body>
</html>
组装 2
然后我有第二个程序集(它引用了上面的那个)并且是实际托管 Web 服务的那个:
Concrete_Assembly.dll
Views
Index.cshtml
这有一个名为IndexResponse 的类,它派生自另一个程序集中的Model。
public class IndexResponse : Model
{
}
Index.cshtml
@Model MyOtherNameSpace.IndexResponse
<p>Test</p>
现在,问题来了。如果我删除 @Model 行,一切正常,我会在另一个 DLL (I use a custom VirtualPathProvider to locate resources across multiple Dlls) 的布局页面中看到我的索引页面。但是,如果我尝试在索引页面中使用IndexResponse 作为模型,我会得到HttpCompileException。由于它是由外部组件抛出的,我实际上并不知道异常消息是什么(我使用服务堆栈二进制文件)。
起初我想知道是不是因为模型类与布局的类不同(即使它派生自它)。为了测试该理论,我创建了一个派生自 Model 的 TestModel 类(放置在公共程序集中),并使用了它 - 它运行良好。
这让我相信这是因为 IndexResponse 在辅助程序集中 - 但无法确定,因为我看不到错误。
任何帮助将不胜感激!
编辑
为了完整起见,这里是实际的 WebService 方法。我认为这里没有任何问题,因为当我进行其他测试时它运行良好(使用 TestModel 代替)。
public IndexResponse Any(Index index)
{
return new IndexResponse() { Title = "Test Title" };
} // eo Any
编辑 2
对所有编辑表示歉意。此外,无论如何我可以掌握这个异常或处理它,以便我可以查看错误?抓住并显示它会很好 - 否则将这些页面开发为嵌入式资源就像拔牙一样:)
编辑 3
在遵循 Mythz 的一些建议,并将正确的命名空间添加到 Razornamespaces 配置中后,我终于控制了它抛出的错误:
+ $exception {"(0): error CS1704: An assembly with the same simple name 'Concrete_Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null has already been imported. Try removing one of the references or sign them to enable side-by-side."} System.Exception {System.Web.HttpCompileException}
`
【问题讨论】:
标签: c# .net servicestack razor-2