XXX doesn't contain a definition and no extension method - c#-4.0

I need to access some methods and properties of a third party unmanaged DLL from my VS2010 C# project. One property in particular “disappears” when trying to access it after I added the DLL to the reference. I am using MS VS2010 and the target platform is an XP SP3 x86.
From the .NET VB, the Item property is shown as
Item([Object], [Object]) As Object
or
ReadOnly Default Property Item(Optional ByVal Name As Object = Nothing, Optional ByVal Index As Object = Nothing) As Object
I can use it with no problem.
However, in C#, this property disappears and the closest one I can find become
this[[object], [object]]
or
dynamic this[[object Name = System.Type.Missing], [object Index = System.Type.Missing]] { get; }
How do I access this property in my C# project? Thanks.

The Item property in VB.NET is the indexer in C#.
So, the following VB.NET and C# codes are equivalent:
/* VB.NET */
yourObject.Item(o1, o2)
/* C# */
yourObject[o1, o2];

this is an indexer and can be accessed like this.
var yourObj = new SomeObject();
var item = yourObj[value1,value2];
In other words you just use [] brackets after the object variable itself, rather than Item()

Related

How to select value from a dropdown using JScript (not JavaScript) with TestComplete

Currently I'm working on TestComplete automation tool. I'm facing a problem in selecting a value from a dropdown using Jscript. It can done easily in javascript by
document.getElementById("id").options[1].selected=true
I cant do it using JScript'. I've tried
Browsers.Item(btIExplorer).Run("Page URL"); //opening the browser and running a URL
browser=Aliases.browser; //creating alias of browser object
page=browser.Page("PageURL"); //creating a page object for the page opened
page.NativeWebObject.Find("id", "defaultLocationBinder_newOrExisting", "input") // This is the dropdown
I'm not able to find any suitable option to select the options in the dropdown which are given in the <option></option> tags
I just wrote this piece of code and was able to do it.
Use the selectedIndex to set the option you want.
use the object spy to check the properties/methods you can use with the object.
function loginDropDown()
{
var dropDown = Sys.Browser("iexplore").Page("*").FindChild("Name","Select(\"myList\")",10,true)
dropDown.selectedIndex = 1
}
The NativeWebObject.Find method returns a native object while you may want to work with a TestComplete wrapper. Use the Find or FindChild method to get such a wrapper and the Clickitem method to select a specific item.
function test()
{
var b = Sys.Browser("iexplore");
b.ToUrl("http://support.smartbear.com/message/?prod=TestComplete");
var page = b.Page("http://support.smartbear.com/message/?prod=TestComplete");
var cBox = page.FindChild("ObjectIdentifier", "ddlRequestType", 20);
cBox.ClickItem("General product question");
}

TestComplete Objects - Enumerate properties

For the TestComplete objects of processes, windows and controls on the screen - is there a way to enumerate and print out all the properties. I tried the following code and I get a runtime exception:-
var deskObj = Sys.Desktop; //TC Desktop Object
var normObj = {a:1, b:2, c:3}; //Normal JScript Object
for (var prop in normObj)
{
Log.Message(normObj[prop]); //1, 2, 3
}
for (var prop in deskObj) //Runtime error - Object doesn't support this action
{
Log.Message(deskObj[prop]);
}
This leads me to believe that TC Objects are not quite JScript objects - so is there a way to convert these to JScript Objects.
That's right: objects from the Sys tree (the object tree in the Object Browser) are special COM wrappers for actual application objects. They are not common JScript objects.
To get the list of properties and methods of such TestComplete objects, you can use the GetProperties and GetMethods methods of the aqObject object. You can find sample code within the corresponding help topics.

ASP.NET MVC4 List of all areas

I have an ASP.NET MVC4 application in which I am creating multiple areas, is there a way I can find out programmatically the number of areas that are present and their names.
The AreaRegistration.RegisterAllAreas(); registers each area route with the DataTokens["area"] where the value is the name of the area.
So you can get the registered area names from the RouteTable
var areaNames = RouteTable.Routes.OfType<Route>()
.Where(d => d.DataTokens != null && d.DataTokens.ContainsKey("area"))
.Select(r => r.DataTokens["area"]).ToArray();
If you are looking for the AreaRegistration themselves you can use reflection to get types which derives from AreaRegistration in your assambly.
AreaRegistration.RegisterAllAreas() cannot be used pre-initialization of the web application. However, if you want to get the areas without calling RegisterAllAreas(), e.g. in an automated test, then the following code may be helpful:
var areaNames = new List<string>();
foreach (var type in typeof(MvcApplication).Assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(AreaRegistration)))) {
var areaRegistration = Activator.CreateInstance(type) as AreaRegistration;
areaNames.Add(areaRegistration.AreaName);
}
Note that MvcApplication is the class derived from HttpApplication. You can use any class name as long as that class is in the same assembly as the assembly registrations, i.e. the classes derived from AreaRegistration. If you have split up your application with areas in more than one assembly, then you'd need to adapt this code accordingly so it searches all those assemblies.

SharePoint List Error: "Value does not fall within the expected range"

Hi I am developing using the SharePoint namespace and I ran into the following error when I try to retrieve a URL column from one of my lsits.
"Value does not fall within the expected range"
All I am doing is:
item["URL"]
Can someone tell me what I can do about this?
The error definitely means that the field can't be found.
Debug the process and look at the ListItem.Fields.SchemaXML property to find its internal name, it may be saved internally as something other than URL. You can also use the following method to get a list item value.
SPField l_field = l_item.Fields.GetField("URL");
string l_fieldValue = l_item[l_field.Id].ToString();
The GetField method looks for a field by both DisplayName & InternalName.
To get the URL of an SPListItem, use Item.Url.
public static string GetItemURLValue(SPListItem item, string fieldName)
{
string exit = "";
SPFieldUrlValue link = new SPFieldUrlValue(item[fieldName].ToString());
exit = link.Url;
return exit;
}
This usually means "URL" is not a field in the list.
If it's a promoted InfoPath column, try deactivating and re-activating the form template to the site. I have noticed that I have to do this whenever I add a new promoted field to an infopath template.
There is a special method for retrieving URLs. Try this:
SPListItem li = ...
SPFieldUrlValue fuv = new SPFieldUrlValue(li[strFieldName].ToString());
return fuv.Url;
Mine is a Windows application. I used to get this exception after I created the set up and tried deploying.
My application needed to write in Excel and then save it. I used reference of COM component 'Microsoft Excel 11.0 Object'. I noticed when I add this reference actually 3 dll's appear in my reference list.
Microsoft.office.core
Excel
VBIDE
I removed the 'VBIDE' reference and my problem is solved.
If it's just a column name and in "Single line of Text" format, what about:
item["URL"] != null ? item["URL"].ToString() : "Not Found";

C++/CLI Managed Wrapper and ADODB::Recordset

I have a native C++ DLL that uses COM ADO Recordsets and am in need of converting it to the .NET variant (ADODB::Recordset). I have tried several approaches to tackling this problem without success.
The native C++ DLL dynamically creates and populates the COM Recordset. Ideally I'd do the same for the ADODB::Recordset within the managed wrapper, but the needed properties aren't accessible to me.
For example, when attempting to utilize the Fields collection in order to Append Columns (despite intellisense telling me otherwise), I receive:
error C2039: 'Fields' : is not a member of 'ADODB::Recordset'
ADODB::Recordset ^RS = gcnew ADODB::Recordset ();
RS->Fields->Append("ID", DataTypeEnum::adInteger, 1, FieldAttributeEnum::adFldKeyColumn);
My C++/CLI solution contains the ADODB reference (c:\Program Files\Microsoft.NET\Primary Interop Assemblies\adodb.dll) version 7.0.3300.0
I am using Visual Studio 2005 with .NET Framework 2.0.50727 SP2
I would appreaciate it if someone in the StackOverflow community can direct me to a sample that dynamically populates a .NET ADO Recordset using C++/CLI.
I think that the main difference between the raw COM Recordset and the one provided by the .Net wrapper classes is just that some things get renamed. It is simply a wrapper around the underlying COM object and not a new class in its own right.
To answer your immediate example, try
RS->default->Append(...);
You could try to run ILDASM over the adodb.dll you have to see what the API on the recordset class is.
You can do the following too:
//Create instance of a recordset
ADODB::RecordsetClass^ recordset;
recordset = gcnew ADODB::RecordsetClass();
//Set some options
recordset->CursorLocation = ADODB::CursorLocationEnum::adUseClient ;
recordset->CursorType = ADODB::CursorTypeEnum::adOpenDynamic;
recordset->LockType = ADODB::LockTypeEnum::adLockBatchOptimistic;
//Add columns
recordset->default->Append("Name", ADODB::DataTypeEnum::adWChar, 50, ADODB::FieldAttributeEnum::adFldFixed, nullptr);
recordset->default->Append("Number", ADODB::DataTypeEnum::adWChar, 20, ADODB::FieldAttributeEnum::adFldFixed, nullptr);
//Build an array of field names
fields = gcnew array<Object^>(2);
fields[0] = gcnew String("Name");
fields[1] = gcnew String("Number");
//Add values
array<Object^>^ values = gcnew array<Object^>(2);
values [0] = "some name";
values [1] = 1.2;
recordset->AddNew(fields, values);
//Get a value out again
recordset->MoveFirst();
ADODB::Field^ pNum= recordset->default[1];
double num = Convert::ToDouble((pNum->default));

Resources