How to compile System.Console in C# - 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/

Related

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!).

I am *not* missing an assembly or reference

I'm using Visual Studio 2013, and I'm getting an error in my C# code that I can't figure out. I'm working with the Microsoft Kinect SDK, but I'll keep it general.
I downloaded the SDK, and I can get the included sample programs to build and run. But when I try to use the code in my own project, I get the
Type or namespace name 'Kinect' does not exist in the namespace 'Microsoft' (Are you missing an assembly reference)
error.
The thing is, I'm not missing an assembly or reference. I have it added to the project's references, and the path is valid. Also, the using statements at the top of the file will autocomplete to "Kinect" for me. If I start typing using Microsoft., Kinect will appear as an autocomplete option.
What are the steps to debugging an error such as this? Could it be a 32/64 bit issue? I tried using Dependency Walker to look at the Kinect DLL, and while it throws some errors (Error: Modules with different CPU types were found.), it doesn't show any issues that I don't see with other DLLs that I'm using successfully.
What are some other potential issues that might cause a problem with DLLs not being recognized?
1 - Try going to your project settings and verify the version of the .NET framework it uses.
The best to do is to choose the same version as the external libraries.
If it's a client profile, it will very often bring that exact problem. (I'm not sure what the client profile is, but I ended up never using it...)
2 - Check if any of your references got an exclamation mark.

System.ComponentModel.DataAnnotations version reference issue on Schema

I am working with an application that uses System.CodeDom.Compiler to generate Silverlight client DLL's for use in referencing entity framework entities. My machine generates errors during the compilation process. It is not finding System.ComponentModel.DataAnnotations.Schema. This is not a .net v4 for construct. My machine we had upgraded to Silverlight 5 and discovered an incompatability with Silverlight 5 and had to return to Silverlight 4. Other machines that were never attempted to upgrade to Silverlight 5 do not exhibit this issue. The code explicitley includes a reference to System.ComponentModel.DataAnnotations when certain dataannotations are required. I have not been able to expunge this dependency to a version of the System.ComponentModel.DataAnnotations namespace that appears to be more advanced than my machine should have. I can not move forward in version as I must remain compatable with an automated build process that distributes the results of my work to clients. If I change the reference systax to work for me it will fail for everyone else. I need ideas as to how to identify the source of this so that I can eliminate it. The references within my project show correct versions, but since this compilation is done on the fly outside of my solution I do not know how I can verify the version used in the application generated compilation done later. I have trapped the error at the time it occurs, but that is not helpful, as it is providing a list of the references by name at compile time and I do not know how it resolves to the particular dll's to use at that time, and it does not appear to be finding the one I think it should or it would not be referencing the .schema namespace. Something I do not have a handle on is forcing in this reference. I think this means I have something on my machine using an entity framework reference later than v4.3 but I think my machine has only v4.I am looking for thoughts on how I can track this down.
I have done many generic searches on this problem, finding many references to this particular error, some of which are on this site, that indicate I need to be looking for a problem with the versions of the DLL's, but I am not sure where the compilation is pulling the dll's from and the ones I have checked appear to be the correct version for the namespace System.ComponentModel.DataAnnotations so I think my problem must be being picked up from something else.
There are 2 not specifically Silverlight 4 assemblies listed as inputs to the compiler. My two source files do not cause the reference, so I think if must come from one of these.
...\bin\RIAServices\v1.0\Libraries\Silverlight\System.ServiceModel.DomainServices.Client.dll
...\bin\RIAServices\v1.0\Libraries\Silverlight\System.ServiceModel.DomainServices.Client.Web.dll
The actual error generated is:
The type or namespace name 'Schema' does not exist in the namespace
'System.ComponentModel.DataAnnotations' (are you missing an assembly
reference?) with an additional tage of: error CS0234.
Most posted solutions involve an upgrade to a later version of Dot Net and/or Entity Framework and those are not available to me.
I am no expert on Entity Framework or RIA Services and may be overlooking something fundamental.

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

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?

How to fix C# error "The type or namespace name '[x]' could not be found (are you missing a using directive or an assembly reference?)"

I would like to use the open source code from here - Roger Lipscombe's .NET wizard form classes.
Unfortunately for me my target is a Windows Mobile 6.5 device and not a Win7/VS 2010 project. So since I could not use the projects as is I decided to create the two dependency projects by hand for the mobile device in VS2008.
Things seemed to go well until I tried to compile.
I am not sure now why i get the following error:
Error 1 The type or namespace name 'CategoryAttribute' could not be
found (are you missing a using directive or an assembly
reference?) C:\Development\SmartDeviceProject1\Wizard.Controls\EtchedLine.cs 50
The line of code is:
[Category("Appearance")]
I think the open source project is using .NET 2 and the mobile project is 3.5.
I am a C++ developer trying to make a mobile app with a wizard UI.
Can someone perhaps point out what I may be missing and what this error means and how to fix it?
EDIT
Thanks all who answered.
Commenting those decorators out fixed the problem (though I have a lot of issues apparently with things that are NOT supported in the compact framework. Oh well - it wa worth a shot)
The CategoryAttribute is used when the control is loaded in visualstudio i.e. when editing the form and how to find the associated property in the property grid. You could probbaly just comment it out with no ill effects. The associated property will just appear somewhere else in the grid.
The category attribute can just be commented out without any negative consequences.
If you have that error with other code, ask again and we'll try to help you find an equivalent for .NETCF or a workaround.
It appears that [Category("Appearance")] adds a new Design-time option in the
Designer under the "Appearance" category in this instance.
Note that in the examples that I've found use [CategoryAttribute("Appearance")]
The property is then followed by a variable, as the sample you've provided would allow you to set a color for Light and Dark of an etched line.
Here is a very detailed article on the subject, however the line of code [Category("Appearance")] may not be required as it's for the Designer only.
http://msdn.microsoft.com/en-us/magazine/cc164159.aspx#S8 - Figure 11

Categories

Resources