ASP NET MVC application asks static 'Main' method - c#

Building ASP NET Application I capture the following error:
Error CS5001 Program does not contain a static 'Main' method suitable for an entry point [ProjectName] [ProjectPath]\CSC 1 Active
Output type of the project is 'Windows Application'. Default namespace and assembly name match the namespace through the application. And there's just one project in solution.
The whole problem started as soon as I created entities model (based on Northwind), made some relevant changes in controller and called to create a new view. The window I received informed me
"There was an error running the selected code generator: 'There was an error getting the type [ProjectName].Models.Category'. Try rebuilding the project". [ProjectName].Models contains public class 'Category'.
I suppose it is just the result of some error, not the error itself.
I changed namespace all over the application not long ago, so I assume this might be the problem and the compiler still requires some changes to be done. But looking through the whole solution I didn't find any notions of the old namespace.
My competency in ASP.NET MVC is far from brilliant, so please any ideas how to check, what I should examine, where I should look through and/or change are welcome.

Oops, pity me. It should be "Class Library" type instead of "Windows Application". Simple mistake made me triplecheck almost all the application (and a relevant part of similar SO issues).

Related

C# beginner program

I'm using Visual Studio and when I try to compile the code below I get two errors;
CS0103 The name 'Console' does not exist in the current context
CS0017 C# Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point.
How do I fix this?
using System;
namespace App2
{
class Class1
{
static void Main()
{
Console.Writeline("Hello");
}
}
}
It looks like Class1 is not the only class that has a static void Main() method defined. Usually, when you create a console application, there's a class called "Program" that already contains a method Main. There should be no need to add another class.
Just modify the existing Main method. This should solve the second error.
The Main method is a bit like the Highlander of methods - there can only be one.
As for the first error: You do need to target the Windows platform to be able to use Console, so you need to create a Console application or a Windows Forms/WPF application or the like.
The first error is caused by a typo. To correct it, change Writeline to WriteLine (with a capital letter L).
The second error is caused by the fact that you did not specify clearly which entry point the program should use. To fix this, follow these steps:
Right-click on your project in Solution Explorer, and open the "Properties" menu. You will see the similar page and all that you should do is explicitly select entry-point.
As Thorsten Dittmar said, ensure you don't have a duplicate static void Main method,
CS0103 The name 'Console' does not exist in the current context
Ensure you did not create an Universal Windows Platform (UWP) project/Android. You can't call Console on it.
As many have suspected I fixed the error by going into the installer, modified and checked off the .NET Desktop Development.
It works now.

The argument docData must implement the interface IVsTextStream ERROR after importing image as resource

I am coding a UserInterface for our ETO Autodesk CAD Software. This is done as a simple add on in C#. Effectively its a class Library DLL placed under a certain path.
Now at the point I need to show images in the user Interface I get this message: The argument docData must implement the interface IVsTextStream.
The code is not saving anymore and eventually the complete windows form is suddenly empty.
I try to use pictureBox or add the image directly on the tab of a tabcontrol. I used different file formats like png or bmp. Always the same Error.
Hope someone can help. Internet does not show anything.
Same Problem occurs to me for a windows application. I have searched for the same issue and find somewhere that "deleting resx file from the form may help you." Well, my issue was resolve after doing so.
Hope it will be helpful for you.
VS2019 (16.9.2) Got the The argument docData must implement the interface IVsTextStream
My case happens when importing new thing to resx. (Inserting an image to the form or control also counted as importing thing to resx) I compared my project the working one and noticed wrong file dependency, I made the following fixes:
Note that this is WinForm for .NET framework, not .NET core. When creating new project in VS there are 2 separated project templates:
"Windows Forms App (.NET Framework)" <- I'm using this one
"Windows Forms App" <- This one will be using newer gen of cross platform .NET family
My fix
I found that my resx was parented in wrong fashion. MainForm.resx should be parented (dependent upon) MainForm.cs
I found that my resx was associated with wrong tool. Correct one for my form's resx is 'blank'. Note that Custom Tool for application global Resources.resx should be PublicResXFileCodeGenerator
For OP's case of blank form after error dialog
I also suffered from this, and I has confirmed that the designer somehow confused and actually REMOVED all of your form contents. This cannot be undone, unless you have version control, sadly.

WinForms - Inheritance Picker - Unable to load (irrelevant) assembly, how do I avoid it?

I'm using VS2010, and developing a C# WinForms app.
I would like to create a new form, that inherits from a form in a different dll. I right click on my project, hit 'add new item' and then under 'forms' click 'inherited from'.
At this point I get the error: 'Unable to load assembly 'X'. Ensure that the file is a valid .net framewrok assembly'. I hit OK, and then get another error for 'Y' project. They are both C# .net 4.0 winforms projects.
The important note here. I don't care about those two projects. I have 270 projects in my solution, and Neither of them are even control libraries. They are .exes.
So, the question:
Is there someway to mark the entire dll as "Im not going to be using any public types, and i don't want to ever load from the inheritance picker"? If not, is there anything I can look for that would help figure out why these 2 of 270 projects wont load?
I know I can just create a new form and manually type the actual class I want to derive from. I need visual studio to work the intended way, and wanting to avoid shortcuts. Also, i've gone through and marked every single class in both projects as either private or internal.
Thanks!

C# resx file not working after changing namespace

I am working on an existing windows form application. I only need to make few modification, during those changes i came across a scenario where i need to rename an existing namespace aswell. Now after renaming that namespace my project is not running. Although it compiles fine but breaks at the following line of code
ImageList il = new ImageList();
ImageList = il;
il.Images.Add((Image)new Bitmap(GetType(), "Images.ImageFileName.png"));//when this line is executed a dialog box appears and says that "there is no source code available for current location"
Now since i am new to .net world so i study this problem and figure that it arises due to change in namspace. I also trying renaming the namespace in the Resources.Designer.cs
but it also didn't solve my problem
Thanks All.
I find the solution by myself. The purpose of posting solution here is that may be some one else benefit from it.
Infact its a sort of carelessness from my side because i forget to change the value of Property "Default NameSpace" this property contains the old namespace that's why my resource file alwasy point to old namespace
Right click on Resources.resx, select Properties, find Custom Tool Namespace, set the namespace that you need.
Also, why don't you reference your resources in the typed manner like Resources.ResrouceName.
Here is a quick tutorial how you can setup your resources so you don't have to cast and think about namespaces: http://msdn.microsoft.com/en-us/library/7k989cfy%28v=vs.80%29.aspx
try getting rid of that second line, ImageList = il;. what it's doing is replacing a class with an instance of a class. not good.
I have also came across this issue. I had to rename the namespace of my application. After that the designer was ignoring all resources, although they were appearing after building a solution and running the application.
I found that even though I had renamed the namespace, it wasn't replaced in Application Properties under "Default Namespace" textbox. I have changed the old namespace which was still appearing there with the new namepspace and it worked properly afterwards.
That specific overload of the bitmap constructor combines the namespace of the given type with the string name of the resource and looks for a match in the assembly manifest. So in this case it would be the namespace of your class + ".Images.ImageFileName.png". I'm guessing that does not exist. Change the namespace of the Resources.resx by right clicking on it and selecting properties, do a Rebuild and see if it works now.

Monodevelop warning "Could not generate code for widgets of type: xxxx"

About 2 years ago I worked on a C# project, using MonoDevelop V1 and later V2 (beta release, compiled from source, what a mission) under Fedora. The project went dead. Now I am bringing it back to life, but I have changed my development platform to Debian (testing, i.e. squeeze), which has MonoDevelop V2.2.
I am mostly very pleased with the features of V2.2, but I have a nasty little problem. All the code compiles OK, but at the end of the compilation run I am left with lots of warnings as in the subject line. Obviously, as soon as I try and run the application, I get exceptions left, right and center when I open anything that uses these widgets.
The funny thing is that the library containing the widgets compiles just fine. But somehow these widgets (it's not all of them, only one or two) don't get exposed on the interface, and then subsequent dialogs or windows using them throw the above warning.
Has anybody had this problem? I have googled this and all that comes up is Michael Hutchinson throwing his hands in the air and saying "sorry, can't help here". I really need a fix for this, otherwise I will have to rewrite substantial chunks of code from scratch.
I would recommend trying MonoDevelop 2.4, but in any case here are some hints.
If you have an assembly which uses custom widgets implemented in the same assembly, you may be having a chicken-egg problem, since MonoDevelop needs the built assembly in order to find the custom widgets, but that's the assembly you are trying to build. This problem can be easily solved by building again the project after you get the warnings you reported. Beware, you have to build, not rebuild, since rebuild will delete the assembly and you'll hit the same problem again.
If you are not having the above problem, or if the solution doesn't work, the problem may be that the objects.xml file that contains the information about the exported widgets is not properly updated. You'll find that file in the project that implements the custom widgets, in a hidden gtk-gui folder. Open the file and check if the all the custom widgets are declared there. If a widget is missing, try opening the source code file of the widget and do a small change (e.g. a whitespace change) and then build the project again. MonoDevelop should be properly updating the file.
If you are still having trouble, please file a bug report.
I think I found a way out. Not sure whether this is the "official" method, but it seems to work.
In this library a normal widget's class definition starts like this:
namespace Amino.Common
{
//! A text entry combined with a pop-up date selector, very useful for otherwise busy dialogs
public class DatePicker : Gtk.Bin
{
If I now add two additional declarations right in front of the class statement, like this:
namespace Amino.Common
{
//! A text entry combined with a pop-up date selector, very useful for otherwise busy dialogs
[System.ComponentModel.Category("Common")]
[System.ComponentModel.ToolboxItem(true)]
public class DatePicker : Gtk.Bin
{
then
That widget gets included in the objects.xml file and
The entire solution compiles as expected (and runs as expected).
Maybe somebody could shed some additional light on this, I would love to understand this better.

Categories

Resources