Bitmap not found in System.Drawing in Unity3D - c#

Maybe just an oversight on my part, but I can't make sense of this:
I have the reference to System.Drawing in my project tree within the references
I have the correct using statement using System.Drawing;
I can access other members of this namepace
According to the docs, bitmap should be within this namespace.
However, if I try use a bitmap, I get the following error:
Error CS0246 The type or namespace name 'Bitmap' could not be found
(are you missing a using directive or an assembly reference?)
VS19-IntelliSense suggests to install the package System.Drawing.Common, however if I do that, I get yet another error, stating:
The type name 'Bitmap' could not be found in the namespace
'System.Drawing'. This type has been forwarded to assembly
'System.Drawing.
How can I resolve this issue to actually use the Bitmap class?

Copy the System.Drawing.dll from C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0 into your Unity project folder. I put mine under Assets/Plugins/System.Drawing.dll.
This version will contain the Bitmap class. You will still have an error in the editor, but everything will compile fine and you should be able to use Bitmap in Visual Studio.
A problem you may now encounter when using certain types from this dll (e.g. Color, RectangleF) is that Unity gets confused between the 4.0 and 2.0 versions of the dll files. The only solution I found to resolve this is to change Api compatibility Level from .NET Standard 2.0 to 4.0 under Edit > Project Settings... > Player. .
If you choose not to do this, you will find that there is System.Drawing in the C:/Program Files/Unity/Hub/Editor/2020.2.0f1/Editor/Data/NetStandard/ref/2.0.0/netstandard.dll. Removing this dll will cause Unity to complain until you restore it.
There are solutions suggesting to modify C:\Program Files\Unity\Hub\Editor\2020.2.0f1\Editor\Data\NetStandard\compat\2.0.0\shims\netfx\System.Drawing.dll or C:\Program Files\Unity\Hub\Editor\2020.2.0f1\Editor\Data\MonoBleedingEdge\lib\mono\4.5\System.Drawing.dll, but I would advice against this as it would impact other projects using the same Unity version.

Related

How to use System.Speech in Unity?

I want to use System.Speech to implement a text-to-speech to my unity desktop application. I don't get how to implement the System.Speech. When I type using System.Speech; in my C# file, it gives error : The type or namespace name System.Speech could not be found (are you missing a using directive or an assembly reference?)
I have copy the System.Speech.dll from C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0 to the asset folder, but it doesn't work.
When I add it using Nuget, it says that it doesn't compatible with any framework.
Can someone explain how to add the reference, to make it works?
Thank you very much.
you cant use this assembly directly in Unity, you have to have a wrapper
you could find a solution Wrapper For unity

The type or namespace name 'File' does not exist in the namespace 'System.IO'

I'm trying to create a script that will open a CSV file on Visual Studio using C# but when I reference the File class the error will pop up:
The type or namespace name 'File' does not exist in the namespace 'System.IO'
I've made sure that I'm using System as well as using System.IO and went to add references for System.dll and System.IO.dll but when I do try and add them I get the error:
A reference to 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.dll' could not be added. This component is already automatically referenced by the build system.
Same error for System.IO.dll.
I'm using .NETFramework v4.6 and Visual Studio 2015.
This component is already automatically referenced by the build system
This message is particular to the kind of project templates that do not support the File class. Windows Store, Phone or Universal. You have to jump through more hoops when you target them, manipulating the file system is vetted by the runtime broker that ensures you are poking around in places you are allowed to look. And it must always be done with async code on the theory that it might be slow.
The Windows.Storage.StorageFile class is roughly similar.

Upgrading solution from MVC 3.x to MVC 5.2.3: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web'

I have a solution that was originals built using VS 2010 and MVC 3.something. I am now using VS 2015 and MVC 5.2.3. I deleted the old reference to MVC3 and changed it to the 5.2.3 dll. Now, whenever I try to build the solution, I receive multiple instances of this error:
Error CS0234 The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
The error happens in each file (class) when I try to use System.Web.MVC:
using System.Web.Mvc;
The reference DOES exist. The odd thing is, if I remove this line in a given file, and replace it with the exact same thing, the error for that file will temporarily vanish, but will then come back at some seemingly random point in the future when I build again.
Based on some other threads of a similar nature, here's a couple things I have tried:
Create a new project in VS2015 using MVC5, then copy the Web Config files from the new solution into the existing solution. Both in the root, and in the Views folder
Made sure Copy Local on the ref to System.Web.MVC is set to True
Any other suggestions?
Is there more than one project in the solution? It's possible that one of the other projects is referencing an older version of MVC.

Type or namespace name does not exist [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
This post was edited and submitted for review 9 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I have a WCF Data Service project built with Visual Studio 2010, which was working fine. All of a sudden, it didn't compile anymore. It was giving me messages like:
Error 7 The type or namespace name 'Services' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) C:\U...s\Visual Studio 2010\Projects...\DataService.cs ...
Error 8 The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?) DependencyResolver.cs 3 14
Error 10 The type or namespace name 'Web' does not exist in the namespace 'System.ServiceModel' (are you missing an assembly reference?)
Error 12 The type or namespace name 'DataService' could not be found (are you missing a using directive or an assembly reference?)
How can I fix it?
I have had the same problem, and I had to set the "Target Framework" of all the projects to be the same. Then it built fine. On the Project menu, click ProjectName Properties. Click the compile tab. Click Advanced Compile Options. In the Target Framework, choose your desired framework.
I had an issue with System.Linq not being recognized. The using statement had a red squiggly, etc. The way I solved it was to change my website to target dotnet 3.5, then switch back to the original targeted framework (4.0 in my case).
I found that this is caused by me having the same namespace name as class name (MyWorld.MyWorld = Namespace.ClassName).
Change your namespace to a name that is not the same name as your class and this will compile.
Source
I faced the same issue with an ASP.NET MVC site when I tried to use LINQ to SQL. I fixed the problem by:
Solution Explorer -> References -> Right-click on System.Data.Linq -> Copy Local (True)
I have experienced same problem with System.Data.SQLite. The source of the problem is the dll you have used should have same .NET version with your project.
For example if you have used (in my case) SQLite for .NET 4.5, your platform target should be .NET 4.5 too.
You can find platform target by: Project > (project name) Properties > Build.
Check to see that your target framework has the same .NET versions. I had the same problem and my class .NET was 3.5 and web solution had 4.5. I synchronised those, and then it worked :)
I had the same problem and tried all of the above without any success, then I found out what it was:
I'd created a folder called "System" in one of my projects and then created a class in it. The problem seems to stem from having a namespace called "System" when the .cs file is created, even if it is in a namespace of "MyProject.System".
Looking back I can understand why this would cause problems. It really stumped me at first as the error messages don't initially seem to relate to the problem.
In my case the problem was happening because the class I created had a namespace that interfered with existing classes. The new class A had namespace zz.yy.xx (by mistake). References to objects in another namespace yy.xx were not compiling in class A or other classes whose namespace was zz.
I changed the namespace of class A to yy.xx , which it should have been, and it started working.
FOR ANYONE WITH LINKED FILES: I had this problem and was using silverlight and the offending file that was throwing this error was a linked file.
The error from the compiler told me the error was happening in the project that the file lived in. It ended up that the error was NOT in that project, it was occurring in the project that contained the linked file. That project was missing a reference.
I encountered this problem while using Visual Studio's Git integration to manage the project. For some reason the Windows Phone 8 project would compile just fine when targeting x86, but when I set it to target ARM, it would fail compiling with an error indicating that "Advertising" didn't exist in the Microsoft namespace.
I ended up resolving the issue by removing the Microsoft.Advertising.*.dll reference and adding it again.
I experienced the same errors. After I discovered my project had the wrong Assembly name (I copied files from a different project and the namespaces got a little confused), and changed it back, the project compiled nicely.
I got a very similar error message that was caused by inadvertently having made a duplicate of a class in another project of my solution. Deleting the duplicate fixed the issue
And if all else fails, such as ensuring that the target frameworks are the same, and you are dealing with a WPF class library in VS2010, simply restart Visual Studio. That did it for me.
In my case there was no change in projects, it just stopped to compile and with "type or namespace name XXX does not exist" and in the complaining class itself intellisense for that XXX namespace/class works fine.
The problem was in references indeed!
Steps to reproduce:
Solution has ProjectA, ProjectB.
ProjectA references to third party log4net and it is marked Copy local: true.
ProjectB references ProjectA and does not have reference to log4net.
Solution compiles fine.
Change in ProjectA: reference property for log4net to Copy local: false.
Clean bin and obj folders.
When you compile, ProjectA compiles but ProjectB complains about not finding ProjectA namespace.
This is because ProjectB bin folder is missing third party library (log4net in my case)!
In this case solution would be -
make sure that third party libraries references are set to Copy local: true
or
add path to such libraries in project properties under reference path.
I am referencing Microsoft.CommerceServer.Runtime.Orders and experienced this error. This project is old and has Target framework .NET 2.0. In output I had this error:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3268: The primary reference "Microsoft.CommerceServer.Runtime" could not be resolved because it has an indirect dependency on the framework assembly "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "Microsoft.CommerceServer.Runtime" or retarget your application to a framework version which contains "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
I simply changed the target framework to .NET 4 and now it builds.
I recently needed to do a System Restore and it caused several of my files to change/disappear that I had been working on since the restore. Some of those were DLL files. I used Source Control to retrieve the entire project but I still had a similar issue as above. I found this answer that described you may need to remove a DLL and readd it to get your errors fixed. This was the case in my scenario.
Removing WebMatrix.WebData and readding it as well as adding in WebMatrix.Data fixed my error of The type or namespace name 'Data' does not exist in the namespace 'WebMatrix' ....
Delete the .refresh.dll file if you are under source control. Then rebuild. It should work.
This worked for me

Reference DLLs not loading in Visual Studio 2010

I'm working on a C# 4.0 project in VS2010 and needed to use some older DLLs containing controls that were created in C# 3.5 on VS2008. When I first add the DLLs to the references, I was able to see the namespace via intellisense and create an instance of one of the controls, but when I go to build, it gives me the following error:
The type or namespace name 'BCA' could not be found (are you missing a using directive or an assembly reference?)
And I do have a using directive for that namespace already, which is now underlined in red, showing that VS cannot find it. And now, intellisense won't pick up that namespace at all.
I even tried added the controls to the toolbox (which worked) but then when I drag them to the GUI, it says that it cannot locate the DLL reference, even though it obviously knows where it is.
I even tried changing the target framework to 3.5, but still with the same results.
Any thoughts as to why this could be happening?
Edit - I've notice that in the csc.exe arguments that VS outputs, it does not have any /reference entries for the DLLs I'm trying to use. When I create the same basic project in VS2008, those entries exist. Also, I can successfully reference the DLLs in a DLL project in VS2010... it seems to just be WinForms projects that don't work.
Turns out that it was something to do with VS2010 defaulting to the .NET 4 client profile, as soon as I changed it to the regular profile it built fine. There's a day wasted...
view the target framework.. in my project, was 4.0 client profile, e the reference dll was in 4.0
I tried Build->Clean Solution and then could add the reference.
I used to have similar problem, but the profiles were not the issue, so the problem was that my class library use a special NuGet package that has Dependency... so I install the dependency package in the target project and added the project reference and works!
But I am not sure if there is a better solution for this problem??? for me VS should be smart enough to carry those dlls along with the references. (I already verified that "Copy Local" is set to True)

Categories