Ambiguous error between TableNameAttribute.TableNameAttribute(string) - c#

I just upgraded the .Net v4.0 to 4.6.1 and ended up having the ambiguous error for the sql related attributes(TableName, PrimaryKey, Column) I used in the application.
I am trying to figure out which DLL is causing this error.I am seeing the errors like
TableNameAttribute.TableNameAttribute(string)
PrimaryKey.
ColumnAttribute...etc
I want to know which dll I have to delete

the ambiguity was between the Entity framework and the System.componentmodel.dataannotations

Related

DeskTop: How to Fix MC1000 unknown Build error - could not find type 'System.Management.Instrumentation.InstrumentedAttribute

I am migrating a .net framework 4.6.1 Desktop app to Core 6. I have resolved all errors except this one: MC1000 Unknown build error, 'Could not find type 'System.Management.Instrumentation.InstrumentedAttribute' in assembly 'C:\Users\M70151.nuget\packages\system.management\7.0.0\lib\net6.0\System.Management.dll'.' ABC C:\ProgramFiles\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.WinFX.targets.
I cannot see System.Management being used anywhere in the App. I do not see WinFX.Targets referenced in the framework version of the App. I guess this was added because of the migration? Any ideas on resolving this issue?
I tried replacing system.Management, verifying the path, no success. I checked the System.Management.Instrumentation for the InstrumentedMethod. It does not appear to exist.How can I tell what is trying to use the method?

Reference an EF5 project from an EF6 project

Is it possible to use a project that was written and built using Entity Framework 5 as a reference in a project that uses Entity Framework 6? When doing so, I get "Method not found" errors on functionality that has been deprecated in EF6, but that works just fine when used in the EF5 project as a standalone project.
A call like this:
dataContext.Database.SqlQuery()
throws an error of:
{"Method not found: 'System.Collections.Generic.IEnumerable`1<!!0> System.Data.Entity.Database.SqlQuery(System.String, System.Object[])'."} System.Exception {System.MissingMethodException}

Entity Framework setup issue

When I run my code
using (foodEntities db_Linq = new foodEntities())
{
return db_Linq.Database.Exists();
//return db_Linq.Foods.Any();
}
I keep getting this error in the output window.
A first chance exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll
What could be the issue? DB Credentials in web.config?
Other info:
I actually have 2 projects in my solution. One's a class library, the other MVC 4 web project.
Class library uses Entity Framework connection. Web project uses ADO connection string.
The above issue happens when web project calls the class library.
The code given above is from class library.
What version of the EF are you using? It seemed to me that you use EF6 and you have issues with the namespaces.
Please, check Updating Applications to use EF6 link. The main part for you is "Update namespaces for any core EF types being used"

Entity Framework 4 upgrade issue, Loading by both name and attribute is not allowed

I just upgraded my project from asp.net 2 to asp.net 4. More precisely I converted the project from VS 2008 to VS 2010. I did this because I needed the new features of EF4. I am running into an issue though where I am getting this error message:
The types in the assembly 'XXX' cannot be loaded because the assembly
contains the EdmSchemaAttribute, and the closure of types is being
loaded by name. Loading by both name and attribute is not allowed.
After some playing around I found that the cause is context.GetObjectByKey. I had a little function that would take an object id and build an EntityKey from it for use in GetObjectByKey. If I change that to context.ObjectName.FirstOrDefault(x => x.id == searchId) then I don't get the error anymore.
I'm in the process of updating all my code to the version that works but I'm wondering if anybody knows the reason for this? Or does it indicates some underlying issue with my code; perhaps that my EDM got munged in the conversion?
Is your entity really called "object?" That might be the problem. Having an entity with the same name as the root CLR type is certainly going to be an issue.

"Missing compiler required member" error being thrown multiple times with almost no changes to code

Today after deploying some changes to a C# MVC site that I run, I went back to make some more modifications and came across this error:
Missing compiler required member System.Runtime.CompilerServices.ExtensionAttribute..ctor
The error is a bit vague (other than it's description, obviously) as it doesn't give me a file, line, or column to reference, only the project. Also, it throws the error a total of 20 times. I only made three changes to the code between the time I deployed (it was completely functional at that time) and now. I reverted my changes and it is still throwing the same error which makes no sense to me.
I haven't found a lot of information on this error on SO or Google, other than this guys solution and a couple references to some Mono project errors (I'm not using Mono). The solution the guy above gives requires adding a class definition that will allow the compiler to resolve the reference. I don't particularly want to do this because I haven't needed to do it up until this point and it will just muddy my code.
Just curious if anyone has run across this before.
In my case it was because the project was not referencing Microsoft.CSharp. Once I added a reference to that assembly, it compiled just fine.
I don't know if anyone else has experienced this, but I suddenly ran into this error after adding some code utilizing dynamic types and incorporating WebAPI into a project that originated as a TypeScript application in VS2013. Simply adding a reference to Microsoft.CSharp resolved my issue.
Hope this helps someone else.
This error usually means either your project is compiling against .NET 2.0 or you aren't referencing the correct version of System.Core.dll
For a near duplicate question, see Error when using extension methods in C#
I ran into this situation as well today. In my case I was referencing the Newton.Json.Net dll v3.5 in my .NET 4.0 application. I realized that I wasnt even using this library, thus once I removed it from my references, it no longer gave me the compiler error.
Problem solved!!!
The actual error comes from the fact that your 2.0 assembly that causes the error contains this code:
namespace System.Runtime.CompilerServices
{
public class ExtensionAttribute : Attribute { }
}
The Code Above allows the .NET 2.0 Assembly to use extension methods (see Using extension methods in .NET 2.0?). While it confuses the compiler if you target .NET 4.0 and reference a 2.0 Assembly (containing above code) as the mscorlib.dll(4.0) contains the same class in the same namespace.
I fixed this
by compiling the original 2.0 assembly again without the attribute targeting 4.0
by removing the assembly (obviously)
by adding a third Extension Attribute in the target you compile (it seems to overrule the referenced definitions)
Writing this code somewhere in your project may solve your problem. It works for me
namespace System.Runtime.CompilerServices
{
public class ExtensionAttribute : Attribute { }
}
Probably you use dynamic keyword In .NetStandard Class library project. If so, you need to add a reference to Microsoft.CSharp library in the project. Hope it will resolve your problem.
NLog.dll 2.0 referenced from a .NET 4.0 project can cause this too.
I don't have a correct solution, but I'll add my data point:
In my case the error is caused by referencing GoogleSearchAPINet20
Here is what happens:
I close the solution that builds
I open the solution again. It still builds
As soon as I make any change and try to build, I get 19 "Missing compiler required member ..." errors
I remove the reference to GoogleSearchAPINet20
I add back the reference to GoogleSearchAPINet20
I build the solution. It builds without errors
I can now make code changes, build or perform any other actions with solution correctly as long as my Visual Studio is open
I close Visual Studio
Repeat from step one
I'm not referencing System.Core.dll in my solution at all and my target framework is .NET 4.
I'm a bit annoyed at this point ...
Got this error when trying to use async Tasks against .NET 4.0. Updating Target Framework to 4.5.2 fixed the problem.
I hit the same set of exceptions after I added some async methods to a winforms project. I needed to bump my .NET version from 4 to 4.5
For me, the problem occure when I add asynchronous method with async Task await in my .net4.0 project !
With previous versions of the .NET-Framework 4.5, you must install this package:
Install-package Microsoft.Bcl.Async –pre
or
Install-Package Microsoft.CompilerServices.AsyncTargetingPack
more info on Nuget or Nuget

Categories

Resources