How to implement IVsStatusbar when making a Visual Studio Add-In - c#

I am trying to create a visual studio add-in, and one of the things I will need to do is interact with the status bar. According to MSN: Status Bar it should be a fairly straightforward process. However, I cannot get it to resolve properly on the IVsStatusbar object.
The example suggests following a pretty standard process such as:
IVsStatusbar StatusBar = (IVsStatusbar)GetService(typeof(SVsStatusbar));
But Visual Studio will not resolve the reference and tells me IVsStatusbar does not exist. If I right-click to auto-resolve, it will just tell me to generate a new class for it.
I know it requires Microsoft.VisualStudio.Shell.Interop which I added, but still no luck. I have tried v 10.0 and v 11.0 of the dll, but neither have worked. Does it no longer exist in the namespace? Or is there another reference / object I should be using?
I should have all of the references I need:
using System;
using Extensibility;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.CommandBars;
using Microsoft.VisualStudio.Shell.Interop;
using System.Resources;
using System.Reflection;
using System.Globalization;
using Microsoft.VisualStudio.Shell;

You need to reference all of the versions of Microsoft.VisualStudio.Shell.Interop.xx.dll, not just one of them. Rather than change interfaces over time, they create a new assembly with added interfaces which the services implement in addition to the previous versions.
Edit: Note that this only applies to the Interop assemblies. For other assemblies, such as Microsoft.VisualStudio.Shell, you only need to reference version 10.0 (for a Visual Studio 2010 or 2010+2012 extension) or version 11.0 (for a Visual Studio 2012-only extension).

Related

C# using System.Xaml missing assembly reference

I'm writing a C# Console Application that is targeted towards .Net 4.5. I want to use Xaml Services to save and read a List data structure to file. I'm using VS 2013 Pro.
The .net doc's say Xaml has been in .NET since 4.0(?) I have my projected targeted to 4.5, but even with 4.0, 4.5.1, 4.6, and 4.6.1... same missing assembly reference. I'm doing a
using System;
using System.Collections.Generic;
using System.IO;
using System.Xaml; // <-- this is getting the assembly error
using System.Xml;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
But that is where the missing reference is getting the error...
I've used it before in Win Forms. It is that maybe it's excluded for console applications? Or am I missing something that Xaml Class depends on before using that assembly?
Could it be that you did not add a project reference to the assembly "System.Xaml.dll"? The Xaml functionality is not contained in the assemblies which are included in a new VS console project by default. (Right-Click on the "References" entry of the project, then select "Add References", then browse to "Framework" and look for System.Xaml, which refers to the dll of that name).
A namespace however does not necessarily correspond uniquely to an assembly, so you might require even more assemblies. If you know which types you need, you can browse the MSDN documentation for looking which assembly might still be required.

unable to find the namespace of a third party api

I have received a .dll file from a partner firm with an API that will be used for database logging. I have added it to the references and can see it in the Solution Explorer. The documentation provided gave me a code snippet which references the file with a different namespace than the file name. I am using Visual Studio 2013 Express.
using com.XXXXX.XXX.microsites.api;
When I want to use the EntityFramework, it is simply the name of the reference.
using Microsoft.AspNet.Identity.EntityFramework;
The reference is not even showing up with a different name when using IntelliSense.
I am using the recommend framework ASP.NET 4 in the documentation.
I am using the code snippet they provided.
I would personally use dotPeek (https://www.jetbrains.com/decompiler/) to decompile the assembly and see what the defined namespaces are. Not sure if there's anything build in to Visual Studio.
If you added the dll reference in your solution then try opening the dll in object browser and see if you see the namespaces listed there and then use the one needed.

I can't use ActiveUp.MailSystem.Net

I'm trying to use ActiveUp.MailSystem.Net which I downloaded from here:
https://mailsystem.codeplex.com/
I added all the dll-s through the add reference option. Now Using ActiveUp, Using ActiveUp.Net are working, but for the Using ActiveUp.Net.Mail I get the error The type or namespace name 'Mail' does not esist in..... I also added the dll-s to the resources but no luck. What makes me that noob?
P.S.: I'm using Visual Studio Express C# 2010

WCF - Cannot resolve [WebGet] symbol - what am I doing wrong?

I am working on a REST WCF project and when I implement the following code, it complains that it can't resolve the WebGet class? What am I missing?
I tried importing the System.ServiceModel.Web namespace but it can't find it even though I referenced it. The "Web" in System.ServiceModel.Web does not register when I register it in a using statement on top of my code.
Basically, what do I need to implement such WCF REST concepts like WebGet, WebInvoke, UriTemplate, etc?
UPDATE: After some feedback and thinking about this a little bit more what I've done, it seems that the DLLs (System.ServiceModel & System.ServiceModel.Web) do not come up via the 'Add Reference' window when I go to add a project reference. When I first started the project, FYI, since these assemblies did not come up at first, I went 'searching' for them, and copied them to a temp folder so I can reference them and thus, I guess I am having the resolve issues. So, now that I am at this point, how can I get my VS to recognize/register these WCF REST DLLs? Thanks!
UPDATE: I believe I am update-to-date on everything: developing on VS 2008 SP1 - I try to download the latest SPs, downloaded the REST Preview 2 Starter Kit, developing against 3.5 Framework, trying to create a WCF REST layer to ultimately be consumed by Silverlight 2 client.
This is what I have:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using UtilityClasses;
using Microsoft.ServiceModel.Web;
using Microsoft.Http;
namespace WcfRestService
{
[ServiceContract]
public interface IRestService
{
[OperationContract(Name = "Add")]
[WebGet(UriTemplate = "/")] // ** can't compile here **
int Add();
}
}
Any advice will be greatly appreciated it.
You need to reference the System.ServiceModel.Web DLL.
Right-click the 'References' folder in your project and choose 'Add Reference...'. Scroll down to System.ServiceModel.Web and click 'OK'.
Just a one thought, you might be targeting your project to .Net Client Profile which exposes limited namespaces. you may need to check the target framework setting at your project properties.
I have faced that with a WCF project not finding System.ServiceModel.Web untill I changed the default framework settings.
HTH
This happened to me too.
I did this:
Delete System.Service.Web from References
Build
Clean Project
Add System.Service.Web to References
Build
..and VS found it??
In "project properties" make sure your "target framework" is set to : .NET Framework 4
and not: .NET Framework 4 Client Profile, or any lower .NET version.
Also, if possible use VS 2010.
--DBJ
right click on the project name and choose Properties.
change the target framework to .NET Framework 4.
right click on the References and choose Add Reference.
And then you can see System.ServiceModel.Web.
By default the target framework is .NET Framework 4 Client Profile,
so you cannot find the System.ServiceModel.Web.
I had the same problem.
I have added this missing reference:
System.ServiceModel.Web
and this code line:
using System.ServiceModel.Web;
and all got solved! ;)
using System.ServiceModel.Web;
In my case my project was building despite this warning in the designer view of the service class. Not really a big issue, but still pretty annoying. Realised it was just ReSharper playing up - it hadn't updated its internal cache when the reference to System.ServiceModel was added automatically by VS when I added a new WCF Service. I turned off real-time code analysis in:
Tools -> Options -> Resharper Ultimate -> Options -> Code Inspection->
Settings -> Enable code analysis
This restored the built-in VS code analysis, and problem was fixed straight away.
If you'd prefer to keep using ReSharper code analysis, clearing the cache in:
Tools -> Options -> Resharper Ultimate -> Options -> Environment ->
General -> Clear Caches
may also sort the issue.

Referencing namespaces globally?

Is there a way to reference a namespace globally across the whole solution?
So instead of having these lines in every code file:
using System;
using MyNamespace;
having to declare them only once, and every code file would use them.
Btw I am using Visual Studio.
No, C# doesn't have this concept. Each source file is independent in this respect. (And if the using directives are in a namespace declaration, those are independent from other using directives in peer namespace declarations, too. That's a pretty rare case though in my experience.)
You don't need ReSharper to change what gets included in a new class though. You can use the Visual Studio templates.
EDIT: Just to clarify the point about using directives within namespaces, suppose we had (all in one file):
using Foo;
namespace X
{
using Bar;
// Foo and Bar are searched for code in here, but not Baz
}
namespace Y
{
using Baz;
// Foo and Baz are searched for code in here, but not Bar
}
Usually I only have one namespace declaration in a file, and put all the using directives before it.
No, this is not possible.
If you're using ReSharper, you can set an option to include specific using directives in every new file you create though.
From this SO question and follow-up blog post. You can edit the Visual Studio default templates.
To do this, look at the file in this zip : [Program Files][Visual Studio]\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip
and modify the Class.cs file as needed. Additionally, Visual Studio may have cached this file here :
[Program Files][Visual Studio]\Common7\IDE\ItemTemplatesCache\CSharp\Code\1033\Class.zip
In C# 10.0 you can use Global Usings.
global using System;
global using MyNamespace;
No, you can not reference a namespace globally across the whole solution in .NET or .NET CORE.
But you can use project wise namespace globally in solution. this feature will be available from c#10/.NET 6. currently it's in preview but it will be released in NOV 2021
=========Project level .NET 6 global using namespace=========
Create a class file at root of the project e.g GlobalNamespace.cs
global using System;
global using System.Linq;
global using System.Text.RegularExpressions;
global using System.Threading.Tasks;
Then you don't need to declare using namespace in other .cs files of the project which are already declared globally.
As others have mentioned Visual Studio Templates are the way to go.
Note that simply adding a using statement to your template will not ensure that the compiler can resolve your types. So, if you are adding a using statement for MyNamespace in every class you may need to add an assembly reference to your project as well. See the C# FAQ for more information.
One trick I miss as a newb to CSharp is to look at the "refences" (in VS), to right click and "Add New Reference". This is especially handy when combining mulitple projects where I have made some generic class for reuse elsewhere.

Categories

Resources