0

I have created a list in the code, then I've called GetItemById function to get an item, but this function throws me this exception:

One or more field types are not installed properly

I've created the list using Visual Studio and it gave me this error once, but I've now deleted this list altogether and created it manually in the target SharePoint site, but it still gives me that error.

Any advice?

  • what value are you passing into the GetItemById? could you show some code? – Ali Jafer Jan 17 '18 at 11:20
  • I'm passing and integer number (-1 for default) so in the first time SPListItem will be null and then I add a new item.. The weird thing about this is that I've done that for countless times. – Gamil Silvergeek Jan 17 '18 at 11:27
  • Now, I've changed the list name completely and referred to the new name in the code with this list only having the title as a field but the code still throws the same exception.. I really don't know what's going on here. – Gamil Silvergeek Jan 17 '18 at 11:36
  • Share your code here... – P S Jan 17 '18 at 11:40
0

Could you please share your code?

And per my test in my SharePoint 2013 environment, the GetItemById function can work fine to get the item from the list created by code in visual studio.

To troubleshoot the issue, you could add break point in your GetItemById function to debug your code in visual studio.

There is a demo for your reference.

public static SPListItem GetItemById(string listname, int itemId)
        {
            String siteUrl = "http://sp:5872";
            SPSite spSite = new SPSite(siteUrl);
            SPList list = spSite.RootWeb.Lists[listname];
            SPListItem item = null;
            try
            {
                // init
                if (listname == null) { throw new Exception("SPList passed is null"); }
                item = list.GetItemById(itemId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return item;
        }
0

I have figured out what was going wrong.. The problem is when I pass "-1" as a default value for GetItemById the function throws the exception that is mentioned in the question which is totally misleading.

Many thanks, though, for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.