SPWeb.GetListItem COMException on first call - second is ok - sharepoint-2010

I'm trying to use SPWeb.GetListItem() to get an item by a known URL (MSDN).
So basically I'm doing the following:
using (SPSite spSite = SPContext.Current.Site)
{
using (SPWeb spWeb = spSite.RootWeb)
{
SPListItem spListItem = spWeb.GetListItem
("/sites/testSite/Lists/testList/Folder/Subfolder");
}
}
in case you are wondering, I'm trying to get the folder "Subfolder" to do stuff with it.
The problem is that the first time I call this, I get a COMExpeption:
Cannot complete this action.
Please try
again.<nativehr>0x80004005</nativehr><nativestack></nativestack>
Description: An unhandled exception
occurred during the execution of the
current web request. Please review the
stack trace for more information about
the error and where it originated in
the code.
Exception Details:
System.Runtime.InteropServices.COMException:
Cannot complete this action.
There are some reports about the COMException happening because you need to use the full relative site URL, so instead of /Lists/testList/Folder/SubFolder, you need to use /sites/testSite/Lists/... - I'm doing just that. I also tried using the absolute URL (http://sharepoint/sites/...). The problem remains: I get the COMException when trying to get the spListItem for the first time.
When I try to run the code again after the Exception, the SPListItem is received just fine. Also all subsequent calls work - only the first one fails.
AmI doing some initializing wrong or something like that?

Perhaps try SPWeb.GetFolder() instead... but again it depends on what exactly you want to do with the Folder. Seems strange though that you're using a method used for getting list items on a Folder.
http://msdn.microsoft.com/en-us/library/ms461547.aspx

Try to instantiate the web where the list item is located - _uiserWeb.
I tryed Site.RootWeb.GetListItem(item_url) - it gave me null first time after code redeployment and was fine second time.
_item = _userWeb.GetListItem(item_url)

Related

Magento SOAP API: Error in retrieving catalogCategoryTree

Currently I'm using Magento 1.9.01 and PHP 5.3.28. In ASP .NET I'm trying to retrieve the catalog tree by using the SOAP API using the following code:
var magentoService = new MagentoService.Mage_Api_Model_Server_Wsi_HandlerPortTypeClient();
var sessionId = magentoService.login(userName, apiKey);
var categoryTree = magentoService.catalogCategoryTree(sessionId, "", "");
The errror I get is "Internal Error. Please see log for details."
And in the logs I can see the following:
Argument 1 passed to Mage_Catalog_Model_Category_Api::_nodeToArray() must be an instance of Varien_Data_Tree_Node, null given
From what I've read it can be a bug with PHP 5.4 or greater, but not the version I'm using... So if someone has any idea how to solve this, it will be greatly appreaciated.
Seems pretty straight forward, though the error thrown suggests a much bigger problem. First make sure that the variables are exactly as you specified in your Magento installation (pay attention to caps). Second you can't pass empty strings, instead try "Null".
Good luck

Underlying provided failed to open ? mvc4 , wcf

This code section i am getting error any ideas ?
public IEnumerable<LOBinfo> getLobinfo()
{
// var obj = from n in lobj.LOBinfoes select n;
return lobj.LOBinfoes.Select(m=>m).ToList();
// return obj.ToList();
}
I am not even using USING keyword ?
This issue been for a while and i referred many articles in stackoverflow itself but things looking bad for me .
Thank you for your suggestions
Underlying provider failed to open means, that at some point a database could not be reached, due to wrong connection settings for example or a previous failure etc...
The code you show here is allright, except for the fact you write a useless .Select you can drop the .Select(m=>m) and just leave the .ToList there.
Further, to find out what is causing your crash post the exact error message as well as the inner exception. (and the inner exception's inner exception and so on...)
Next to that the part "lobj.LOBinfoes" is probably a repository or something? You might as well post the code of that and the code of your data access object as well.

Sharepoint Timer Job debuggging unable to set the Breakpoint

I have a little problem. I'm trying to add a timer job following this tutorial : http://dotnetfinder.wordpress.com/2010/07/24/creatingcustomsharepointtimerjob2010/
I came to the point where my timer job is enabled and is launching every five minutes.
The problem is that it doesn't execute all the Execute method.
public override void Execute(Guid contentDbId)
{
// get a reference to the current site collection's content database
SPWebApplication webApplication = this.Parent as SPWebApplication;
SPContentDatabase contentDb = webApplication.ContentDatabases[contentDbId];
// get a reference to the "ListTimerJob" list in the RootWeb of the first site collection in the content database
SPList Listjob = contentDb.Sites[0].RootWeb.Lists["Liens"];
// create a new list Item, set the Title to the current day/time, and update the item
SPListItem newList = Listjob.Items.Add();
//newList["URL"] = "http://"+DateTime.Now.ToString()+".fr";
//newList.Update();
}
I attached the debugger to the OWSTIMER.EXE.
If i try to add a breakpoint at the line : SPList ListJob = ..., it's ok,
But if i try to add a new breakpoint at the next line (SPListItem newList = ...) then i have the following message :
"The following breakpoint cannot be set : ...
The CLR was unable to set the breakpoint".
Does anyone has any idea how i can make it work ?
You seem to be attaching to the correct service. See How to: Debug a Timer Job to double check your steps.
Also, as pointed out in this comment, you should restart the timer service when deploying a timer job:
mark
February 11, 2011 at 4:41 am
There is a very important step that
needs to be completed with any Timer Project. You hav to recycle the
SharPoint timer service in between deployments. Best way to do this is
to add
net stop SPTimerV4 – Pre Build
net start SPTimerV4 – Post Build
to your sharepoint project. If you do not do the above – you will be
puzzled as to why your code seems not to be up to date. The reason is
that the timer service Caches the assembly with your class. This can
cost you hours of troubleshooting, in trying to identify why your code
does not deploy.
Make sure your project configuration is in Debug mode (in Release mode compiler is setting is enabled for optimized code). Refer to this blog post

Ninject: More than one matching bindings are available

I have a dependency with parameters constructor. When I call the action more than 1x, it show this error:
Error activating IValidationPurchaseService
More than one matching bindings are available.
Activation path:
1) Request for IValidationPurchaseService
Suggestions:
1) Ensure that you have defined a binding for IValidationPurchaseService only once.
public ActionResult Detalhes(string regionUrl, string discountUrl, DetalhesModel detalhesModel)
{
var validationPurchaseDTO = new ValidationPurchaseDTO {...}
KernelFactory.Kernel.Bind<IValidationPurchaseService>().To<ValidationPurchaseService>()
.WithConstructorArgument("validationPurchaseDTO", validationPurchaseDTO)
.WithConstructorArgument("confirmPayment", true);
this.ValidationPurchaseService = KernelFactory.Kernel.Get<IValidationPurchaseService>();
...
}
I'm not sure what are you trying to achieve by the code you cited. The error is raised because you bind the same service more than once, so when you are trying to resolve it it can't choose one (identical) binding over another. This is not how DI Container is supposed to be operated. In your example you are not getting advantage of your DI at all. You can replace your code:
KernelFactory.Kernel.Bind<IValidationPurchaseService>().To<ValidationPurchaseService>()
.WithConstructorArgument("validationPurchaseDTO", validationPurchaseDTO)
.WithConstructorArgument("confirmPayment", true);
this.ValidationPurchaseService = KernelFactory.Kernel.Get<IValidationPurchaseService>();
With this:
this.ValidationPurchaseService = new ValidationPurchaseService(validationPurchaseDTO:validationPurchaseDTO, confirmPayment:true)
If you could explain what you are trying to achieve by using ninject in this scenario the community will be able to assist further.
Your KernelFactory probably returns the same kernel (singleton) on each successive call to the controller. Which is why you add a similar binding every time you hit the URL that activates this controller. So it probably works the first time and starts failing after the second time.

selenium.captureEntirePageScreenshot does not work but selenium.captureScreenshot works

I'm running Selenium with TestNG using Eclipse and Selenium RC. I used the command:
selenium.captureEntirePageScreenshot("\\test.png","");
but got the following error:
com.thoughtworks.selenium.SeleniumException: ERROR: Command execution failure. Please search the forum at http://clearspace.openqa.org for error details from the log window. The error message is: Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsILocalFile.initWithPath]
Can someone please suggest why this error is occuring? I have already tried the following:
1)Replaced "" (String kwargs parameter) with "background=#CCFFDD"
2)Running in Firefox in chrome mode
3)Changed the path to the following values and I'm still getting the error:
"\test.jpg",
"c:\test.jpg",
"c:\test.png",
"c:\folder1\test.png", (folder1 exists)
"c:\folder1\test.jpg",
4)Tried with - selenium.captureScreenshot("\test.png"); and it works fine but it does not solve my purpose and I dont want to use awt.
Can someone please suggest what could be wrong?
Thanks,
Mugen
Better yet...
I ran into a similar issue, where I only had access to a relative path instead of an absolute one. Here is the solution I came up with:
public void saveScreenshot(String methodName) {
if (methodName == null) {
methodName = String.valueOf(System.currentTimeMillis());
}
File f = new File("reports" + File.separator + methodName + ".jpg");
selenium.captureEntirePageScreenshot(f.getAbsolutePath(), "");
}
Which will put a screen shot of the entire page into the reports directory that is relative to the project. I am using the method name as the file name, or the current time if null is sent to the method.
Try this:
String path = System.getProperty("user.dir");
selenium.captureEntirePageScreenshot(path + "\\test.png", "");
To whomsoever it may concern,. the problem was solved after I kept fiddling with the code for a while and restarted my system. I came to know that captureEntirePageScreenshot works only on absolute paths so I made sure I kept trying with just that.
I got it working after looking at this page.
http://ashishbhatt.wordpress.com/2010/02/03/using-captureentirepagescreenshot-with-selenium/