Why can't my c# compiler find System.Windows.Forms - c#

Here's the basic information:
I've been studying Rob Miles' C# Yellow Book 2011 extensively.
I'm on page 155 of 197 (mostly finished) and coming to the part about forms/guis.
I use Notepad++ and NppExec for quick compiling and easy editing (I just personally loathe VisualStudio... I don't like having things done for me.)
I'm using .NET 4.0's compiler
I've set up csc.rsp to include:
System.Windows.Forms.dll
System.Drawing.dll
System.Drawing.Design.dll
and the other required resource references.
I've double-checked all my references.
I include all required "using" statements in my code.
And the problem:
Every time I try to compile a piece of code which makes use of any form methods I get this error:
error CS0234: The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?)
I've looked everywhere. What can I do to resolve this issue?
PS - if you really want or need to see the code, I can paste it in a response. I won't do it unless someone asks because it's kinda long.

If it can't find Windows under System, then your reference to System.Windows.Forms.dll isn't working. You don't show exactly how you are doing that, but: that is the problem. So: however you are using csc.rsp, it isn't working. Are you perhaps using /noconfig? Have you edited the right file? Did you edit it as an admin user? If you open csc.rsp in an editor, are your changed there?

Related

error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)

I am trying to go through this tutorial for on making sounds with waves using C#:
https://www.codeguru.com/dotnet/making-sounds-with-waves-using-c/
The first sample code it has you run is this, which is supposed to play a .wav file:
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.Devices;
namespace MyApp
{
class Program
{
static Audio myAudio = new Audio();
static void Main()
{
myAudio.Play("m:\\crooner2.wav",
AudioPlayMode.WaitToComplete);
}
}
}
In my code, the filepath and name of the .wav file was replaced with a different one, but otherwise the code is identical. However, I get an error regarding the second line of code: error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)
Without the Microsoft.VisualBasic.Devices call working, I have no way of running even the first exercise in the tutorial, and definitely no way of further progressing in using C# for sound manipulation.
I was expecting the code to run and play the .wav file. However, I got the error message instead.
As part of debugging, I came across this post on the Microsoft website:
https://learn.microsoft.com/en-us/dotnet/core/compatibility/visualbasic#types-in-microsoftvisualbasicdevices-namespace-not-available
I'm not sure what to make of it. It seems like it's saying it could be solved by upgrading to .Net 5 or higher, but I'm already using .Net 5. It also seems like it saying that Microsoft.VisualBasic.Devices was made obsolete with .Net Core 3.0, so I'm not sure how upgrading would make it easier to use something that was made obsolete.
It also says that certain functionality in Microsoft.VisualBasic.Devices has equivalent functionality that can be called by other means. It gives specific replacement calls for Microsoft.VisualBasic.Devices.Clock and Microsoft.VisualBasic.Devices.Ports, but nothing for Microsoft.VisualBasic.Devices.Audio, which is what I want to use in my code.
I have tried this in both Visual Studio and Visual Studio Code and get the same errors either way.
With .NET Core, you generally add references via NuGet packages. There is no NuGet package for Microsoft.VisualBasic.Forms.dll, which the documentation clearly states that type is declared in. To get that assembly reference, I believe that you need to replace this line in your project file:
<TargetFramework>net5.0</TargetFramework>
with these lines:
<TargetFramework>net5.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
After doing that, you should see Microsoft.WindowsDesktop.App.WindowsForms added under Dependencies -> Frameworks in the Solution Explorer and the relevant assembly is listed under that.
You have to use reference to "Microsoft.VisualBasic" in your project.
You have two way for do that :
1st way :
Right click on project references, select "Assemblys" => "Framework" and you can search (at top right) "basic" keyword, and select "Microsoft.VisualBasic" item.
After that you can compile your project and normally its works !
Screen for add references
2nd way :
Comment or delete "using Microsoft.VisualBasic.Devices;" instruction.
The class "Audio" should be underline to red, hover with your mouse and you have option by IDE which let you "using Microsoft.VisualBasic.Devices;".
References should be automatically added in project.
And now you can compile your project.

How to solve 'AlprNet' could not be found?

I looked for the answers here and there with no luck, so I decided to ask out.
I want to implement openalpr (open source Automatic License Plate Recognition)
repository on my own PC and I am following this video to accomplish the task. I have done all the steps he did and at the end, when I tried to build it but, in one of the .cs code there is CS0246 error that says:
Error CS0246 The type or namespace name 'AlprNet' could not be found (are you missing a using directive or an assembly reference?) number_plate c:\users\sohib\documents\visual studio 2015\Projects\number_plate\number_plate\Form1.cs
I could only find AlprNet in my D:\Projects\plate_recognition\openalpr-master\src\bindings\csharp\AlprNetTest and it is in .csproj format.
AlprNet is not in .dll format like other references so I cannot reference it in References.
I found some say that it might be because of different versions of .NET Framework platforms. I almost did nothing to check that, because I don't think it's related to .NET
In my mere opinion I should link that AlprNet.csproj to get its content, but I'm not sure. If someone can help get around this issue, I'd be very grateful.
If it's not a .net Assembly (dll) that's referenced and it's not a nuget package, then check that the code isn't expecting the Assembly to already be present in the Global Assembly Cache (If you have access to another developer machine where this works, this is easy to check).
Failing that, adding the .csproj to your .sln and then referencing it sounds like the way to go (provided you have access to that of course!).

DLL import gone wrong? Missing class

I am trying to ressurect an older project of mine in a newer Unity3D version. This is all well and good, except for a plugin that it was using is messing up.
I am using TouchScript : https://github.com/TouchScript
I updated to the newest version and everything, but i keep getting an error saying:
Assets/Scripts/Puzzle/Gesture Usage/PickupScript.cs(149,33): error CS0246: The type or namespace name `TouchHit' could not be found. Are you missing a using directive or an assembly reference?
This script has the required Using TouchScript.Hit; line. And i opened up the DLL to make sure that the class "TouchHit" is there, and it is. However when viewed in monodevelop by going to the DLL itself, it does not show at all. It shows the other classes that are supposed to be there, but not that specific TouchHit class.
I used that class, thus the error. But i am unsure on how to proceed with fixing this. I tried all sorts of import settings but no luck.
Any ideas?
Sincerely,
Smileynator
The classes in question were marked INTERNAL at some point, and documentation did not reflect this until i started looking at the commit regarding this change in feb 2014.
https://github.com/TouchScript/TouchScript/commit/ccb1a6cb44cb444618ca613fe1f8e5b15c076cc3

How to compile System.Console in C#

So I was taking a look at the source code for System.Console here.
I thought it would be interesting to see how it is implemented and possibly make some changes myself.
So I copied the source code directly from Microsoft's example and pasted it in Visual Studio.
It does not compile.
Win32Native.Beep(frequency, duration);
There are several lines like this one. All of them with the same error message.
Error 32 The type or namespace name 'Win32Native' could not be found (are you missing a using directive or an assembly reference?)
There are about a hundred error messages, but only 4 unique-ish ones. Including the main one above.
Error 85 The name '__Error' does not exist in the current context
Error 89 Cannot take the address of, get the size of, or declare a pointer to a managed type ('Win32Native.CHAR_INFO')
Error 18 The property or indexer 'System.Console.InternalSyncObject' cannot be used in this context because it lacks the get accessor
I strongly suspect I am lacking some assembly references. If you know what they are let me know, so that I can compile this.
Didn't you know that Microsoft publishes compilable source code at GitHub?
https://github.com/dotnet/corefx/tree/master/src/System.Console/src
To compile it, follow this guide.
The rational behind is like this,
The Reference Sources are already available before under a non-OSI compliant license. Due to missing files, you cannot compile them. Now Microsoft puts them under an OSI compliant license.
Microsoft is publishing reference sources plus some other private source files together to form the new open source .NET Core stack at GitHub.
You can now find https://github.com/dotnet/corefx and https://github.com/dotnet/coreclr . More things are coming, so you can keep an eye on http://dotnet.github.io/

"The type or namespace name 'XmlSerializer' could not be found" error when System.Xml.dll is referenced

I've already wasted a few hours on this one:
XmlSerializer serializer;
YES, the using is there, the reference is there, I made the entire solution in VS2010 using .NET 4.0 so it's not any of those things. If I go in Object Explorer I can find the XmlSerializer class I want in the correct namespace but if I try typing the above line in to my code file and compiling I get the dreaded
The type or namespace name 'XmlSerializer' could not be found (are you missing a using directive or an assembly reference?)
warning of death. I don't get it on IntelliSense either. All other threads/websites I've looked on have come up blank or with one of the solutions I've already ruled out. What am I missing?
Cheers
Do you build a Silverlight app?
Silverlight has XmlSerializer defined inside System.Xml.Serialization.dll assembly which is not referenced by default.
This often leads to confusion because other framework versions have it defined in System.Xml.dll.
You need to add System.Xml.Serialization.dll to project references to wire it up.
I had the same problem.
Go to Object Explorer, select XmlSerializer and choose copy. Then, paste into code
This helped me with some weird reason (no there wasn't a typo or anything like that).

Categories

Resources