Refactor LINQ-to-SQL class in new namespace - c#

I have a LINQ-to-SQL Generator class in a project I'm working on, and to conform to naming conventions, the default namespace has to be a little different than the name of the project itself.
Essentially, it has to be GroupName.ProjectName, instead of just ProjectName.
I can manually rename stuff and that's fine, except for the LINQ-to-SQL class we have in the project.
Renaming the namespace manually just causes the change to be wiped out next time the tool is regenerated. Any help on getting this refactored properly?

Nevermind. I am an idiot and thought this would be handled at the solution level and not the project level. For what it's worth, right click on your project file, click properties, and edit the "default namespace" field.

Related

class name change in a dll project wont update?

In a dll solution, I changed the main public class (namebase) to have a better name EasyXML.Settings class has now becomme EasyXML.XMLconfig.
namespace EasyXML
{
public class XMLconfig // i changed this name and its constructor.
{
When compiling i did a clean solution first and then i compiled both debug and release versions for this .dll
Another project already used the older version, but needed to update to the new version. Thus I removed references to the old dll, and removed old dll, added the new version of the dll, and created a reference to it again.
However somehow that other project doesn't recognize the updated class name XMLconfig. (not on clean builds either), it behaves like if it is cached or so.
I'm not sure, do i need to do additional actions on the dll solution, or on the other project?, to refresh those names.
There must be a simple explanation for this:
make sure there aren't any errors in the second project (otherwise VS most likely fails to update the class names from the dll)
make sure by adding the reference of the dll to the second project you are referencing the right file (use solution tab instead of browse)
make sure your dll project was actually compiled. (There are several cases where the project didn't compile but the solution build was successful). Check the modified date of the dll project output and make sure it isn't an old one.
you can go to project->properties->build->output path and project->properties->build events and make sure the output for the current build configuration points to a right location
make sure both projects use the exact same version of .net framework
other than that:
make sure the class name (XMLConfig) is not exact match of a namespace (EasyXML) otherwise the class might get inaccessible to the VS user
make sure there aren't any partial classes in dll project with the same name.
make sure there aren't any other classes somewhere else with the same namespace and class name

The Type does not Exist in the namespace. Are you missing an Assembly?

I have 2 C# projects first one name is "Advocar" and the second one is "Import".
There is a class in Advocar project which we need to access to that from Import project. So in Import project I added reference to Advocar.
The problem is from Import project I recognizes all the Advocar classes except the new class that I just created in the Advocar. and when I build it, it say "The Type or namespace does not exist in the Advocar.Data.Inventory namespace. Are you missing an assembly?", but the class is exist in that namespace.
I build Advocar project and re-add the assembly to the Import project and it did not help. Both project are in .NET 2.0.
Any Idea please?
Check the access level of new class added into the namespace.
Ok. I found the solution although I dont know what would cause that.
since 40% of all the classes that I have are the same code, so to create a new class I just copied and pasted one of the existing class and made changes on that one.
So to solve my issue, I deleted the new classes and I just Add New Item and create a blank class and past the code that I needed to the new class and it fixed that.
Its look like some kind of caching issue that although you rename a class and so on, but it still has some record from past.

App_Web_XXXXXXXX.X.cs type or namespace not found

I have a web application that is giving me type or namespace not found errors. The bizarre thing is that the errors are happening in an auto-generated file App_Web_XXXXXXXX.X.cs. How can I figure out which file is auto-generating this file so I can fix this issue?
I hit this today using VS2013 and MVC4.
In my case I had added a new Model class, referenced it in a couple of places (a view and partial view) and then excluded the class and the referencing files from the solution / project. When everything was excluded I could not get the project to compile. I added the class and referencing files back in (e.g. "included" them) and then it built just fine.
I subsequently excluded the files that referenced the new class and it rebuilt successfully.
I then excluded the class and it failed again.
Then I included the class and commented all its code out and the compiler returned errors from the referencing files, which were excluded. Very strange. So apparently excluding files from the solution doesn't prevent them from being picked up during builds.
What ended up working for me was to simply make a backup of the files and delete them rather than excluding them.
HTH,
Andy

Properties does not exist in the current context

I have to store some strings in the Settings file of my project. However, I am not able to access the Settings file to store the strings.
I definitely have accessed Properties file in an earlier project without facing any problems to store values.
Properties.Settings.Default.test = ...
MyApp.Properties.Settings.Default.test = ...
But here in the current project, I am constantly being driven mad by getting the Properties does not exist in the current context
Is there any setting or something that has changed because of which Properties does not appear in Intellisense?
I had this same problem occur when I had been copying and pasting code for plug-ins. It turns out that I had accidentally left the namespace of the other project in place when I copied. By changing the namespace back to the appropriate project, I was able to use the Properties.
at compile-time, Visual Studio generates a c# class which allows access to user and application settings. the generated class is defined in the default namespace specified in the project settings.
you may have to prefix any access to the Properties namespace with the default namespace defined in the project settings;
or you may change the default namespace: go to project settings, application tab, and edit the default namespace of the project.
Make sure your project has a settings file by going to the project properties and clicking on the Settings tab. If there is no settings file, it will tell you so and provide you with the option to create one.
I had this error when I accidentally had the wrong namespace as the Default namespace in the project properties.
To choose the default namespace, right click the project in the Solution ExplorerProperties->Application tab->Default namespace and check that it matches the namespace of your .cs files:
[...]
using System.Text;
using System.Threading;
namespace Correct.Namespace //<-- should match Default namespace field
{
static class Program
{
[...]
In my case, i have referenced a resource that has an Internal/Public access modifier. I have changed its access modifier to Public and the problem was gone.
First, try to recreate your project from scratch, if it's your testing environment. This step will recreate default namespace properly. You may skip this step if you are confident with your namespace configurations.
Second, if you still get Properties unrecognize as in my example where im trying to get data from sqlCon.
string connectionString = Properties.Settings.Default.sqlCon;
go to Project -> EventsandDelegates Properties as shown in the picture below. Make sure to create default settings file.
As soon as you create default settings under your Application settings, in my case it's SQL connection variable. Properties error will go away.
I just had the same problem. But the problem occured when I added a new setting to an already defined settings file (created a long time ago). Somehow adding a setting to the settings file made Visual Studio change the setting's namespace to the project default namespace (which had changed since the settings where modified last time).
So, because the settings access modifier was set to Internal, and the class trying to access the settings still where in the old previous namespace (still in the same project though), the settings became invisible from that class.
Quickest Solution i can offer is to double click on your resources.resx file if it exists, than change the Access Modifier Property at the top of the window from Internal to Public, Rebuild, which should compile successfully, then switch it back to internal and rebuild again. Should be fine after that.
In my case I was referencing one project (A) from another (B). Both in the same solution.
A has a public class (AClass) with a public static method. (AMethod)
I wanted to Test the results of this AClass.AMethod(...)
Visual Studio "colored" AClass in the call AClass.AMethod(...)
and I could right-click AClass and "Go to Definition",
which took me either directly to the source if I added referenced to the "Solution" project
Or to the DLL "outline" if I added reference to the DLL created by building Project "A"
But when I tried to build project "B" I got the error "AClass does not exist in current context"
It turns out Project B was targeting 4.5 and Project A was targeting 4.5.2
This answer helped: https://stackoverflow.com/a/15556365/1175496
Make sure you can see your setting in Settings.Designer.cs file. If not, try deleting and reentering the setting. For some reason, sometimes, the code auto generated by the tool does not include your setting. In that case, the setting wont be available in intellisense.
Funny, but in my case, I had defined the Properties in one project in the solution and was trying to access from another.
Hope this might help someone.
My issue with the "does not contain a definition for 'Properties'", was caused by adding a class to the namespace (JsonBreaker), with the same name as the namespace (ie JsonBreaker.JsonBreaker). Its notable that it was breaking compilation, as it seems some other folks are having a different experience.
namespace JsonBreaker {
public class JsonBreaker {
private readonly Options _opt = null;
...
I just changed the classname (and .cs filename) to Breaker, and my JsonBreaker.Properties.Settings.Default["InteractiveMode"] call started compiling again.
namespace JsonBreaker {
public class Breaker {
private readonly Options _opt = null;
...
I had this problem when running my web project in Visual Studio 2019. After unsuccessfully trying some of the solutions here, I closed VS2019 and re-opened the project from VS2017. Now the Properties namespace is being recognised.
My case:
I added a new database in the Solution Explorer
I tried:
string connectionString = Properties.Settings.Default.SlovickaSQLConnectionString;
My error:
I get:
Properties does not exist in the current context
Here is why:
I forget to add a new dataset in Data Sources panel.
This dataset has to be connected to the previously added database.
And now it works..

C# asp.net - The type or namespace name 'Helper' could not be found (are you missing a using directive or an assembly reference?)

I'm reworking someone else's code, where they had a helper class with way to much code that shouldn't be there (data access, business logic, everything had slowly been shoved in there).
I've moved the relevant code into the appropriate pre-existing classes and created a separate, brand new helper class in the appropriate project, but all my references to this class simply don't work.
Here's a simple view of how my class looks (names slightly changed);
namespace Company.Web.Application.Reporting
{
public class ReportHelper
{
here I have a bunch of methods
}
}
and here is how it is being referenced;
using Company.Web.Application.Reporting;
namespace Company.Web.Application.App.Reports
{
public partial class PlansReports : PageBase
{
//This is the problem part
private ReportHelper Helper = new ReportHelper();
heaps of other code with no problems here...
}
}
My problem is that the I get the following error, everywhere that I try to access my new helper.
The type or namespace name
'ReportHelper' could not be found (are
you missing a using directive or an
assembly reference?)
All my using statements are there, I have the appropriate references in each relevant project, yet this still persists.
At this point I am totally stuck, I just need to get this referencing issue sorted out so I can ensure all my helper methods work correctly.
Any help is greatly appreciated,
Pat.
OK, I found the problem (actually a colleague did)
This original Helper class was contained in the app_code folder of my main project, which as I have just learned, handles compiling differently to all other folders in a project.
Code in here is compiled at run time, rather than during the build.
When I created my new classes, they were in the app_code folder because I used code rush to extract the class to a new file, which kept it in the same location...after which I moved them to their "sensible" location.
Unfortunately they still had the build action of "Content" inherited from their previous presence in the app_code folder.
So, on the new class file, I simply changed its build action to "Compile" and now all is well with the world.
Cheers,
Pat.
Is your ReportHelper in a separate project or DLL? If so have you added this project/dll as a reference? (In your solution explorer under References, check your project/dll is there.
Have you built Company.Web.Application.Reporting so that the type would be known? That would be my idea along with ensuring that the dependencies are set up properly.
It sounds like you know what you are doing and everything looks right, so it has to be something simple. Are you trying to access changes in ReportHelper that haven't been compiled into the dll? I would try rebuilding the reference assembly; every time you make changes to that assembly, it needs to be rebuilt.
Also verify you are adding the correct assembly (e.g. Debug vs. Release) to your project. It doesn't matter which type, but you don't want compile new changes into the Debug dll, and keep adding the old version of the Release dll.

Categories

Resources