获得一个HttpCompileException在ServiceStack剃刀视图(自托管) [英] Getting a HttpCompileException in ServiceStack Razor view (Self hosted)
问题描述
组件1
这是我的项目结构(我服了,从嵌入的资源内容):
This is my project structure (I serve up content from embedded resources):
Common_Assembly.dll
Css
Common.css
Views
Shared
_Layout.cshtml
此也有一类称为Model.cs,它本质上只是:
This also has a class called Model.cs, which is essentially just:
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服务的一个:
I then have a second assembly (which references the one above) and is the one that actually hosts the web-service:
Concrete_Assembly.dll
Views
Index.cshtml
这有一类叫做 IndexResponse
派生自型号
中的其他组件。
This has a class called IndexResponse
that derives from Model
in the other assembly.
public class IndexResponse : Model
{
}
Index.cshtml
@Model MyOtherNameSpace.IndexResponse
<p>Test</p>
现在,问题。如果我删除 @Model
线,一切正常,我看到其他DLL的布局页面内我的索引页(<一href="http://stackoverflow.com/questions/17475547/servicestack-razor-self-hosted-with-embedded-images-css">I使用自定义的VirtualPathProvider定位资源跨多个DLL )。但是,如果我尝试并使用 IndexResponse
作为索引页的典范,我收到了 HttpCompileException
。因为它是由外部组件抛出我真的不知道该异常信息是什么(我使用的服务堆栈二进制文件)。
Now, the problem. If I remove the @Model
line, everything works correctly and I see my index page within the layout page of the other DLL (I use a custom VirtualPathProvider to locate resources across multiple Dlls). However, if I try and use the IndexResponse
as a model in the index page, I get a HttpCompileException
. As it is thrown by an external component I do not actually know what the exception message is (I use service stack binaries).
起初,我不知道是不是因为模型类是从布局的类不同的(即使它提炼出来)。为了测试这个理论我创建了一个 TestModel
类派生自型号
(放置在普通装配),并用该 - 它工作得很好
At first I wondered if it was because the model class was different from the layout's class (even though it derives from it). To test that theory I created a TestModel
class that derives from Model
(placed IN the common assembly), and used that - it worked fine.
这使我相信这是因为 IndexResponse
是在二级组装 - 但不能肯定,因为我不能看到错误
This leads me to believe it is because the IndexResponse
is in the secondary assembly - but can't be sure because I can't see the error.
任何帮助将是AP preciated!
Any help would be appreciated!
修改
有关完整,这里是真正的WebService的方法。我不相信什么是错在这里,因为它工作得很好,当我做了我的其他测试(使用 TestModel
代替)。
For completeness, here is the actual WebService method. I do not believe anything is wrong here as it worked fine when I did my other tests (using TestModel
instead).
public IndexResponse Any(Index index)
{
return new IndexResponse() { Title = "Test Title" };
} // eo Any
编辑2
道歉所有的编辑。此外,有反正我能掌握此异常或处理它,所以我可以看看这个错误吗?这将是很好赶上这一点,并显示它 - 否则开发这些网页嵌入的资源将是就像拔牙一样:)
Apologies for all the edits. Furthermore, is there anyway I can get hold of this exception or handle it so I can have a look at the error? It would be nice to catch this and display it - otherwise developing these pages as embedded resources is going to be like pulling teeth :)
修改3
下面从Mythz一些建议,并到Razornamespaces配置中添加正确的命名空间后,我终于得到了缓缴的错误,它抛出:
After following some suggestions from Mythz, and adding the correct namespaces in to the Razornamespaces configuration, I have finally gotten hold over the error that it is throwing:
+ $异常{(0):错误CS1704:用相同的简单名称Concrete_Assembly,版本= 1.0.0.0集会,文化=中性公钥=空已经导入尝试去除其中一个引用或签名,以使并排端。} {System.Exception的System.Web.HttpCompileException}
`
推荐答案
如果您还没有,你应该添加你使用任何组件的的app.config
,如:
If you haven't already you should add any assemblies you're using to your app.config
, e.g:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc,
Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="ServiceStack.Razor.ViewPage">
<namespaces>
<add namespace="ServiceStack.Html" />
<add namespace="ServiceStack.Razor" />
<add namespace="ServiceStack.Text" />
<add namespace="ServiceStack.OrmLite" />
<add namespace="Concrete_Assembly" />
<add namespace="Common_Assembly" />
</namespaces>
</pages>
</system.web.webPages.razor>
另外,请禁用ASP.NET网页:
Also disable ASP.NET webpages:
<appSettings>
<add key="webPages:Enabled" value="false" />
</appSettings>
见<一href="https://github.com/ServiceStack/RazorRockstars/blob/master/src/RazorRockstars.SelfHost/app.config"相对=nofollow> RazorRockstars自主机的app.config 的参考。
这篇关于获得一个HttpCompileException在ServiceStack剃刀视图(自托管)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!