none
SharePoint 2016 System.Reflection RRS feed

  • Question

  • Hello Everyone,

    We are migrating from SharePoint 2013 to SharePoint 2016. We have been going through all of our code and have the problem when System.Reflection is used.

    Code as below:

    if (libFolder.RequiresCheckout)
                                        {
                                            MethodInfo mi = typeof(SPFile).GetMethod("CheckIn", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(string), typeof(SPCheckinType), typeof(bool), typeof(SPUser) }, null);
                                            
                                            try
                                            {
                                                mi.Invoke(spfile, new object[] { "New Upload by " + _currentUser.Name, SPCheckinType.MajorCheckIn, false, _currentUser });
                                                int newCarId = this.AddCar(site, picUrl);
    
                                                if(newCarId >0)
                                                {
                                                    if (HttpContext.Current != null)
                                                    {
                                                        HttpContext.Current.Response.Redirect(SPUtility.ConcatUrls(siteUrl, "/department/cad/Lists/cads/EditForm.aspx?ID=" + newCarId.ToString()), false);
                                                    }
                                                }
                                            }
                                            catch (TargetInvocationException invokeEx)
                                            {
                                                Logger.LogError("Error in (): While trying to checkin the new Car Picture file following error occured. Error:=" + invokeEx.ToString(), LogCategory.Applicationpage);
                                                this.lblInfo.Text = invokeEx.Message;
                                                this.lblInfo.Visible = true;
                                                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CloseWaitDialog", "closeWaitDialog();", false);
                                            }
                                        }

    The variable mi is null but with SharePoint 2013 is not null. We have other code that uses FieldInfo too and those are also coming out as null. This has happened on SharePoint 2016 running on Server 2012 R2 and on Server 2016.

    Does anyone have an idea why?


    • Edited by iamsp16 Thursday, February 16, 2017 2:12 PM
    Thursday, February 16, 2017 2:10 PM

Answers

  • open Microsoft.SharePoint.dll (v.16 from the GAC) in some reflector (e.g. in Telerik JustDecompile), browse to SPFile class and check whether it contains private CheckIn method with specified signature (method which receives 4 parameters { typeof(string), typeof(SPCheckinType), typeof(bool), typeof(SPUser) }). It may be so that it was changed - e.g. new parameter is added. Since it is private MS may not keep compatibility with previous version.

    And BTW it is possible to check in file using public methods:

    file.CheckIn("comment");
    file.Update();
    file.Publish("comment");

    Blog - http://sadomovalex.blogspot.com
    Dynamic CAML queries via C# - http://camlex.codeplex.com

    • Marked as answer by iamsp16 Thursday, February 16, 2017 2:53 PM
    Thursday, February 16, 2017 2:40 PM

All replies

  • open Microsoft.SharePoint.dll (v.16 from the GAC) in some reflector (e.g. in Telerik JustDecompile), browse to SPFile class and check whether it contains private CheckIn method with specified signature (method which receives 4 parameters { typeof(string), typeof(SPCheckinType), typeof(bool), typeof(SPUser) }). It may be so that it was changed - e.g. new parameter is added. Since it is private MS may not keep compatibility with previous version.

    And BTW it is possible to check in file using public methods:

    file.CheckIn("comment");
    file.Update();
    file.Publish("comment");

    Blog - http://sadomovalex.blogspot.com
    Dynamic CAML queries via C# - http://camlex.codeplex.com

    • Marked as answer by iamsp16 Thursday, February 16, 2017 2:53 PM
    Thursday, February 16, 2017 2:40 PM
  • Thanks for the answer.

    This is an application so we wanted the modified field to be the current user and not the webapp user or system account. Gonna have to go deeper into SharePoint 2016.


    • Edited by iamsp16 Thursday, February 16, 2017 2:57 PM
    Thursday, February 16, 2017 2:55 PM
  • Hi Iamsp16,

    Did you finally figure out how to deal with this issue?

    I got the same in my environment.

    Friday, November 3, 2017 2:16 PM