Wednesday, 21 December 2011

Unable to cast COM object of type 'Microsoft.SharePoint.Library.SPRequestInternalClass' to interface type 'Microsoft.SharePoint.Library.ISPRequest'.

I was working with PowerShell and Sharepoint 2010 and for some reason I have got this error:

Unable to cast COM object of type 'Microsoft.SharePoint.Library.SPRequestInternalClass' to interface type 'Microsoft.SharePoint.Library.ISPRequest'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{BDEADEBE-C265-11D0-BCED-00A0C90AB50F}' failed due to the following error: Bad variable type. (Exception from HRESULT: 0x80020008 (DISP_E_BADVARTYPE)).

This is the only stuff I was doing was adding a new library to my existing site. This is the code:

 [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
 $listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary
 $spWeb = Get-SPWeb -Identity "http://sp_foundation_g/sites/Documents"
 $spWeb.Lists.Add("AllDocuments","My Doc Library",[Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary)
If you use Powershell you normally are administrator, but just in case I decided to check RunWithElevatedPrivileges in order to avoid any problem with the security. Everything was fixed straight away, and I didn’t get the error anymore, even if I tried to run the code without RunWithElevatedPrivileges. This is the code I ran to fix it:
[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges(  
 {      
     [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
     $listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary
     $spWeb = Get-SPWeb -Identity "http://sp_foundation_g/sites/Documents"
     $spWeb.Lists.Add("AllMydocuments","My Doc Library",[Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary)
 }
)  
Conclusion: I have done plenty of research but I can’t find the answer of why this is happening, but the good news, it can be fixed!.

4 comments:

Anonymous said...

Good day! Do you know if they make any plugins to assist with Search Engine Optimization?
I'm trying to get my blog to rank for some targeted keywords but I'm not seeing very good gains.
If you know of any please share. Cheers!

My homepage :: http://www.sexyhotgirlz.com/

Anonymous said...

Hi, i feel that i saw you visited my weblog so i came to return
the favor?.I am trying to in finding things to improve my site!
I guess its ok to use some of your concepts!!

Feel free to surf to my blog; www.jnmassage.info

Anonymous said...

Hello, Neat post. There is an issue with your site in internet explorer,
might test this? IE nonetheless is the market chief and a large
element of other folks will miss your excellent writing due to
this problem.

Here is my weblog - http://sexvideovoyeur.com

chenmeinv0 said...

hollister clothing
coach outlet store online
cheap rolex watches
tiffany and co jewelry
cheap ray ban sunglasses
replica rolex watches
coach outlet store online
true religion
prada handbags
discount ray ban sunglasses
2016.12.17xukaimin