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?
CodePudding user response:
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