The namespace already contains a definition in wsdl-generated file - c#

I'm trying to integrate reporting services in an C# application, but when I'm trying to compile it I'm getting a bunch of 'already contains' errors, just like those two:
error CS0101: The namespace 'Microsoft.SqlServer.ReportingServices2005' already contains a definition for 'ListSecureMethodsCompletedEventHandler'
error CS0101: The namespace 'Microsoft.SqlServer.ReportingServices2005' already contains a definition for 'GetRenderResourceCompletedEventHandler'
They all come from ReportingServices2005.cs file, which was generated using wsdl and which I included in the project. What am I doing wrong here?
I probably should also mention that I'm using ReportingService2010.cs and ReportExecution.cs.

Well, that was easy enough. It was my first time using ReportingServices in C# and I misread the documentation. I thought both ReportingService2005 and 2010 are needed. After excluding ReportingService2005 and changing a few things everything worked.

Related

c# compilation error "missing static Main" in .net6

(beginner)
I'm trying to understand LinkedList and I have one working in .net5 but when I am trying to move it to .net6 it gives "missing static Main" error. Do I need to use the template showed in the link below or move classes to other file OR there is different work around?
At what point do I have to include old template? Is it at creating new class? Is empty template only used to create very basic code and nothing more?
I know that using template in link solves the problem but I would like to get wider understanding.
https://learn.microsoft.com/en-us/dotnet/core/tutorials/top-level-templates

Getting Context errors when creating a CRUD application

I'm trying to create a crud web app. I'm getting errors about the name space, which I can't figure out (sure it's something simple!) What does the type or namespace could not be found mean? It's only on pages related to the database. Or is there a way to link the sqlite database without a migration folder - ProjectContext file?
This class looks like it exists but in a different namespace to the one the controller is in. You will either need to provide a full refeerence to it's location:
Place1.Place2.ProjectContext
or a using statment at the top.
using Place1.Place2;
Visual studio has a shortcut to help you track down classes like this, right click on the problem class and click "Quick actions and Refactoring..." and you may be presented with an option to either insert a 'using' statement at the top or use a full reference.
Quick actions and Refactoring

C# MVC5 View not recognizing namespace

I have recently run on this problem. I have tried to add namespace to Views/web.config or on top of the view, but still occur on the problem, where View can't find the contents of namespace.
Problem
Ofcorse it is not a big problem, but it is annoying to always write the full namespace.
Maybe you should try write another using that contains your Resources path?

What using directive do I use for Server.MapPath in a separate .cs file in WebMatrix?

I am trying to use Server.MapPath() in a separate .cs file in WebMatrix.
I can get the method going fine by using HttpContext.Current.Server.MapPath("~/SomeDirectory/someFile.txt")
but do I really have to type HttpContext.Current every time?
Isn't there any using directive to shorten my typing to simply Server.MapPath like it is when coding in a .cshtml file?
I have looked here, but none of the answers worked for me. Probably because the answers therein don't target an asp.net-webpages, WebMatrix environment.
http://www.sitepoint.com/forums/showthread.php?167802-Server-MapPath-in-C-class
Server.MapPath()
Also, if there is a kind of cheat sheet to help me find C#.net using directives, considering my environment, letting me know where I can find it is definitely an acceptable answer.
You can assign the Server property to a variable to save a bit of typing:
var server = HttpContext.Current.Server;
var file = server.MapPath("~/SomeDirectory/Somefile");
To answer the question posed in the title of your post - the using directive you need in the class file is System.Web:
using System.Web;
I don't know of any "cheat sheet" as such. Experience and a growing familiarity with MSDN help, as does Resharper if you can afford it and have the full version of Visual Studio.

ASP.net c#, how do I know what to use?

I keep coming accross code samples online for ASP.net c#, however they never seem to list which namespaces they include, for example:
using System.Data.SqlClient;
etc etc
Am I missing something obvious or should I be expected to know exactly what namespaces each code example requires?
When I'm in that situation, typically I search for the class on MSDN. The documentation will tell you which namespaces contain the class.
If they don't include them, you can follow this list in order:
Find that they are in one of the namespaces listed in the "blank code file" template , or
In Visual Studio You can click the missing type and press shift+F10 or Ctrl+. To get the option to automatically add the using statement (if the assembly is referenced)
With Resharper, Select the type and hit alt+enter for Resharper to find the namespace for you, and add it to the usings (possibly even reference the assembly as well)
Go to MSDN and search the name.
Go to Google and search the name (honestly, I normally do this before hitting MSDN anyway)
Compain to the article author
If code samples use the assemblies that a project references by default, then you can hover on the class name and click shift+F10 which will add the using statement automatically. If the class is not in any of the referenced assemblies then you are out of luck and need to know in what assembly does the class resides.
A quick google search can help, and in time you will memorize the namespaces... Of course its best if samples included the namespace and reference info, but mostly they do not.
If you are viewing code in Visual studio, just hover mouse over class or object you want and you will get tool tip about it if assemly of that class is present or you can google for particular class.For example if you want to know more about 'DataTable'class, just google it and you will come to know that its part of Syste.Data namespace.
I'm with the OP on this one. Having to just magically "know" what namespaces are required seems supremely silly.
I spent some time before C# as a Java Developer, and the NetBeans IDE will resolve these for you automatically. Ctrl-Shift-I, and it will insert all the packages (ie, namespaces) you need. If more than one package defines the class you are resolving, a window pops up and lets you choose which one you want.
For as fine a product as VS is, I am incredulous that this feature is not included.

Categories