How to add standard .Net references such as
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
When trying
using (System.Drawing.Image I)
I get the error
Severity Description File Line
Error The type name 'Image' could not be found in the namespace 'System.Drawing'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcdxxxxx' Consider adding a reference to that assembly.
When going into reference VS 2018 wants me to point to the DLL File.
Its really frustrating. This is a Asp.NetCore MVC web based project.
System.Drawing is incompatible with .NET Core, because it uses Windows-specific APIs not available in .NET Core. Microsoft has since released System.Drawing.Common, which is a NuGet package that provides a similar API to the old System.Drawing but uses cross-platform APIs. To make this truly a drop-in replacement, the System.Drawing namespace now forwards to System.Drawing.Common, so older code could work without change.
Long and short, you need to add the System.Drawing.Common NuGet package to your project.
Related
Here is the setup when I am getting this error:
Project "main" based on Core 3.1 and of type console application. Does not have a reference to System.Data.SqlClient and does not need one.
It calls project "process" also based on Core 3.1 of type class library. Does not have a reference to System.Data.SqlClient and does not need one.
"Process" calls project "service" based on Core 3.1 of type class library. This project needs System.Data.SqlClient and has a reference to a package "System.Data.SqlClient (4.5.1)".
When debugging "main", when it gets to "service", the first time it reference SqlConnection, it errors with message "system.data.sqlclient is not supported on this platform"
Why am I getting this error and how can I fix it.
Note: When I add a refernce to System.Data.SqlClient in project "main" - no error, but of course as "main" does not need System.Data.SqlClient, it should not have one.
When I test "service" using xUnit, no errors, it works OK
Thanks
According to the document:
The Microsoft.Data.SqlClient NuGet package includes a number of DLLs
supporting different .NET targets and different runtime platforms. If
you are getting a PlatformNotSupported Exception when you don't think
you should be, it ultimately means your application is not loading the
appropriate DLL. There could be a number of reasons for this. The
NuGet package structure and infrastructure around referencing and
loading referenced NuGet packages includes logic that allows a package
to contain multiple DLLs which implement support for different .NET
and platform targets. Meaning a different DLL for .NET Framework, .NET
Core, .NET Standard, Windows, Linux, etc. The NuGet infrastructure
will automatically reference and load the appropriate DLL based on
your application's needs.
If your application loads a DLL from a NuGet package directly, it
bypasses all this logic and probably loads the incorrect DLL. The DLL
in the NuGet package under
lib/netstandard2.0/Microsoft.Data.SqlClient.dll is basically the
fallback DLL for any unsupported target and simply throws the
PlatformNotSupported exception for any call. This is a nicer exception
than what you would otherwise get when running on a platform that does
not have a DLL built for it. Ultimately, you want to use the NuGet
package reference infrastructure or you would have to implement all
this target framework and platform support logic yourself when
determining which DLL to load.
Additionally, the NuGet package contains all the dependency
information for the SqlClient library and facilitates the downloading
and referencing of dependencies. If you reference and load an
individual DLL manually, it is up to you to ensure all dependencies
are also available to the SqlClient library.
I suggest you could try to use Microsoft.Data.SqlClient instead. More details about cheat sheet for porting from System.Data.SqlClient to Microsoft.Data.SqlClient, you could refer to this article.
I'm in the process of converting an Asp.Net Core 2.2 Website that targeted the Full Framework to an Asp.Net Core 3.1 App that targets .Net Core 3.1. I'm a bit unclear about dependencies related to System.Drawing and how to fulfill them.
My project uses System.Drawing and when compiling under Asp.Net Core 3.1 I get this error that suggests that I add a reference to System.Drawing.Common.dll :
Error CS1069: The type name 'Image' could not be found in the namespace 'System.Drawing'. This type has been forwarded to assembly 'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly. 1-wwwGiftOasis3 C:\Users\Ron\source\repos\wwwGiftOasis3\wwwGiftOasis3\site\seller\profile\about\s-photos.cs
In Visual Studio I don't see a way to add a reference directly to the bare System.Drawing.Common.dll so I assume that I should add the reference via NuGet.
In NuGet I see a System.Drawing.Common package which looks like what I want but it's unclear to me whether my project fulfills the dependencies:
My Project shows these dependencies:
So I have a couple questions related to all this:
1) Does the fact my the project depends on Framework Microsoft.NETCore.App fulfill the NuGet package's Microsoft.NETCore.Platforms dependency?
2) Does the fact that I intend to only run this Asp.Net Core 3.1 website on windows fulfill the NuGet package's Microsoft.Win32.SystemEvents dependency?
System.Drawing utilizes Windows-specific APIs, and as such, is incompatible with .NET Core, which is cross-platform. Microsoft created System.Drawing.Common as an in-place replacement for System.Drawing for .NET Core. It is an exact API replacement, but performs the image operations in a cross-platform, rather than Windows-specific, way.
Long and short, yes, you just drop the NuGet into your project and go to town. There's nothing else you need to worry about.
I'm building a Web API in .NET Core 2. I'm using some custom nuget packages to leverage their built in functionality. These custom packages were built against an older .NET version (4.6.1). The problem is some of these packages have references to the old System.Web dll. I'm getting this warning on some of the custom packages in the solution
package was restored using '.net framework version=v4.6.1 instead of using the proj target framework.
The app is also throwing this exception below when I call code in one of the custom packages
System.IO.FileNotFoundException: Could not load file or assembly System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral,The system cannot find the file specified
Is there any way around this other than re-writing the code in my web Api?
No. System.Web is completely incompatible with Core. While Microsoft opened up NuGet packages that target .NET Framework to be utilized in with .NET Core, it did so based only on .NET Standard 2.0 compatibility, and makes no assurances that the packages will function in part or whole. You'll actually get a warning during compile telling you as much. Also, while you can actually have something like an ASP.NET Core app actually target .NET Framework, again, compatibility of third-party components is not guaranteed, simply because they target the same framework.
Long and short, if there's any dependency on System.Web at all, you can't use it.
I am new to F# and I apologize if this question was asked before, but I could not find it.
I am trying to create an F# DLL in NetStandard 2.0 and I would like to use HttpClient
open System.Net.Http does not work: The namespace 'Net' is not defined.
I looked and could not find any solutions specific to F# and HttpClient in the context of NetStandard 2.0
The name space System.Net.Http is there on the C# side using in NetStandard 2.0. No problem there.
On F#, intellisense does not show the .Http namespace when expanding System.Net
Any ideas would be greatly appreciated.
TIA,
David
That namespace is an assembly that is not automatically referenced as part of .NET, so it needs to be referenced for each project that uses it. It's possible that the C# project already had the reference, or your tooling added it automatically when you tried to open the namespace. So you just need to add a reference to the DLL "System.Net.Http" in your F# project.
I installed asp.net mvc-4 beta a while ago to host our api. It worked fine until I just installed vs2012 ultimate on my machine. The project is neither compiling in vs2010 nor in vs2012. What can I do to resolve this conflict. Furthermore, I bin deployed asp.net web api assemblies on my server. What I have to do to run the latest build (once the previous problem is solved) on server?
Edit:
The compilation errors when I open in vs2012 are
'System.Net.Http.HttpRequestMessage' does not contain a definition for 'GetUserPrincipal' and no extension method 'GetUserPrincipal'...
'System.Web.Http.Hosting.HttpPropertyKeys' does not contain a definition for 'UserPrincipalKey'
In vs 2010 on the other hand, it refuses to accept types like DelegatingHandler and others. Some errors are as follows.
The type or namespace name 'DelegatingHandler' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'HttpResponseMessage' could not be found (are you missing a using directive or an assembly reference?)
I have installed the latest build of asp.net mvc 4 as well and the version its showing me is 4.0.20713.0. Previously, I added web-api beta using nuget. I have removed them all and installed latest builds of web-api from nuget. I don't know what could be the problem. One thing, I don't understand: why do I need to install web-api assemblies seprately when they are supposedly part of mvc framework?
thanks
Add using System.ServiceModel.Channels; to your file. The Extension methods for HttpRequestMessage exist in this namespace according to THIS.
add
using System.Net.Http;
You probably have the reference already, so just add the using for the extension method.
Otherwise add the Assembly of the same name.