Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have the following code. In the comments for methods Identified by 'A' and 'B' you will see that I identified the methods calling for the reference and the one that does not. I would like to know why the ide is barking when I highlight the method that I need an object reference; however the other method is not. I have other classes and they are not. If I can word this title better or the question better - I am open to fixing that too..

</<pre lang="c#">
namespace API.Core.Da
{
	
	[ServiceContract]
	public interface IServers
	{
	 Opc.Server[] GetRemoteServers(string host);
        }


	[DataContract]
	public class Servers : MarshalByRefObject, IServers
	{


	// A
	// This method the IDE tooltip says that an object reference is required for the non static field, method, property GetRemoteServers 
	[OperationContract]
	public Opc.Server[] GetRemoteServers(string host)
	{
	  IDiscovery discovery = new OpcCom.ServerEnumerator();
 	  //Get all OPC DA servers of version 2.0 of machine "MyMachine"
 	  Opc.Server[] hostservers = discovery.GetAvailableServers(Specification.COM_DA_20, host, null);
	  return hostservers;
	}



		// A
		// This method the IDE tooltip says that an object reference is required for the non static field, method, property CreateServer 
		[OperationContract]
		public Opc.Da.Server CreateServer(Opc.URL url, System.Net.NetworkCredential credentials)
		{

			Opc.Da.Server client = null ;
			OpcCom.Factory fact = new OpcCom.Factory();
			client = new Opc.Da.Server(fact, url );
			return client;
			
		}

		// B
		// This method the IDE tooltip does not say it requires any object reference it just shows the tooltip that a good method should.
		[OperationContract]
		public Opc.Da.Server CreateServer(string OpcUrl, OpcCom.Factory factory, System.Net.NetworkCredential Credential)
		{
	 
			Opc.URL Url = new Opc.URL(OpcUrl);
			Opc.Da.Server client = new Opc.Da.Server(factory, null );
			client.Connect(Url, new Opc.ConnectData(Credential));
			return client;
			
		}


	}

}
Posted
Updated 2-Jul-15 11:49am
v2
Comments
Sergey Alexandrovich Kryukov 2-Jul-15 17:11pm    
First of all, what is unclear in this error message? If you have an instance member, you certainly need an instance reference (object reference) to use it, how else?
Secondly, what does it mean "this one says" and "this one does not say". What "this"? Your comment does not say anything, the compiler does; it points at the place in code. What place?
—SA
stixoffire 2-Jul-15 17:47pm    
When I hilite the method: CreateServer(Opc.URL url, System.Net.NetworkCredential credentials) the popup tooltip from the IDE declares and object reference is needed for MY method CreateServer. it is not static this I know, the class it is in is not static either because I want other classes that use it to instantiate an instance before they can use it. The other method ['B'] public Opc.Da.Server CreateServer(string OpcUrl, OpcCom.Factory factory, System.Net.NetworkCredential Credential)
does not give me this tooltip error. I do not have a clue why one behaves as it does and the other not ?
Sergey Alexandrovich Kryukov 2-Jul-15 17:51pm    
I don't rely on "tooltip errors", never even saw them. Is it Visual Studio? Did you simply try to compile it? What the compiler says?
—SA
stixoffire 2-Jul-15 20:56pm    
I get a null reference exception . My constructor which I did not include in the sample is just a simple empty constructor. So I am sitting at a loss as to why it is null reference except these tooltips in the IDE , I use a Method also that call GetLocalServers which is similar to GetRemoteServers.. My debug seems to jump right past my class method and into a null reference exception. The code compiles with no errors, the app runs to this point and bam .. right now I am using Sharp Develop as Vusual Studio is too expensive for me and the Community Edition limits the things I can do.
Sergey Alexandrovich Kryukov 2-Jul-15 22:05pm    
Wait a second... It means that your project builds successfully. It dismisses those "tooltip errors". As to the null reference exception, this is the simplest problem to locate and fix. Just use the debugger.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900