I need help every time I try to use some Newtonsoft.Json configuration, an error appears:
Severity Code Description Project File Line Suppression State Suppression State
Error CS0433 The type "JObject" exists in "Newtonsoft.Json, Version = 6.0.0.0, Culture = neutral, PublicKeyToken = 30ad4fe6b2a6aeed" and "Newtonsoft.Json, Version = 12.0.0.0, Culture = neutral,
PublicKeyToken = 30ad4fe6b2a6aeed "mia C: \ Users \ Wesley \ source \ repos \ mia2 \ mia \ Controllers \ Api \ ContaController.cs 18 Active
I've already reinstalled my Nuget packages several times and it doesn't work and it's only in this application that I'm having this problem
Example of my controller
public IHttpActionResult Login (JObject form)
{
db.Configuration.ProxyCreationEnabled = false;
var email = string.Empty;
var password = string.Empty;
dynamic JsonObject = form;
try
{
email = JsonObject.Email.Value;
password = JsonObject.Password.Value;
}
catch
{
return BadRequest("chamada Incorreta, Campo Usuário e Senha são necessários");
}
var userContext = new ApplicationDbContext();
var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(userContext));
var userASP = userManager.Find(email, password);
if (userASP == null)
{
return this.BadRequest("Usuário ou Senha incorretos");
}
var user = db.Users.Where(u => u.UserName == email).FirstOrDefault();
if (userASP == null)
{
return this.BadRequest("Usuário ou Senha incorretos");
}
var userResponse = new UserResponse
{
UserId = user.UserId,
UserName = user.UserName,
FirstName = user.FirstName,
LastName = user.LastName,
Admin = userManager.IsInRole(userASP.Id, "Admin"),
Analista = userManager.IsInRole(userASP.Id, "Analista"),
Parceiro = userManager.IsInRole(userASP.Id, "Parceiro"),
Vendedor = userManager.IsInRole(userASP.Id, "Vendedor"),
Financeiro = userManager.IsInRole(userASP.Id, "Financeiro"),
IsEnabled = user.IsEnabled,
TinyUserId = user.TinyUserId,
ConsultorId = user.ConsultorId,
CampanhaId = user.CampanhaId,
};
return Ok(userResponse);
}
There are two possible causes for this issue:
Solution:
If you allow your solution to use multiple versions you will keep having issues. When you build a solution, every project is built and resulting dlls, including their other references are copied to whatever destination they are needed. They will even override each other which is what starts another set of issues since a project expects 12.0 for example but gets version 6 instead.