ReportingService2010 could not be found - c#

I have:
private readonly ReportingService2010 _rs = new ReportingService2010();
Error:
The type or namespace name 'ReportingService2010' could not be found (are you missing a using directive or an assembly reference?)
I setup a reference to the SSRS service. The reference does not give me access to ReportingService2010 as I expect. The closest thing is:
MySsrsServiceNamespace.ReportingService2010SoapClient
How am I supposed to use the ReportingService2010 class? MSDN lists this class vaguely.
Please note I tried using ReportingService2010SoapClient. This class does not match the documentation for ReportingService2010. For example, ListChildren() only accepts 4 parameters and the Url property does not exist.

Just ran into the exact same issue. ReportingService2010SoapClient class was available, but the ReportingService2010 class was not. Was driving me nuts. I had added it as a "Service References", but you have to add it as a "Web References", like so:
Delete your old Service Reference
Right click on References. The "Add Service Reference" dialog comes up.
Do not enter the WSDL URL now, instead: Click on the "Advanced" button at the bottom left.
The "Service Reference Settings" dialog comes up.
At the bottom left, click the "Add Web Reference" button.
Now enter the URL for the WSDL. (for me that was servername/ReportServer/ReportService2010.asmx)
Click the small arrow on the right, it will take its sweet time to load.
Name the web reference, I used "ReportingService2010WebReference", but ReportingService2010" probably works just as well.
Click "Add Reference"
In your code, update your using statements to "using .ReportingService2010WebReference (or whatever name you picked)
Code:
private MySol.ReportService2010WebReference.ReportingService2010 rsClient;
rsClient = new ReportingService2010();
rsClient.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
CatalogItem[] items = null;
items = rsClient.ListChildren("/", false);
foreach (var item in items)
{
tr.ErrorMessage += (item.Path + " " + item.CreatedBy);
}
Worked on the first try. Web.config file wasn't touched.

Either create a proxy class and include it in your application or add a web reference to ReportingService. The tutorial is available there:
http://technet.microsoft.com/en-us/library/ms155134.aspx
Note that if you are going for proxy class and you are using more than one endpoint (ReportExecution, ReportingService) you should generate proxy classes on different namespaces, otherwise you will get clashes.
Did you do it by web reference? If so, try using WSDL at the command line. Command line syntax:
wsdl /language:CS /n:"Microsoft.SqlServer.ReportingServices2010" http://serverName/reportserver/ReportService2010.asmx?wsdl

Do not add a Webreference
Follow the following steps and it would work just fine.
1) Make sure you have .netframework >= 4.6.1
2) Run command prompt as administrator
3) cd C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools
4) Generate class: wsdl /proxyusername:Username /proxypassword:Password -out:Reportingservice2010.cs http://Servername/Reportserver/ReportService2010.asmx?wsdl
Additional) Run wsdl /? for help Files will output in: C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools
5) Add the .cs file to your project

Change this;
private readonly ReportingService2010 _rs = new ReportingService2010()
to
private readonly ReportingService2010SoapClient _rs = new ReportingService2010SoapClient()
You are attempting to create an instance to a class that does not exists and adding the reference creates a corresponding *Client class for you to instantiate.

Related

Is it possible to add a new dependency to a .dll without changing the source code?

I have two dotnetcore2.1 projects. First project calls a method of the second project via reflection.
using System;
using System.Reflection;
namespace experiment1
{
class Program
{
static void Main(string[] args)
{
Type _type = Type.GetType("experiment2.Program");
object _object = Activator.CreateInstance(_type);
MethodInfo info = _type.GetMethod("SecondProjectsMethod");
info.Invoke(_object, new object[]{});
}
}
}
I can't give any reference to the Second Project nor changes its code. How can I make this call successfully without adding a Reference to the First Project? I tried to add records to the first project's deps-file and execute the first program like this:
dotnet exec --depsfile experiment1.deps.json experiment1.dll
It didn't work. Is it even possible to do this by changing deps-file or any other config? Or should I manipulate .dll file somehow? Which direction I should go?
You can manually load the assembly by calling:
Assembly.Load("experiment2");
It should look for the assembly in the current folder, or use the deps file to locate it. After that, you should be able to use Type.GetType just fine.
If you want to specify the full path to the assembly, use AssemblyLoadContext.Default.LoadFromAssemblyPath instead.
You can refer to this page for more information on the different ways of loading an assembly in .net core.

Get assembly name at compile time and use it in code [duplicate]

Is there a way to find out the assembly name at design-time (i.e. not using reflection or runtime APIs such as System.Reflection.Assembly.GetEntryAssembly) from within Visual Studio?
The scenario requires a tool to get the assembly name that a Visual Studio project will eventually compile into.
This is like parsing the AssemblyName property of the .csproj - I am wondering if there are any APIs that can give this information reliably.
Please do not respond back with runtime APIs that use reflection - there is no assembly file present at the time I need the assembly name - just the metadata of the assembly in the csproj file.
if you are calling the tool via a post/pre-build event, this data is very easy to access.
Just go to the "project properties->Build Events" tab, then select either "edit pre-build" or "edit post-build", depending on when you want the tool to run. This should bring up an edit window with the ever helpful "Macros >>" button. Press this and you will be given a heap of macros to use and should be pretty much everything you need.
The "API" you could use is LINQ to XML after all the .csproj file is just xml. (and you can get the location of the .csproj file if you need from the solution file which for some reason is not XML but can be easily parsed)
You can use "TargetName" available in Macros for Post-build events. It will give you the assembly name for your project.
After a quick run through MSDN I found this article which might be a good start for some further research:
Accessing Project Type Specific Project, Project Item, and Configuration Properties
I think you will need to write some regular expression that will give you the value of "AssemblyTitle" attribute in AssemblyInfo.cs file.
Something like this:
public class Assembly
{
public static string GetTitle (string fileFullName) {
var contents = File.ReadAllText (fileFullName); //may raise exception if file doesn't exist
//regex string is: AssemblyTitle\x20*\(\x20*"(?<Title>.*)"\x20*\)
//loading from settings because it is annoying to type it in editor
var reg = new Regex (Settings.Default.Expression);
var match = reg.Match (contents);
var titleGroup = match.Groups["Title"];
return (match.Success && titleGroup.Success) ? titleGroup.Value : String.Empty;
}
}

The name 'zipfile' does not exist in the current context

I have an SSIS project that I can run as is, but when I try to edit it, I get an error:
The name 'zipfile' does not exist in the current context
Without editing, it works fine.
The code that's producing the error:
public void Main()
{
// TODO: Add your code here
string moduleName = Dts.Variables["User::ModuleName"].Value.ToString();
string s = Dts.Variables["User::ZipFileLocation"].Value.ToString().TrimEnd('\\') + "\\" + moduleName + "\\" + moduleName + "_" + DateTime.Now.ToString("ddMMyyyy");
// TODO: Add your code here
string startPath = s;
string zipPath = s + ".zip";
try
{
File.Delete(zipPath);
ZipFile.CreateFromDirectory(startPath, zipPath);
}
catch (Exception e)
{
}
Dts.TaskResult = (int)ScriptResults.Success;
}
How can I solve this?
Make sure you are using .NET version 4.5. Reference the Compression DLL - here is the path:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.IO.Compression.FileSystem.dll
Reference it in the class by adding using System.IO.Compression.FileSystem. If the class is inherited from another class, make sure to reference it in the parent class too. (This is what I have to do to make it compile)
To use the ZipFile class, you must add a reference to the System.IO.Compression.FileSystem assembly in your project; otherwise, you'll get the following error message when trying to compile:
The name 'ZipFile' does not exist in the current context.
For more information on how to add a reference to your project in Visual Studio, see How to: Add or remove references by using the Reference Manager.
I found that the ZipFile class would not cooperate only using System.IO.Compression, it asked to see a Reference to System.IO.Compression.FileSystem.
If you're using Visual Basic, adding a reference is fairly easy. In the solution explorer, one of the tabs under the project is called References. Right click there and select Add Reference. Scroll down a bit an check the checkbox next to System.IO.Compression.FileSystem. Once you click OK, you shouldn't even need to explicitly reference System.IO.Compression.FileSystem in your code!
Good luck (:
Just for Update: -
With .Net 4.6.1 version
Adding reference to System.IO.Compression.FileSystem and using System.IO.Compression is enough.
using System.IO.Compression.FileSystem is giving below error.

Is there a way to select a project using ENVDTE?

I want to add a Service reference to a project using ENVDTE. The only way is by the following command which pops up the Add service Reference window:
_applicationObject.ExecuteCommand("Project.AddServiceReference", string.Empty);
But this command will work only on currently selected project. Is there a way to select a particular project where the service reference is to be added?
DTE2.SelectedProjects has no way to select a project, it only helps to retrieve selected projects.
You have to navigate through the solution tree like this :
var se = _applicationObject.ToolWindows.SolutionExplorer;
var proj = se.GetItem("PathToYourProject");
proj.Select(vsUISelectionType.vsUISelectionTypeSelect);
After you launch your command.
PathToYourProject is a "pseudo" XPath. If you're workging in a project called "Project" in a solution called "Solution" your path will be : "Solution\Project"
Take care if your project is in a solution folder. It's a little bit more tricky. You have to expand solution folder like this :
var solutionFolder = se.GetItem("PathToYourSolutionFolder");
if (!solutionFolder .UIHierarchyItems.Expanded)
{
solutionFolder .UIHierarchyItems.Expanded = true;
}
Then you retrieve and select your project by this way :
var proj = solutionFolder .UIHierarchyItems.Item("ProjectName");
proj.Select(vsUISelectionType.vsUISelectionTypeSelect);
Finally, I'm not sure, but you may have to select the "Service References" node of your project before to launch the command.

Many error - what are they and how to solve?

I got many exceptions like:
Error 95 The type or namespace name 'Web' does not exist in the namespace 'MyProj.System' (are you missing an assembly reference?) C:\Projects\Solution\MyProj\Web References\GeneralServices\Reference.cs 269 24 MyProj
Error 108 The type or namespace name 'Uri' does not exist in the namespace 'MyProj
.System' (are you missing an assembly reference?) C:\Projects\Solution\MyProj\Web References\GeneralServices\Reference.cs 322 43 MyProj
The only thing I sis was adding WCF service (I already have web services in the same project). How can I solve those errors??
Where did they came from??
For some reason I don't know people closed this questions because they think it is fake question. So this is not a fake question and if they need more information - they can be specific and ask and I'll provide it. I know it looks like very generic question - but I really don't know what info to add.
It is nor a refernces problem for sure. It happend after I add wcf service and the all errors accurs in Reference.cs file that generated after I added an external web service.
*EDIT*
Here is the code of the WCF service I added. I am not sure that it is the problem:
using System.Collections.Generic;
using System.Linq;
using MyProj.Domain.Business.Entities.System.Calls;
using MyProj.Domain.Business.EntitiesRepository.System.Calls;
using StructureMap;
namespace MyProj.System.WcfServices
{
public class SystemService : MyProjService, ISystemService
{
#region Calls
public Reason[] GetCallReasons()
{
IReasonRepository rep =
ObjectFactory.GetInstance<IReasonRepository>();
return rep.GetReasonsList().ToArray();
}
public Call InsertCall(long reasonId, string phoneNumber, string description)
{
ICallRepository rep =
ObjectFactory.GetInstance<ICallRepository>();
return rep.Insert(User.UserCompany.CompanyId, reasonId, phoneNumber, description);
}
public void UpdateCall(long callId, long reasonId, string phoneNumber, string description)
{
ICallRepository rep =
ObjectFactory.GetInstance<ICallRepository>();
rep.Update(User.UserCompany.CompanyId, callId, reasonId, phoneNumber,
description);
}
public void CloseCall(long callId)
{
ICallRepository rep =
ObjectFactory.GetInstance<ICallRepository>();
rep.CloseCall(User.UserCompany.CompanyId, callId);
}
public IList<CallsListItem> GetCallsList(bool? isClosed)
{
ICallRepository rep =
ObjectFactory.GetInstance<ICallRepository>();
return rep.GetCallsList(User.UserCompany.CompanyId, isClosed);
}
public Call GetCall(long callId)
{
ICallRepository rep =
ObjectFactory.GetInstance<ICallRepository>();
return rep.GetCall(User.UserCompany.CompanyId, callId);
}
#endregion
}
}
*Another EDIT*
I remember that I also installed ef4.1 from Here.
Maybe It make something??..
*Another Another EDIT*
I think I figure it out! but I still don't know how to fix this..
The file that creates the errors has using System, using System.Web and so on. The Im My project I have also System Folder and the WCF service is in MyProj/System/WcfServices/SystemService.svc. So, it creates a cs file with namespace MyProj.System.WcfServices.
This namespace confused with System namespace! Because the file that creates the errors is generated by the system (it is the References.cs file that created for web reference) I can't edit the file. How can I solve it?..
One solution would be to stop naming folders "System"!
Another solution would be to qualify the system namespaces:
using global::System;
using global::System.Web.UI;
etc.
These mean that you're missing an assembly reference. E.g. you are referencing a type in your code for which you have not added a reference to your project. It sounds like you need to add a reference to System.Web by right clicking on your project and choosing "Add Reference".
If that doesn't work then make sure your project is targeting the full .NET framework instead of the "Client Profile" - do this by right clicking on your project and choosing "Properties" and then set the "Target Framework" on the "Application" tab.
Even if it looks like the references are correctly added, perhaps there is a .NET version mismatch? .NET 4 Client doesn't support all WCF features, so that could be the problem. Sometimes intellisense and the complier don't quite see eye-to-eye, so it might look like everything is OK but then it fails to build.
You can check which version you're project is set to by right clicking on the project -> "Properties". Go to the "Application" tab, and check under "Target framework."

Categories