This project has moved. For the latest updates, please go here.

OID as String

Topics: feature request (I want ...), usage (how to ...)
Jul 30, 2008 at 8:10 AM
Edited Jul 30, 2008 at 8:21 AM
Hi,

Is it possible to specify the following line:
Manager.Walk(VersionCode.V1, IPAddress.Parse(DeviceIP), Community, new ObjectIdentifier(new uint[] { 1, 3, 6, 1, 2, 1, 2, 2 }), WalkList, 1000);

using the string "1.3.6.1.2.1.2.2" rather than the new uint data type? I have been looking at this for a few hours and getting any where. if so, could you give me a quick example

Thanks in advance!
Coordinator
Jul 31, 2008 at 3:28 AM
hi, you may use this function written by Andy Hau,

uint[] StringToUint(string s)
{
 string[] p = s.Split('.');
 uint[] u = new uint[p.Length];
 for (int i = 0; i < p.Length; i++)
 {
   u[i] = uint.Parse(p[i]);
 }
 return u;
}

Personally, I do not use OID strings that much, so I do not include this helper function in #SNMP.
Jul 31, 2008 at 7:59 AM
That works great, many thaks for your quick response!

FunkyGibbon
Aug 5, 2008 at 1:52 PM
Please include possibility of specifying OID as string as a constructor for ObjectIdentifier. Usually you are building OIDs starting from a  Root OID of your application to which you concatenate Variables OID, Types OID and so on.
String concatenation of OIDs is certainly more natural than working with arrays of uints.

Coordinator
Aug 6, 2008 at 4:22 AM
Hi, finally I added this function into ObjectIdentifier.cs in Change Set 14893. It is one of the Convert static methods that convert OIDs between string and array formats.

BTW, I decided to provide as little overloading functions as possible in the core library (SharpSnmpLib.dll). Maybe one day I am going to split all overloading methods into a helper library (SharpSnmpLib.Helpers.dll). I think Extension Method in C# 3.0 provides me a nice way. Stay tuned.
Marked as answer by lextm on 10/6/2013 at 9:45 PM
Aug 12, 2008 at 1:51 PM

Hi

when I carry out the following line of code

ObjectIdentifier ObjId = new ObjectIdentifier(ObjectIdentifier.Convert("1.3.6.1.4.1.9.9.68.1.2.2.1.2"));

I get the error messages

Textual 'ObjId.Textual' threw an exception of type 'System.ArgumentOutOfRangeException' string {System.ArgumentOutOfRangeException}

+  base {"Specified argument was out of the range of valid values.\r\nParameter name: index"} System.ArgumentException {System.ArgumentOutOfRangeException}

Any ideas what the problem might be?

Thanks

Coordinator
Aug 13, 2008 at 4:02 AM
If you want to get textual form of an object identifier, please make sure the MIB document containing this object identifier is already loaded in ObjectRegistry. If not, #SNMP cannot provide you the textual form but raise such an exception. (Yes, you are required to provide MIB documents in this case.)

Because I consider it as a design error other than a run-time exception, you see that I do nothing to hide this exception. :-)

-Lex
Marked as answer by lextm on 10/6/2013 at 9:45 PM