开发者

Compile Error Unless .svc File Is Open in VS 2010

I have a very simple .svc file (VSTOService.svc) for some web services being offered up in VSTO:

<%@ ServiceHost Language="C#" 
    Debug="true" Service="MyCompany.Communications.VSTOService" 
    Factory = "MyProject.Communications.IocServiceHostFactory" 
    CodeBehind="VSTOService.cs"%>

This file is in a Communications project that is one of 12 projects in my solution. As long as the file is open in the VS source editor, the entire solution compiles just fine. If, 开发者_C百科however, the file is closed, I get compile errors.

When I compile the Communications project by itself, I have the same problem, with two compile errors: Keyword, identifier, or string expected after verbatim specifier: @

A namespace cannot directly contain members such as fields or method

Clearly, I haven't specified a namespace in the .svc file, but just in case, I also checked the two classes in the project. They are fine. I also tried to remove the space between the @ and the "ServiceHost" but VS insists on putting it back in when I save the file. (I hate it when software/hardware gives me lip!)

So, what is causing this entirely bizarre behavior?


<% @ServiceHost Language="C#" 
    Debug="true" Service="MyCompany.Communications.VSTOService" 
    Factory = "MyProject.Communications.IocServiceHostFactory" 
    CodeBehind="VSTOService.cs"%>

move @ sign with ServiceHost as <% @ServiceHost and hopefully your error get resolved


Make sure that when you create the *.svc file that it does not create a *.svc.cs file. If it does, delete it and remove the CodeBehind attribute from @ServiceHost


I saw that my svc file is like

<%@ ServiceHost Language="C#" Debug="true" Service="MessageProcessor.Async" %>
<a href="Msg.svc">Msg.svc</a>

Don't know how the anchor tag got inserted below servicehost tag, which was causing the issue. after removing anchor tag (), it fixed the issue "A namespace cannot directly contain members such as fields or method"

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜