C
C#•2y ago
cyan_live

namespace missing imports after copying class [Answered]

Hi guys, I am struggling with a problem for a few weeks. So I have a ASP.NET Website project (Not web application) inside I have a folder called App_Code with many classes without namespaces inside. They magically reference each other without issues. Now I wish to copy a class to a folder outside of App_Code so for example New_Folder. I choose refactor and move the class to the New_Folder. What happens now is that every class inside App_Code can't find the class that I moved into New_Folder. Only way I am able to reference the class inside New_Folder is by giving it a namespace and importing that in the classes inside App_Code. What's the issue? Well I have 100 classes inside App_Code and after copying it to New_Folder I have thousands of missing references. Is there a way to copy classes out of app_code and keep the reference to the other classes in App_Code?
8 Replies
Cisien
Cisien•2y ago
Add a using statement in each of those files to import the new namespace Maybe webforms has some kind of magic to make it work without that (something in web.config?)
cyan_live
cyan_live•2y ago
No I tried but there is no namespaces to use. I tried giving every class the same namespace and then directly reference it using that namespace for every variable! which is hundreds of lines of code that needs a direct reference. Importing the namespace causes errors because there are classes with functions with the same name. So the class doesn't know which class function to reference and get ambiguous errors. Only by writing out every New variable and function by typing the whole reference out Application.CodeNamespace.ClassName.runFunction() does it work. Any idea how it is called?
Cisien
Cisien•2y ago
Add a namespace to the classes you move out
cyan_live
cyan_live•2y ago
I added a namespace to every class using resharper tool and moved every class inside a new folder, now I get errors in classes that they can't find the external static functions that are being called. So I try to Import the namespace of the missing class reference, now I get ambiguous errors because some classes have a functions with the same name. To fix this I have to write out every function call to the namespace of the class. So App.ClassName.FunctionName(). This if I know which class to reference, sometimes I am clueless which function of which class is meant to be called so I end up searching in the old project to see which class to reference to make the function work. Now I have to repeat this a few hundred times because this is a large code base. It's too much work, is there a easier way to move classes out of App_Code without them losing their references
Cisien
Cisien•2y ago
Sounds like a nightmare It really sounds like you just need to bite the bullet and get this code organized if you stand any chance of it being maintainable in the future
cyan_live
cyan_live•2y ago
Thanks for the info, I will start working then. 🥲
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Accord
Accord•2y ago
✅ This post has been marked as answered!