VS2008 Update Web Reference creates naming conflicts in Reference.cs - asp.net

I have a Web service which, when updated on one computer with VS2008 works perfectly fine, but on another computer does not. The critical difference is the contents of the auto-generated Reference.cs.
In the correctly functioning environment, the methods have fully qualified class names, refering to classes in a class library. However, in the problem environment, the class names are unqualified and partial classes are declared near the end of the file. E.g.
public string MyMethod(MyClass pr_Class)
...
public partial class MyClass {
}
versus
public string MyMethod(Class.Library.Namespace.MyClass pr_Class)
This causes errors such as:
'<ClassType>' is an ambiguous reference between <ClassLibraryNamespace>.ClassType and <WebReferenceNamespace>.ClassType
The code is under source control. Checking out to the working environment works straight away, checking out to the problem environment will only work if the reference.cs is manually edited to be like the working environments. Transferring the project manually from problem environment to the working one only requires an "Update Web Reference" to be performed to allow compilation. Both Reference.cs files claim to be auto-generated by the same tool version. The settings from the good environment have been exported to the other. No success so far...
Any ideas would be greatly appreciated!
Matt

Ok, so I have the answer. The working environment has a long forgotten extension library for importing web references. Customizing generated Web Service proxies explains the procedure. I'm new to the project and so had no idea about this!

Related

References and external class use problems

Using Visual Studio 2015 on an ASP.NET project. Everything works fine except now I have a block of code (A common AD utility function) that I want all the pages to be able to access. The original language (inherited project) is VB.NET, but it should work just fine either way.
I created a class file, named it CommonADFunctions.vb. The file uses System.DirectoryServices, and there's a reference in the project to that assembly. However, there are two problems:
I can't reference the new class to call the functions from any of the page code files. This includes attempts to instantiate a new variable as the class type.
When I move the new .VB file into App_Code, the reference to System.DirectoryServices breaks, and it refuses to build.
This may seem like a trivial ask, but what am I missing?
Turns out this was a simple property on the file itself I created a new Class File, and somehow the Build Action got set to Content rather than Compile. Setting this to Compile allowed the object to be referenced and instantiated properly. It doesn't fix the IDE intelliSense from APP_Code for DirectoryServices references in the code, but it compiles and runs, which is what I needed.
EDIT: Received external help which pointed this out.
Without code and screenshots to illustrate I can only recommend a few things to try.
I can't reference the new class to call the functions from any of the page code files. This includes attempts to instantiate a new variable as the class type.
The methods in the class have Private or Friend scope.
Its a static class (a Module in VB.Net) and you do not need to instantiate it.
You are somehow referencing an old DLL which doesn't have the methods. Check the reference to this AD project and make sure its "Referenced" via Project.
When I move the new .VB file into App_Code, the reference to System.DirectoryServices breaks, and it refuses to build.
This sounds like a corrupt project file. Clean the solution, delete the .suo file, delete the obj & bin folders.
Then move the CommonADFunctions.vb to the App_Code folder and add the DLL reference to System.DirectoryServices. Or create the CommonADFunctions.vb file in App_Code to start with.

Sub New() has multiple definitions with identical signatures

I was working in ASP.Net web forms application (website not web application) on Win 7 and everything was fine.
I had to transfer my solution to another machine also win 7, once I did that everything became NOT OK.
when I build my solution I got tons of building errors in files existing in
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
most of these errors such
Protected Sub New(info As System.Runtime.Serialization.SerializationInfo, context As System.Runtime.Serialization.StreamingContext) has multiple definitions with identical signatures.
and
Public Sub New()' has multiple definitions with identical signatures.
I googled it and tried all solution stated in all sites. clearing my solution and rebuild it,
clearing Temporary ASP.NET Files folder, clearing C:\Users\user\AppData\Local\Temp and also manually deleted .NETFramework,Version=v4.0.AssemblyAttributes.cs exists in Temp folder
even I created new solution with different name but of course I imported files from old solution.
Nothing work for me, I don't know what is the problem exactly and why it happen and how can I solve it and back my solution to live?
Usually when you use Visual Studio to generate some code for you (for data or whatever) it does them as Partial Class ... so you can create another partial class and add your own code to the same class without loosing your changes when the tool regenerates it's code. Long story.
Anyway, since this is a web site, all files in the folder are part of the project. If you accidently copy the same file twice, it is automatically added and your partial class with the same methods and properties (like NEW) now have multiple definitions.
Look for copies of the same classes.

Copying/Moving App Code to New Project

Ok, I am in the process of breaking apart of intranet application (VS 2010 Web Site, ASP.NET Web Forms with VB code behind). During this process i'm trying to convert some of our our app_code files in to WCF rest service in a new project. However, when I copy or "add existing" vb files into the new "services" project. I get tons of errors including...
error BC30002: Type 'XXX' is not defined
warning BC40056: Namespace
or type specified in the Imports 'System.ServiceModel' 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.
From what i've read it may (or may not) have something to do with Assemblies and references that I just have very little knowledge on. I have added the namespaces from the current web.config to new project's web.config, and the files are identical. So there is something in the background that needs to be added to the new project I just don't know what its.
PLEASE HELP!!
THANKS
JOSH
UPDATE 1
So one of the errors i'm getting = "error BC30002: Type 'MailMessage' is not defined." Which is a namespace that is added to the web.config, which apparently isn't being picked up??? IDEAS?
I've come across a similar issue - not sure what the reasoning behind it is, but I got around it by creating a new .vb class with the same name as the one you want to copy, then copy and paste all the text from the old one to the new one. Save it, then it seems to like it - it didn't like me copying and pasting the actual file, nor did it like me adding existing files.
Hope this helps :/
This issue seems to be tied to the the differences between Web Application Projects versus Web Site Projects. Eventually I had to add different namespaces on the new project level.
Here is more info about WAP vs WSP....
http://msdn.microsoft.com/en-us/library/dd547590(v=vs.110).aspx

Subclassing Global and overriding Application_Start

I have a couple of web applications whose source code is missing. The project is compiled to a dll and is hosted on a IIS.
I have couple of questions to make.
What is the best way to recreate the
project from the dll file??
We are planning to change the
database server, and the database
connection strings are specified in
the Global.asax ( I mean the public
class Global : HttpApplication ). Is
there a way I can subclass this
Global and override the connection
strings? If yes, how can I make the
IIS refer to the new dll
Thank you all for any suggestions!!
For first part, use decompiler tools such as Reflector/ILSpy/dotPeek to convert IL code from DLL to higher level language such as C#. However, tools cannot get back comments, local variable names and project structure. You need to manually organize the code into files and project structures. From aspx files, you have to figure out the code-behind classes and then link up the source of the class into a correct named code-behind file - for example, if default.aspx says that it inherits from MyApp.Default then create file default.aspx.xs and put the source code for the class into that.
For second part, you can create a new class derived from Global and modify Global.asax to use that class - you need to put the assembly containing new class in bin folder and overwrite inherits clause in asax file to point to the type name of new class. You anyway need to inspect the code of your current Global class (using tools sighted above) to see if you can override connection strings by sub-classing.
Probably the best tool available to reverse engineer a dll into code is .NET Reflector. Unfortunately, the latest version is no longer free, but it is worth the money.
I am not sure exactly if this still applies if you can already reverse engineer your source code. However, I would recommend moving your connection strings outside of your project into web.config as a best practice. This way you can make the change in the future without changing any code.

Class will compile for Tests/Console but not in Asp.net application

I have a simple interface:
public interface IVisitorsLogController
{
List<VisitorsLog> GetVisitorsLog();
int GetUniqueSubscribersCount();
int GetVisitorsCount();
string GetVisitorsSummary();
}
the class VisitorsLogController implements this interface.
From a console application or a TestFixture - no problem - the console/test fixture compile perfectly.
However, from an Asp.Net web site (not application) in the same solution with this code in the code behind
private IVisitorsLogController ctl;
protected int GetUniqueMembersCount()
{
ctl = new VisitorsLogController();
return ctl.GetUniqueSubscribersCount();
}
the compiler throws this exception:
Error 1 'WebSiteBusinessRules.Interfaces.IVisitorsLogController'
does not contain a definition for
'GetUniqueSubscribersCount' and no
extension method
'GetUniqueSubscribersCount' accepting
a first argument of type
'WebSiteBusinessRules.Interfaces.IVisitorsLogController'
could be found (are you missing a
using directive or an assembly
reference?)
yet for this code in the same file:
protected static int GetVisitorsCount()
{
return VisitorsLogController.Instance.GetVisitorsCount(DateTime.Today);
}
the compiler compiles these lines without complaining. In fact if I add anything new to the Interface the compiler now complains when trying to compile the asp.net page.
It can't be a missing using directive or assembly reference otherwise both methods would fail.
This is driving me nuts!
Any thoughts please?
Thanks,
Jeremy
Out of interest, can you compile the following line:
ctl = VisitorsLogController.Instance;
? I'm just wondering if somehow you've got two interfaces named the same thing.
What does Intellisense prompt you with when you type ctl. and press Ctrl-Space?
It would seem the other important bit of code would be VisitorsLogController, wouldn't it? It looks like VisitorsLogController is implementing a different IVistorsLogController interface.
Right clicking and GoTo Definition should clear things up, I think.
I would start by checking the namespaces on each of the files involved and make sure that you don't have a conflict or a namespace that you are not expecting.
The solution contains the web site and three class projects (Data Layer, Service Layer and Core Services). They are added as references to the web site as Projects.
I had compiled the solution at one point for Release - published the site, and then changed the config to Debug.
Evidently what had happened was that the Release dll's in the /bin file of the website were not being overwritten by the new Debug dll's. I manually deleted all the files in the /bin directory, and lo and behold - everything compiled perfectly.
So Mark and John - you were both spot on - I effectively did have two interfaces named the same thing.
Thanks very much for your help - if you hadn't given me these pointers I would never have finally worked it out.

Resources