dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.98k stars 4.03k forks source link

Getting Started VB Semantic Analysis is not current and examples don't work #23974

Open paul1956 opened 6 years ago

paul1956 commented 6 years ago

Version Used: Anthony D. Green edited this page on Sep 19 2015 · 1 revision from this Repo Steps to Reproduce:

  1. The page refers to VS 2015
  2. The Example as below are marked Obsolete with VS 2017 15.5.2
    Dim compilation As Compilation =
                VisualBasicCompilation.Create("HelloWorld").
                                       AddReferences(MetadataReference.CreateFromAssembly(
                                                         GetType(Object).Assembly)).
                                       AddSyntaxTrees(tree)

    Even when you attempt to follow the instructions to fix

            Dim comp As Compilation = VisualBasicCompilation.Create("HelloWorld").
                                       AddReferences(MetadataReference.CreateFromFile((New Object).GetType().Assembly.Location.ToString)).
                                       AddSyntaxTrees(tree)

    You get an error

    System.BadImageFormatException: 'Could not load file or assembly 'System.IO.FileSystem, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)'

Expected Behavior: Examples work Actual Behavior: Error pointing out CreateFromAssembly is deprecated and instructions to fix are less than obvious

jcouv commented 6 years ago

Tagging @AnthonyDGreen Relates to https://github.com/dotnet/roslyn/wiki/Getting-Started-VB-Semantic-Analysis