-4

I am getting this error :

CS1061: 'Type' does not contain a definition for 'Assembly' and no extension method 'Assembly' accepting first argument of type 'Type' could be found.

I am trying the solution mentioned in the link below: https://GitHub.com/dotnet/Roslyn/wiki/Getting-Started-C%23-Semantic-Analysis With template Analyzer with Code fix template.

Code snippet:

var compilation = CSharpCompilation
                 .Create("HelloWorld")
                 .AddReferences(MetadataReference.CreateFromFile(typeof(object).Assembly.Location))
                 .AddSyntaxTrees(tree);

I am getting an error in step 3.

I am using Visual studio 2015 and I have installed. " .Net compiler platform SDK".

Anantha
  • 1
  • 6
  • Please post your relevant code here - you cannot expect people to download go through the tutorial just to solve *your* problem. – Filburt Jan 28 '17 at 10:04
  • I am unsure how the solution you suggest fit in to the context... – Anantha Jan 28 '17 at 10:10
  • @Filburt I have added code snippet where I am having issue...For clarity purpose I have avoided the entire code snippet though. – Anantha Jan 28 '17 at 10:19
  • @Roma No...I am trying to write custom Analyzer...Basically want to get the type of a variable used in program (/class) where my analyzer would take an action based on the type declared in the program. – Anantha Jan 28 '17 at 10:24
  • @Anantha, if you change `typeof(object).Assembly.Location` to `typeof(object).GetTypeInfo().Assembly.Location` will you get this error again? – Roman Jan 28 '17 at 10:27
  • @Roma this I tried but location is not a member in assembly and hence below the keyword location it gets squiggled and throws a message as 'Assembly' does not contain a definition for 'Location' and no extension method... – Anantha Jan 28 '17 at 10:32
  • @Anantha, in question is it your own code or code from the link? – Roman Jan 28 '17 at 10:34
  • @Roma code from the link – Anantha Jan 28 '17 at 10:35
  • @Anantha, could you post your code? – Roman Jan 28 '17 at 10:35
  • @Roma I was learning this example...Which is published in the link...So.. – Anantha Jan 28 '17 at 10:36
  • @Roma thanks it worked...I was missing stand alone project...I had selected Analyzer with code fix template earlier...Grave mistake.. Thanks – Anantha Jan 28 '17 at 10:58
  • @Anantha, you are welcome – Roman Jan 28 '17 at 10:58
  • I have added one information more that I am trying the above solution with Analyzer with code fix template. The solution does work with Standalone code analysis tool though..I need the solution to work with Analyzer with code fix because I plan to create a custom rule and integrate it with sonar – Anantha Jan 29 '17 at 05:32

1 Answers1

0

Found the solution: MetadataReference.CreateFromFile(@"C::\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.5\Profile\Profile7\System.Runtime.dll") instead of

MetadataReference.CreateFromFile( typeof(object).Assembly.Location

Anantha
  • 1
  • 6