How to fix namespace path after renaming a folder in visual studio? - visual-studio

I've been practicing Caliburn.micro with mvvm pattern.. till I noticed that I have named the folder"ViewModels" ModelViews which in regards to caliburn doesn't work unless you specify the standard names, but after renaming it I noticed it that visual studio still uses the old path for example when I try to call the class LoginViewModel it automatically calls this path:
using Login2.ModelViews;
event if I try to manually type using Login2.ViewModels;
it doesn't recognize it.
Any suggestion would be appreciated I don't want to restart my project.

I just solved the problem by naming the namespace of the ViewModel classes
from namespace Login2.ModelViews to namespace Login2.ViewModels hopes this will help someone in the future ^-^

Related

Is there a way in visual studio 2022 to add a new line before and after namespace?

I am using Visual Stuido 2022 to code my C# project.
Is there a way to configure VS using (.editorconfig file) where a new line is added before and after the namespace?
So my class will look like this
using System;
namespace ProjectName.Tests;
public class Test
{
}
instead of
using System;
namespace ProjectName.Tests;
public class Test
{
}
I'm not sure there is a Visual Studio native way of doing this.
There is definitely not a way to do this in .editorconfig with Visual Studio alone (meaning no plugins). About halfway down Namespace declaration preferences, it talks about csharp_style_namespace_declarations, and the code formatting sample when that value is file_scoped looks like
// csharp_style_namespace_declarations = file_scoped
using System;
namespace Convention;
class C
{
}
which appears to get you part of the way there (blank line after using). When you look at the supported formatting rules, the list is pretty brief.
If you have ReSharper there is a way. These settings in .editorconfig will do what you want:
resharper_blank_lines_after_file_scoped_namespace_directive = 1
resharper_blank_lines_after_imports = 1
If ReSharper is not an option, here are 3 possible paths to take, none all that great. They certainly aren't simple solutions.
try to find something in the Visual Studio Marketplace
write a .NET Analyzer that is configured via .editorconfig (ref. this page)
raise an issue on Developer Community, and hope they get to it.
Like the other guy said,
No, not with editor config (out of the box).
Resharper can do this; you can build a custom format for your code and tell it, for example, where you want certain sections like imports below the class for some weird reason ;) ...of course, with that spacing around those sections.
But now you have to get ReSharper licenses for all your devs. The Resharper devs are very cool, and Jetbrains has been building quality software for a few decades. Maybe I'm sentimental.
Well, there is another option if you don't want to pay...
In DevOps roles of the past, I've used Roslyn to build extensions for custom formatting.
Build a custom Rosyln analyzer.
https://learn.microsoft.com/en-us/visualstudio/code-quality/roslyn-analyzers-overview?view=vs-2022#severity-levels-of-analyzers
You can build a custom code suggestion with this of configurable severity.
It's pretty easy, too, thanks to Rosyln, but you must think a little backward. Let me know if I can help more.
StyleCop.Analyzers has a bunch of formatting related rules that you can enforce and, in some cases, automatically fix across your codebase.
Unfortunately it looks as though there is not yet support for file-scoped namespace formatting in the way you want. There's a PR to add it here, so if you really wanted to have this you could get that PR across the finish line, or make your own build:
https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3512
This issue might also be worth a look:
https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3578

Reference dll in xamarin

I am using Xamarin and I am new to it. I need to reference a dll which already uses System.Drawing due to which I am getting error. I know we can't use it because it is built aroung GDI+.
So plz let me know what should I do to successfully refer my dll. Even if I remove reference of System.Drawing from my dll then it is getting errors as it is using Bitmap, Image,Size etc. If I have to remove System.Drawing dll then how should I resolve the errors. Is there something else that can be used instead of Bitmap,Image,Size etc.
Plz help me and guide me with simple explanation as I am a beginner
As you found out there is no System.Drawing in Xamarin on mobile. Thus you might reuse sources (I assume you have those) into android(?) library and instead of Drawing types use Android (or iOS) ones. That would require code changes though.
Xamarin Droid already has such classes in framework. You don't need to reference external dll's. All you need to do to start using them is using Android.Graphics; in your class.

Adding a namespace to my permanent library in Microsoft Visual Studio

I am trying to add a custom namespace to my permanent library so that I can us it any future project. I want to just add "using MyNameSpace;" to be able to access it whenever needed. How would I go about doing this, if at all possible? I have looked every place I could think to look, but have come up with nothing. Please help.
You add
namespace MyNameSpace {
after all global using or import/include directives, in all files. Then add the terminating
}
at the end.
Do this for all source/header/etc. files.

System.Data.Linq not loaded in MVC .NET 4.5

I have an ASP.NET MVC4 Web Application project in .NET 4.5 (VS 2012). It is in VB.
It fails loading System.Data.Linq namespace (with all classes and sub-namespaces).
Project has a reference set to System.Data.Linq.dll.
Any ideas where is the problem?
When I try to add Linq2Sql classes, I get such warning:
Namespace or type specified in the Imports 'System.Data.Linq' doesn't contain
any public member or cannot be found. Make sure the namespace or the type is
defined and contains at least one public member. Make sure the imported element
name doesn't use any aliases.
and such errors:
System.Data.Linq.DataContext
But this is just a beginning: if I try to use anything from System.Data.Linq namespace I get an error, for example if I try to use System.Data.Linq.Mapping.DatabaseAttribute, I get such error:
Type 'System.Data.Linq.Mapping.DatabaseAttribute' is not defined.
I had this same problem - and was able to get past it. I'm not entirely sure which of these steps resolved the issue - but this is what I did.
I had originally created the dbml under app_code/gcm
I removed references to System.Data.DataSetExtensions
I deleted the dbml and recreated it outside of the app_code folder
I built the project (no errors/warnings)
I moved the dbml back to the app_code folder and rebuilt (again no errors/warnings)
Hope that helps you get around this.

Accessing Classes from an external project folder in C#

First off here is my file structure
Services.Abstraction.Common
Services.Abstraction.Claims
Services.Abstraction.Clearance
In Visiual Studio 2010, I am in the Claims project and I want to access classes from the Common layer which is on the same level as both Claims and Clearance. I use the namespace below in the Claims project. However it is saying the Common doesn't exists and all the functions that are in the Common folder also don't exist.
using System.Collections.Generic;
using System;
using System.Xml;
using System.Xml.Serialization;
using Services.Abstraction.Common;
How do I fix this? Do I have it wrong in the namespace or do I have to add something to my assembly?
http://msdn.microsoft.com/en-us/library/7314433t(v=vs.80).aspx
There is not much to say here... this link explain you how to add a reference in visual studio, probably you problem is that you are missing a reference to the other dll or project, am I wrong?

Resources