Cannot use dynamic type with asp.net vnext core

I need to read and save the JSON file in an ASP.NETt vNext application, and I would like to use the dynamic variable to store the value loaded using JSON.net, but when I go to compile, I got this error message:

ASP.NET Core 5.0 CS1980 error: it is not possible to define a class or member that uses 'dynamic' because you do not need to find the type 'System.Runtime.CompilerServices.DynamicAttribute' for the compiler. Are you missing a link?

How can this be solved? If I use dynamic , can I start the application using the ASP.NET kernel?

+8
c # asp.net-core
source share
2 answers

You need to enable the Microsoft.CSharp and System.Dynamic.Runtime packages for the aspnetcore50 framework.

This seems to work for me with CoreCLR version 1.0.0-beta1:

    Newtonsoft.Json.Linq;  ;   DynamicTest {        {       public void Main ( [] args)       {          dynamic dobject = JObject.Parse( "{: 1000, : '', : [1,2,3,4,5,6]}" );           (dobject.number);            (dobject.str);            (dobject.array.Count);           Console.ReadLine();       }   } } > 

Project .json

  {   "": "1.0.0- *",   "": {       "Newtonsoft.Json": "6.0.7"   },   "": {       " "   },   "": {       "aspnet50": {},       "aspnetcore50": {           "": {               "System.Console": "4.0.0-beta-22231" ,               "System.Dynamic.Runtime": "4.0.0-beta-22231" ,               "Microsoft.CSharp": "4.0.0-beta-22231"           }       }   } } > 
+5
source share

I struggled with this issue along with an even less useful error message ...

The Linq namespace type or name does not exist in the System.Data namespace

But I ran into a problem on my IIS server (2012 R2 - IIS 8). Most of the posts I read about these issues are about the development environment, not their web server.

To solve both problems, I had to copy the System.Core.dll file from the server infrastructure folder (% windows path% \ Microsoft.Net \ Framework \ v4.0.30319) to the folder with the web application folders.

I do not understand why this was necessary, but I spent 3 days reading the documentation and forum posts, and nothing worked there. We were just lucky ...

Perhaps this will help someone who is struggling.

+2
source share

All Articles