I have created an Error form that I like to use for multiple projects, rather than creating a new one. The Error form was created in, say, Project A. The error form is meant for catching exceptions, of course.
And now I am creating Project B. Like I mentioned, I would rather reuse the Error Form from Project A.
So here's what I did: I clicked Project -> Add Existing Item, then I browsed for Project A's Error Form's related files (ErrorForm.cs, ErrorForm.Designer.cs, and ErrorForm.resx). I am hoping to see the Error Form all in one shape in Project B. The Error Form has a PictureBox with a picture set btw.
Unfortunately, what actually happened: Then again, I was hoping to use Project A's Error Form in Project B. And then when I opened the designer, I get this error:
"The name or namespace name "ProjectA" could not be found in the global namespace". It's in this line in ErrorForm.Designer file:
this.pictureBox1.Image = global::ProjectA.Properties.Resources._2021_04_27_182907;
I commented out that offending line. As it wasn't a big deal, since I can always select the same image later from the designer window. However, the ErrorForm is totally blank, as if it was newly created!
Why is the ErrorForm blank, and how can I fix this problem?
Don't add the single form from A into B. That form uses resources from A that you aren't bringing in if you do. You should add the whole project as a project, into the solution. This is like what Ahmed mentioned in the comments,adding a dll and referencing it, except it's adding the project one step earlier, before it is compiled. This means you can tweak the code of the project within the solution rather than switching to another VS, updating the code, recompiling it, referencing the updated dll... VS does all that for you if you bring some dependent project into a solution ; it will compile the dll project A as a dependency of project B
Right click on the solution and choose add an existing project.
in the file picker choose the csproj from project A to bring the entire Project A into the solution.
Change the output type of Project A (in Project A properties) to be Class Library.
In project B, add a reference to project A, right click References, choose Add, in the panel that appears choose Projects and tick Project A
You can now, in any of your project B classes, do a using ProjectA (I'm assuming the error form is just in that namespace and not any deeper one; of it is, adjust accordingly - vs will help you if you point to the lightbulb in the margin/next to any red wiggly line) and you'll then be able to create a new ErrorForm
Related
I have merged another project in my existing project by right-clicking on the project name and selecting Add->Existing project option. Now i wan't to access the files from my newly added project from the existing one in Visual Studio (Its a C# project) , how can i do this?
If I'm following your question, you had a solution with a project A. You then added an existing project B.
You now want to access a file from A in B. If that's the case, right click on the B -> References and add a reference to project A. Now you can use the files from that project.
Edit: From your comment, I'm not sure if you want to have a separate project / file. If you want them to be only 1, you shouldn't really add a new project, you should add to your project A the files you need from project B. If you want to keep it as a different module that is included, then the above holds, but you need to realize that usually you have one solution, with many projects inside of it.
I struggle with this until I found this the link is below:
If you want all windows application to run as one program rather then calling multiple .exe. Then change 'Out Put Type' of each project to 'Class Library'.
Step 1:
You can do that by right-clicking on each Project in solution -> Go to Properties -> Application -> Out Put Type... set it to Class Library
Once you have done that output of these will be generated as .DLL.
Step2:
Add a new Window Form application project, add reference of exiting projects in it so that they can be executed from here.. you can do that by.. right click on main project-> Add Reference->Projects select all existing projects from here.
Now on the main application, you can create 3 buttons to launch each project...
[Inventory]
[Accounts]
[Payroll]
Now in each button code will be something like that...
Inventory_click()
{
Inventory.MainForm frm=new Inventory.MainForm();
frm.show();
}
Credit goes to forum post
I have a windows application (winForms). I would like to refactor it such that all functionalities are built to .DLL file so that when winForm is run, it will just call .DLL. In addition, I would be creating another .exe which is Console App so when a user wants to just "schedule task" it, he will create a config file that will run the console app, which when run will also call .DLL
I don't have much knowledge about refactoring and compiling projects to .DLL (I hope I am making sense)
I just want to know if I am correct on how I quite understand it for now:
Should I transfer all my functionalities from winForms to a class that will be compiled to .DLL? Or if I am wrong, what should I put in a .DLL class?
You should create a new project in your solution. Create a class library project in your solution in Visual Studio (or tool of choice, you did not specify what you are using so I assume VS).
To add a new project, right click your solution and select Add submenu, then New project.
From the categories menu on the left, select Visual C#, then Windows, and Class Library.
Then you should add a reference to this new class library project from your current WinForms project.
Right click References in your current WinForms project and select Add reference.
Then select Solution category on the left (VS2012), or Projects tab (VS2010) and Select your newly created class library project from there.
Then you can start moving classes from your current WinForms project to this new class library project. Class library project will be compiled as a dll and you will have access to all classes in this dll from your WinForms project.
Nothing dramatic is needed. Just Project + Properties, Application tab, change the Output type setting from Windows Application to Class Library. Done. You may have to declare a class public if you didn't already do that. You could remove your Program.cs source file since it won't be used anymore but that is entirely optional. A good reason to not remove it is keeping your project testable.
Fwiw, changing the Output type setting is not actually necessary, .NET doesn't distinguish between a DLL and an EXE at all. The CLR loads assemblies by their display name, it doesn't include a filename extension. You can add a reference to your EXE assembly in another project and it will work just fine.
So doing nothing at all already works :)
While compiling my Visual Studio C# project, i am getting the following error:
The item "obj\Debug\SampleProject.Forms.MDIMain.resources" was specified more than once in the "Resources" parameter. Duplicate items are not supported by the "Resources" parameter.
However i have searched a lot on internet but none of the solution worked for me.
I tried to delete the form and re-added it into the project, but it doesn't work for me.
I only have one resx file.
I am using VS 2010.
Also, i tried the following solutions but it not worked for me:
https://stackoverflow.com/a/7928191/2074603
https://stackoverflow.com/a/10066009
Easy!
Right-click your project and select "Unload Project"
Right-click again and "Edit your_project.csproj"
Search for the duplicate files mentioned in the error message and remove them.
Save and close.
Right-click to choose "Reload Project" view image
I had this problem recently, and I think I figured out my particular situation, so maybe it will help you.
I had used the Visual Studio IDE to copy an existing form (let's call it Form1). I pasted it into the same project (it arrived as Copy of Form1)
I then renamed that new copy to Form2.
It took me a while, but I eventually found that the IDE had renamed both Form1 and Copy of Form1 to Form2
The filenames were correct... just the actual classes inside were named.
I manually renamed the original back to the proper class and voila, it worked.
I had the same error and In my case, i fixed this problem like the follow.
Down the highlighted part was another file some_name_not_equal_to_main.resx and after removing it, my program start to run normally.
Hope this helped you.
After renaming the file, rename the class and all the constructors inside the new created file. By default, the name of the file changes but the name of the classes inside them doesn't change. So do the needful.
I just had this same problem. Not sure of exact semantics, but it is related to maintaining multiple files as partial of 'Main' form class.
In my case, the IDE got it into it's head to add form initialization routines to one of the partial class files that wasn't the 'main' form.
That created two 'main' forms and the conflict.
Simply finding the added init functions and removing them, along with the associated .resx file, fixed the problem.
If you have created a copy of form, go to properties and change the name of the copied form.
In most cases it happens when you create the copy of form. When you create copy of the form, then new form has the same name as of old one. It is not the old form's name is changed.
From this example:
I had used the Visual Studio IDE to copy an existing form (let's call it Form1). I pasted it into the same project (it arrived as Copy of Form1).
Now go to "Copy of Form1" []In case you have already renamed then it will be that name]
Go to Properties
Change Name to Form2 (or whatever class name you want)
and it should work.
Also, remember when you rename the class name, it is possible that references to the class name in the code also get changes. So be cautious of that. I will suggest after changing name, re-compile the code, so that if references are changed then you can revert back to original class name (Form1 in this case). Then you can start using your new class references.
Sometimes, partial class with the same name of another class would create this problem. Try to find out is there any two classes with the same class name. Remove/rename one of this, then your problem would be solved.
Please can someone could explain why I get this error and what to do to fix it (or what I'm doing wrong!). The steps I have taken are
Download Source code from http://www.codeproject.com/Articles/16859/AForge-NET-open-source-framework
Opening in VS2010 shows the references cannot be found
Re-Add all 3 references from PlayingCardRecognition\bin\Release so no further warnings
When I try and build or Run I get the following message
To fix this issue, do these steps:
Right click the Project name in Solution Explorer of Visual Studio
Select Set as StartUp Project from the menu
Re-run your project
It should work!
If it did not work, be sure that you have set your start page. If your project is C# Windows Application or C# Console Application, try this:
Right click the Project name in Solution Explorer of Visual Studio
Select Properties
Select the Application tab
In the Output Type drop box
Select the correct application type of your project
Re-run your project and let me know if it won’t work.
The project type set as the Start-up project in that solution is of type ClassLibrary. DUe to that, the output is a dll not an executable and so, you cannot start it.
If this is an error then you can do this:
A quick and dirty fix for this, if that is the only csproj in the solution is to open the .csproj file in a text editor and change the value of the node <ProjectGuid> to the Guid corresponding to a WinForms C# project. (That you may obtain from a google search or by creating a new project and opening the .csproj file generated by Visual Studio to find out what the GUID for that type is). (Enjoy - not many people know about this sneaky trick)
BUT: the project might be a class library rightfully and then you should reference it in another project and use it that way.
.Exe's and .dll's are both assemblies. The key difference is that executeables define an entry point Main which can be invoked by the runtime. The error
"Class library cannot be started directly"
is due to the fact that said .dll's do not have a Main. To fix this issue, change the project type to a Windows application/Console application and define an entry point. Or, add a new project that is of type Windows application/Console application and reference said .dll.
The project is a class library. It cannot be run or debugged without an executable project (F5 doesn't work!!!). You can only build the project (Ctrl+Shift+B).
If you want to debug the code add a console application project (set it as the start up project) to the solution and add the reference to the library.
The project you downloaded is a class library. Which can't be started.
Add a new project which can be started (console app, win forms, what ever you want) and add a reference to the class library project to be able to "play with it".
And set this new project as "Startup project"
The project you've downloaded is a class library, not an executable assembly. This means you need to import that library into your own project instead of trying to run it directly.
Your project type is a class library one would suspect, add a ConsoleApplication or WindowsApplication and use that as your startup object. Reference this project and then access the code.
If you convert the WPF application to Class library for get the projects .dll file.After that convert the same project to the WPF application you get the following error.
Error:".exe does not contain a static main method suitable for an entry point".
Steps to troubleshoot:
1.Include the App.xaml file in the respective project.
2.Right Click on App.xaml file change the build action to Application Definition
3.Now Build your project
Goto the Solution properties -> on Build right side you see the startup project type. here you need to select the console appication/windows appication.
If you got this issue (got it in Visual Studio 2017 RC), and you don't get any of the things listed by Mak post from step 3 onward "4 In the Output Type drop box....", it is because you made a Class Library app when you want to create a cross platform app, so here is the solution :
1 Start a new project
2 select Visual C# and cross-platform app.
3 select cross-platform app (Xamarin and native app)
4 select blank form.
From then , right click, select as startup project and build as mentioned by Mak, and it should work.
If you can afford to start from scratch, it could do the trick as it did for me.
This could do the trick for the main issue as well, but must be adapted to your current version of Visual Studio ("Xamarin.forms portable" for visual studio 2015 for example).
Bye!
VS -> Debug -> Attach unity debugger -> double click project
Set your api project to a startup project:
Right click the api Project than choose Set as startup Project.
Just right click on the Project Solution A window pops up. Expand the common Properties. Select Start Up Project
In there on right hand side Select radio button with Single Startup Project Select your Project in there and apply.
That's it. Now save and build your project. Run the project to see the output.
_Sarath#F1
To fix this issue, do these steps:
Right click the Project name in Solution Explorer of Visual Studio
Select Set as StartUp Project from the menu
Re-run your project It should work!
Need to add two same name .csproj class libraries in my solution.Have two project but unfortunately those project class libraries names are same,like: Hello.csproj.I try to add existing project on solution then show me error
http://blogs.msdn.com/b/ansonh/archive/2006/09/27/774692.aspx
from above url I learned how to use same namespace dll on same project ,but I need help how to use same classlibraries on a solution
if have any query please ask,thanks in advanced.
Note:ok people want to know the reason,i have two project on Autocat 2005 and 2010,now want to merge those project on one solution,2010 update base on 2005 so class libraries are same,but i need to use both of them.So problem arise and seeking help.
You can have projects with the same name as long as they are already created in different folders and they are in different solution folders. If the projects are already created, do this to add them to your solution:
Add your first project to the solution.
In Solution Explorer window, right click your solution and select Add->New Solution Folder
Give a name to the newly created folder.
Right click the folder and select Add->Existing Project
Navigate to your second project and double-click the .csproj file.
You're done.
If you really must do this, then ensure the second project has a different name, and then change the namespaces of the classes in the second project (normally the project name comprises the first part of the namespace - just change that part). The classes will still be identical internally, but because they have a different namespace they will be distinct entities. This will lead to very smelly code though when you start mixing them up in the ClientApp - to avoid confusion make sure you always refer to them by their full namespace (i.e. do not have a using xyz.myclassname; statement at the top of the class file that uses them).
Maybe you want to run two (almost identical) instances of the same service or something, but as mentioned it is hard to think of a genuine reason why you would need to do this. If you are looking to have two identical looking instances but different implementation then you will want to use interfaces instead.
Edit: Visual Studio will not allow you to have two identically named projects, and you are playing crazy games if you change a project name but don't change its project GUID (in the .proj file and the .sln file).
The simplest thing for you to do here is to create a new empty project in the solution explorer, right click on it and Open folder in Explorer, then copy the class files from the original project to the new one, then back in the solution explorer choose Show all files (little button at the top of the solution explorer), then select the newly added files under the new project, right click, Add to project. (These menu options are from memory, they should be roughly right).