VB.NET XML Literal Expression Expected with Linq t

2019-06-08 15:05发布

问题:

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.