Type Stopwatch not found

I am learning C # using Xamarin Studio 4.0.3 (formerly MonoDevelop) on Windows 7 . Attempting to use the Stopwatch class (snippet only)

 using System.Diagnostics; class MainClass { public static void Main (string[] args) { Stopwatch stopWatch = new Stopwatch(); } } 

I get:

Error CS0246: Could not find the name of the type or namespace 'Stopwatch'. Do you miss the usage directive or assembly reference?

My target structure: Mono.NET 4.0. According to MSDN , a stopwatch class must be implemented.

BTW, DateTime class works fine.

Question: am I missing something (the correct namespace, library binding), or is the stopwatch simply not implemented?

+4
source share
5 answers

Although you say that you have included the using directive, the error message requires a difference.

Make sure this line is in the same .cs file as a method:

 using System.Diagnostics; 

In Visual Studio, you could easily notice this:

Xamarin Studio may have a similar feature.

+3
source

I had a problem similar to this problem recently in Xamarin Studio for Mac. I was creating a PLC project for a database that needed to be used between iOS, Android and Windows Store applications.

Check the parameters of the PLC project files - right-click on the project header and select "Parameters". Proceed to creating goals and deselect Silverlight 5 / Windows Phone.

If it is a PLC, only a subset of the structure is available to you, since it contains only the functionality that can be deployed in all selected devices. Hope this helps.

Relations Brett

+3
source

I recently ran into the same problem.

My problem was that I created a new project and tried to use the Stopwatch in a new project that has no links yet.

I right-clicked my folder with new projects → "Edit Links" and added a link to "System".

Saved, built and everything is in order.

+2
source

=> The stopwatch is defined in System (in System.dll) Assemblies,

=> Check if the System.dll file is included in the Links (if it is not added, you can add it by right-clicking on the links in the solution explorer)

=> Add a namespace using System.Diagnostics;

=> More details at https://msdn.microsoft.com/en-us/library/System.Diagnostics.Stopwatch(v=vs.110).aspx

0
source

I had the same problem. All using statutes and references were in place. When pointing the brackets, Intellisense even responded to "Initializes a new instance of the System.Diagnostics.Stopwatch class", still displaying a compilation error message.
After saving the current state of the projects, closing VS, reopening VS and the project, the error disappeared.

0
source

All Articles