I'm following quill18creates C# tutorial series on youtube. I'm on video #3, where we start discussing classes and the main.cs script to execute code.
I've copied his example verbatum and started the project EXACTLY as he did in xamarin studio but no matter what, the compiler does not seem to want to accept the code.
Code:
using System; // We need the standard .NET library for many things
namespace DodgeGame
{
class DodgeGameMain
{
static void Main()
{
}
}
}
C:\Users\Aspen\Documents\Projects\DodgeGameSolution\DodgeGame\CSC:
Error CS5001: Program does not contain a static 'Main' method suitable
for an entry point (CS5001) (DodgeGame)
I've noticed that his Xamarin Studio is detecting a "document outline" while mine just says "an outline is not available for the current document". I've tried to save as. the file but that didn't change a thing. So what's going on?
You'll notice from this pic it's not displaying the class in green either:
Change the Output Type under the Project > Properties to that of a “Class Library”. By default, this setting may have been set to a “Console Application”.
OKAY! So props to Victor Leontyev for suggesting to make a clean solution.
I exited, deleted the project. Remade it and this time upon creating the empty file, I checked "add to project" this time. It was off by default for some reason and wasn't even an option at the time the tutorial was made.
This solved all the problems and copy/pasting the code back in seemed to find the classes and compile correctly. A very simple oversite that caused so many problems. Doh'
Related
I got back into my project after a week of not touching it, and intellisense suddenly just isn't showing stuff, and also highlighting is gone. This happens for any class that is imported or created by me, for example:
using Android.App; <- Doesn't get highlighted
using System.Linq; <- No highlighting
Android.Support.V7.Widget.Toolbar t; <- Not highlighted
string s; <- Gets highlighted
EventArgs e; <- Also highlighted
Intellisense isn't showing anything besides system classes, and also imported system classes like linq, but isn't showing anything from imported android stuff, or classes written by me, except for the current class:
File1.cs:
class Example1 {
//Intellisense suggests Example1 here
//But it doesn't suggest Example2
}
File2.cs:
class Example2 {
//Intellisense suggests Example2 here
//But it doesn't suggest Example1
}
I tried restarting VS and my computer, cleaning and rebuilding (the project compiles), and also resetting my import/export settings.
Build the project. > Close solution. > Reopen solution. This fixed this for me.
I am an iOS developer which has been asked to do development in Xamarin. I want to log the outputs in Xamarin.
I am trying to find a library for this. I found one library for this called MetroLog.
Link : https://github.com/onovotny/MetroLog
But the problem is I am getting blue coloured output for every log level.Like this:
I was expecting that the errors would be in red , warnings would be in orange, and others in green or blue or something, but I could not get the required output in the manner I thought I would. I am running sample project from their repo , which has source code as follows:
_log.Info("Information - We are about to do magic!");
_log.Warn("Warning!");
_log.Trace("Trace some data.");
_log.Error("Something bad happened at {0}", DateTime.Now);
_log.Fatal("Danger Will Robinson!");
Are there some changes that I need to make to the logging project when it has been added to my project?
Is there any other library which can solve my use case for logging ?
If not then how can I achieve similar and coloured option from MetroLog ? I am open to other options(open source project) as well.
MORE INFO or EXTENDED QUESTION:
As I am used to iOS development I used to use the following statements in order to log the information:
NSLog(#"%# %# started" ,[self class] ,NSStringFromSelector(_cmd));
NSLog(#"%# %# ends " ,[self class] ,NSStringFromSelector(_cmd));
I am expecting some sort of quick logging option like the one for iOS as shown above without including any library. Is that possible?( including the class name and the method name which is executing the code)
Thanks.
I have not use MetroLog but, in general, such libraries requires you to set a destination / endpoint / server for your logs. The default one is often the basic one offered by the OS (which is the one that Xamarin Studio will redirect) and that won't give you coloured output.
Quick Logging: Every string given to System.Console.WriteLine ends up calling NSLog on iOS. Since that's part of mscorlib.dll (SDK) there's nothing else you'll need to add to your project to use it.
So I'm trying to implement soundeffects whenever I click on an item. I've added a .wav sound to my Content folder.
Then I typed the following code in the Game1 class constructor:
SoundEffect soundEffect;
After that I wrote the following code in the Initialize function:
soundEffect = Content.Load<SoundEffect>("Laser_Shoot25.xnb");
Finally, I wrote the following code in my clickFunction:
soundEffect.Play();
When I tried running it, it gave me the following error.
Could not load nameOfSoundFile asset.
I've looked on Google to see if someone else had this same problem, but none of those solutions seem to work for me.
Does anyone know what else I'm supposed to do to make this work?
First thing that comes to mind is the possibility of you loading your assets before the Content object gets initialized. Please post the relevant code where you load your asset to know if this is the case (usually the initialize and LoadContent methods of your Game1 class).
The other possibility is the asset file format.
I'm not up to date with Monogame as I stopped using it with version 3.2, but if things remain the same on this aspect; then for working with sounds and spritefonts you need to add the asset as an exported xnb file, created by using the actual XNA content pipeline.
I have a blog post that explains exactly how to do all of this, which can be found here.
First, you need to install XNA on your machine (in the same post, it explains how to do it if you have Windows 8 and/or Visual Studio 2012/2013).
Then, just follow the steps detailed on the post:
So, once we have this, let’s create a new Windows Game project (it has
to be a game and not only a Content project as we will need to access
the game output directory).
After having this done, we can add our sound effects/instances to the
Content project by right clicking, selecting “Add existing item” and
choosing it in the folder explorer.
Before continuing, make sure you set the properties of the sound as
desired (in my case, I’ll be using a SoundEffect so I need to specify
it in the Content Processor field):
All that remains is to add the xnb file to the Content folder of your
Monogame project.
My issue is: during Debug Mode in Visual Studio I can not see property name and it value. Any suggestions? UPD This bug/feature is reproducible in college PC.
UPD(15.06.2012)
The base class is placed to separated lib. Base class is abstract. And... Two times Debug was working fine, after making changes in source file (in screen-shots) and then running the project.
Please notice that Immediate window can not evaluate this expression.
MailProcessingViewModelContext inherits that base class that I have mentioned in the top of UPD.
It's a bug in Visual Studio that's caused when you scroll through the properties list with a mouse. Click the down arrow at the bottom of the menu instead.
As somebody on top already mentioned, you need the debugging symbol files (.pdb's) for every dll that you are using which is not your code, otherwise VS can't look 'inside'.
and if it's obfuscated you won't see anything at all
This would happen if you were debugging an ASP.NET wizard and wanted to check a collection of something, all elements in the collection that are in the current wizard step (current context) would be visible while the others are there but not in context just now hence marked as questionmarks -> ?
Maybe it could be something like that in your case. I guess it could be the same scenario
For me, this happened when I had a getter property in a class model pointing to itself. It was a copy paste error, notice the property name is ShouldNotProcess, and in the getter it's returning itself. The return was supposed to be: return !this.ShouldProcess;
public bool ShouldNotProcess
{
get { return !this.ShouldNotProcess; }
}
Are you trying to debug your own code or someone else's?
If it's not your code, the code has probably been obfuscated so you cannot see the private members or use reflector to reverse engineer it.
This also might happen if you're using a trackpad to scroll through the member list. Try using the keyboard instead.
You cannot access these menu items or display these windows in design mode. To display these menu items, the debugger must be running or in break mode.
REF:
http://msdn.microsoft.com/en-us/library/bhawk8xd
Is there a possibility that the object you are referring to belongs to another project (library template) and you added it as a file reference and not project reference?
Please share the details about the structure of the projects in your solution. Also the location of the class you are trying to access.
Make sure you're running in debug mode, I know I'm probably stating the obvious there. Also, check that expression you're evaluating - is it right? Are you casting to the right object. Finally, is the assembly that contains the class you are looking at included as a project in the solution, or just referenced as an external assembly? Make sure it's part of the sln.
If it's recreatable on another copy of visual studio then I'd guess it's not a problem with Visual Studio, but the object you are looking at.
Not sure if this is the case in your situation, but here is a post with a similar issue. Hope it helps
I am experiencing some weird behavior of Visual Studio 2010 when developing Silverlight applications and using project resources (.resx)
Everytime I change a resource it sets itself to internal instead of public in the code behind, altough I can see it in the design mode as set to public it is not.
Any idea how to fix this?
I don't know if this affects only Silverlight projects or generaly all C# projects.
This link might help.
http://blogs.msdn.com/b/silverlight_sdk/archive/2010/09/08/ach-du-lieber-a-tour-of-some-localization-gotchas-in-silverlight.aspx
It says:
Turns out there's a flaw in the VS
build action logic here; unfortunately
changing this tool action will NOT
flip the access level of the class
constructor from internal to public
(at least not for a strongly typed
language). A public constructor is
another requirement of Silverlight
XAML usage of a class. You will have
to do this yourself manually in the
designer.cs file.
Hope this helps
EDIT:-
Here's another one http://www.wintellect.com/CS/blogs/jprosise/archive/2010/06/21/dynamic-localization-in-silverlight.aspx that says
Finally, Visual Studio suffers from a
long-standing bug that leaves the
constructor of the ResourceManager
wrapper class it generates marked
internal when you change the class's
access modifier to public. This means
that whenever you modify the primary
RESX file, forcing a code regen, you
have to manually change internal to
public on the constructor in the
generated code. It beats me why this
hasn't been fixed after all these
years, but it hasn't.
My approach consists in configuring a pre-build event that replaces "internal" with "public" in your .Designer.cs file. I have a post on my blog about the whole process, from creating the localized string to binding them and configuring the pre-build event command line.
The hearth of the process is to get a text-file replace utility (say it's called REPLACE.EXE) and set a pre-build action like this:
c:\utility\replace\replace.exe "$(ProjectDir)\LocalizedStrings.Designer.cs" "internal" "public"
$(ProjectDir) is a VS built-in macro that returns the path to your project folder.
I also gave an example of such a simple replace utility source code on same post.
The best solution is to switch the tool used to generate the resource code behind .cs file to one the automatically outputs the constructor as public instead of internal. The best one I have found is from Guy Smith-Ferrier. Download and run the installer and then change the "Custom Tool" property of your .resx resource file to "PublicResourceCodeGenerator".
Workaround:
Inherit another class from the generated one
public class TextRes2 : TextRes
{
public TextRes2() { }
}
and use that instead of the original
<ResourceDictionary>
<!--res:TextRes x:Key="Strings" /-->
<res:TextRes2 x:Key="Strings" />
</ResourceDictionary>
There's a problem with all of these solutions - at least in our case.
Our resource files are all modified by a 3rd party codegen tool which updates the resource files to match the changes made in the UIs. All it does is update the strings in the xml. we still have to go in to the VS and toggle the Access Modifier from Public to something else, and back to Public so VS will synchronize the code-behind to match the new string values. THEN we have to update the c# by changing internal to public.
So for us, we need both steps automated, rebuilding the code behind and the fixing internal.