VB.NET XML Literal Expression Expected with Linq to XML

允我心安 提交于 2019-12-23 06:31:32

问题


I have the same problem as stated in this question, but the accepted solution there was a "works on my machine" answer.

Here is my code:

Dim document As XDocument = _
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
        <soap12:Body>
            <GetUser xmlns="http://foo.com/bar.asmx">
                <encryptedHash>HashString</encryptedHash>
                <accessKey>AccessString</accessKey>
                <siteUID>SiteString</siteUID>
            </GetUser>
        </soap12:Body>
    </soap12:Envelope>

And I receive the error: BC30201: Expression expected.

Does anyone have a more detailed idea of what could cause this?


回答1:


Ok, Rubber Duck debugging --

Even though the project was set to target .NET 3.5, for whatever reason the web.config was missing:

 <system.codedom>
<compilers>
  <compiler language="c#;cs;csharp" extension=".cs"
            type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            warningLevel="4">
    <providerOption name="CompilerVersion" value="v3.5"/>
    <providerOption name="WarnAsError" value="false"/>
  </compiler>
  <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
            type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            warningLevel="4">
    <providerOption name="CompilerVersion" value="v3.5"/>
    <providerOption name="OptionInfer" value="true"/>
    <providerOption name="WarnAsError" value="false"/>
  </compiler>
</compilers>

So I guess it wasn't running in 3.5. As soon as I added the above to the web.config it compiled.



来源:https://stackoverflow.com/questions/3007118/vb-net-xml-literal-expression-expected-with-linq-to-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!