I get the following as a warning during build of my asp.net application:
The predefined type
'System.Runtime.CompilerServices.ExtensionAttribute'
is defined in multiple assemblies in
the global alias; using definition
from 'c:\Program Files\Reference
Assemblies\Microsoft\Framework\v3.5\System.Core.dll'
How do i resolve this warning?
From this blog:
So the final solution was to use the InternalVisibleTo attribute in one
of the assemblies. This means
ExtensionAttribute only needs to be
defined in one assembly. There's more
info here on how to do that with
strongly named assemblies since it's
not completely straight forward.
Related question: C# Compiler Warning 1685
from MSDN
Visual C# Reference: Errors and
Warnings Compiler Warning (level 1)
CS1685
Error Message The predefined type
'System.type name' is defined in
multiple assemblies in the global
alias; using definition from 'File
Name'
This error occurs when a predefined
system type such as System.int32 is
found in two assemblies. One way this
can happen is if you are referencing
mscorlib from two different places,
such as trying to run the.Net
Framework versions 1.0 and 1.1
side-by-side.
Based on this, we probably need to see the list of assemblies and their references to help you much.
Related
So I tried to add async methods to my routes and to the interfaces, repositories etc and I coded everything properly. Everything looks great but when I try to run the app I get that error:
Error CS1061: 'DbSet<Hotel>' does not contain a definition for 'ToListAsync' and no accessible extension method 'ToListAsync' accepting a first argument of type 'DbSet<Hotel>' could be found (are you missing a using directive or an assembly reference?) (CS1061)
I downloaded EF Core package and even hard coded most of the things since .NET does not detect anything related to async methods.
Do you know why I get this error?
I could not find any solutions. EDIT: I'm on a Mac btw.
Use this namespace
Microsoft.EntityFrameworkCore
I am working in the context of a .NET Core application, windows service, and I have a compiler error telling me I've got a type that has moved assemblies. I cannot find said type and I have gone all over looking for it. So far, I have tried using a combination of dnSpy, Dotpeek, and try.dot.net to reference pertinent nuget packages or .dlls' local to my machine to find the System.Security type(s) I'm looking for. Error for the Type is as follows and afaik an assemblage with that version does not exist...anywhere!
The type name 'DirectorySecurity' could not be found in the namespace
'System.Security.AccessControl'. This type has been forwarded to
assembly 'System.IO.FileSystem.AccessControl, Version=4.0.4.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a
reference to that assembly.
Is there a way I can use external tooling to filter or find a type on my machine that the compiler is asking for? I have referenced all manner of dependencies (individually) in Visual Studio then subsequently removed them if that did not satisfy the compiler.
In any event, any help would be appreciated - thanks!
Upon further inspection of the the nuget-package the version of the specific library (and subsequent type) is .NET Standard compliant only with NET Core 2.0 and under; not 3.0 yet...so I have to downgrade the project, find a different workaround, or wait until the System.Security.AccessControl library is compliant with 3.0+.
I am trying to create a simple code sample that access an oracle database, in a Web Api 2 project.
Since OracleClient dll is not available "by default" (if I understand it right, upon creating a new project the targeting framework subset is not the full framework dll set), I added a reference to System.Data.OracleClient.
The references to the dll's types such as OracleConnection, OracleCommand and so are all recognized by VS, just like intelisense shows OracleClient after typing System.Data.
A build however raises an error stating
The type or namespace name 'OracleClient' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
The runtime version (v4.0.30319) and version (4.0.0.0) are exactly the same as, say, System.Data, automatically loaded when upon creation.
What is wrong ?
Adding a reference to a new dll requires restarting visual studio.
I have a big problem in Visual Studio 2012. Whenever I start an ASP.Net MVC4 project I get the following errors:
Cannot convert lambda expression to type 'System.Linq.Expressions.Expression<System.Func<Carrousel.Web.ViewModels.LoginViewModel,bool>>' because it is not a delegate type
One or more types required to compile a dynamic expression cannot be found. Are you missing a reference? d:\Visual Studio\Projects\School\Carrousel v2\Carrousel.Presentation\Views\Account\Login.cshtml
The type arguments for method 'System.Web.Mvc.Html.InputExtensions.TextBoxFor<TModel,TProperty>(System.Web.Mvc.HtmlHelper<TModel>, System.Linq.Expressions.Expression<System.Func<TModel,TProperty>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
This happens when there are Dynamic expressions like ViewBag, and Html Form Helpers in a cshtml file.
I have been searching for a while, and the only reasons I could find was if Microsoft.CSharp and/or System.Core is not referenced. However I have both referenced in the project.
This problem only occurs when using Asp.Net Mvc 4, when using Mvc 3 everything works fine. This error occurred on both my Windows 7 and Windows 8 Enterprise versions. I have also tried uninstalling and reinstalling mvc4 through the package manager.
Try to delete-and-add your references to the following assemblies:
Microsoft.Scripting.Core.dll
Microsoft.CSharp
With
CopyToLocal = true
I am using JSON.NET which has the LinqBridge .dll merged in. LinqBridge allows Linq to be accessed from .NET 2. If I try to use Linq, even after importing System.Linq, I receive the following error:
Error 13 Could not find an implementation of the query pattern for source type 'int[]'. 'Where' not found. Are you missing a reference to 'System.Core.dll' or a using directive for 'System.Linq'? C:\Users\chrisl\Desktop\SoftTokens\Windows Desktop Soft-Token\Program.cs 27 25 WindowsSoftToken
If I try to include LinqBridge, then because JSON.NET already includes it, I receive this warning. Additionally, I have included the same component twice, which is inefficient:
Warning 2 The predefined type 'System.Action' is defined in multiple assemblies in the global alias; using definition from 'c:\Users\chrisl\Desktop\SoftTokens\Windows Desktop Soft-Token\libs\Newtonsoft.Json.Net20.dll' WindowsSoftToken
If I browse Newtonsoft.Json.Net20 in the object browser, I see that System.Linq appears empty, even after I have slected Show hidden types and methods.
Is it possible to access Linq from the JSON.NET dll or to suppress the error messages?
The Enumerable static class that provides the LINQ query operators in the LINQBridge assembly is still exposed in the System.Linq namespace.
You still need to have the using directive for System.Linq as directed in your first error message.
Update:
It turns out the LINQBridge assembly that's merged into Newtonsoft.Json.Net20.dll has been "internalized" which I hadn't noticed at first. This means your code can't reference the Enumerable type that the compiler needs to "implement the query pattern." So you do have to reference the LINQBridge assembly yourself, but then you get the warning about duplicate definitions as you mentioned.
You can disable the duplicate class warning by going to the Build tab of your project properties and enter "1685" in the "Suppress warnings:" box.
But what would probably be better would be to build your own version of JSON.net from source without merging in LINQBridge.