Delphi CrossTalk和C#公共静态类

我正在尝试将Delphi和CrossTalk与C#类库结合使用。

我收到如下错误消息:

System.NullReferenceException:对象引用未设置为对象的实例。

我似乎无法解决这个问题..

请注意“动态”类定义和实例化的公共静态类型。

Code in class class RESTAdapterConfig is for reading a section of content out of a .config file.

我可以将类与“所有C#”应用程序一起使用。 我遇到问题的课程如下:

using System;
using System.Configuration;
using System.Linq;

namespace HHHHHH.Adapters
{
    public class RESTAdapterConfig : ConfigurationSection
    {
        public static RESTAdapterConfig Instance { get; private set; }
        private static object instanceLock = new object();

        static RESTAdapterConfig()
        {
            if (Instance == null)
                lock (instanceLock)
                    if (Instance == null)
                        Instance = (RESTAdapterConfig)ConfigurationManager.GetSection("RESTAdapterConfig");
        }

        [ConfigurationCollection(typeof(HttpHeaders), AddItemName = "httpHeader")]
        public class HttpHeaders : ConfigurationElementCollection
        {
            protected override ConfigurationElement CreateNewElement()
            {
                return new HttpHeader();
            }

            protected override object GetElementKey(ConfigurationElement element)
            {
                if (element == null)
                    throw new ArgumentNullException("httpHeader");

                return ((HttpHeader)element).Key;
            }

            public new HttpHeader this[string key]
            {
                get { return (HttpHeader)base.BaseGet(key); }
            }
        }

还包括一个RestAdapter.cs类

private static dynamic Submit(RESTRequest request, AuthType authType, object requestBody)
{
    HttpWebRequest webRequest = GetWebRequest(request, authType);
{etc}

private static HttpWebRequest GetWebRequest(RESTRequest request, AuthType authType)
{
    var uri = new Uri(GetServiceUrl(request));
{etc}

private static string GetServiceUrl(RESTRequest request)
{
    var baseURL = RESTAdapterConfig.Instance.baseURL.URL;

Delphi代码如下:

var
    ARESTAdapter: RESTAdapter;
    GenerateHRF605StatusRequest: RESTRequest;
    //ARESTAdapterConfig : RESTAdapterConfig;
    HRF605Req: HRF605Request;
    PartialURL: string;
begin

    // Call Web service

    try
        ARESTAdapter := RESTAdapter.Create;
        try
            PartialURL := 'generateHRF605';
            GenerateHRF605StatusRequest := RESTRequest.Create;
            GenerateHRF605StatusRequest.PartyCode := DataModule.AJF2GetPartyId;
            GenerateHRF605StatusRequest.Method := 'POST';
            GenerateHRF605StatusRequest.ApiVersion := 1;
            GenerateHRF605StatusRequest.Path := PartialURL;
            HRF605Req := HRF605Request.Create(
                            FormatDateTime('yyyy-MM-dd', rsRangeSelector.DateFrom) ,
                            FormatDateTime('yyyy-MM-dd', rsRangeSelector.DateTo) ,
                                                        0,
                            '\\FILESERVER01\H2FileRepository\Dev\CommonDev\reports\');
            //HRF605Req := HRF605Request.Create;
            //HRF605Req.FromDate := FormatDateTime('yyyy-MM-dd', rsRangeSelector.DateFrom) ;
            //HRF605Req.ToDate := FormatDateTime('yyyy-MM-dd', rsRangeSelector.DateTo);
            //HRF605Req.MembershipId := 100;
            //HRF605Req.MembershipId := 100;
            //HRF605Req.FolderPath := null;
            //ShowMessage('Debug:  FromDate: ' +  HRF605Req.FromDate + ' ToDate: ' +  HRF605Req.ToDate + ' PartyID : ' + GenerateHRF605StatusRequest.PartyCode) ;

            try
                ARESTAdapter.HRF605RequestHelloWorld();
                //have tried both
                //ARESTAdapter.SubmitHRF605Request(GenerateHRF605StatusRequest,HRF605Req);
                ARESTAdapter.SubmitHRF605Request(GenerateHRF605StatusRequest,HRF605Req);

            finally
                HRF605Req.Free;
                GenerateHRF605StatusRequest.Free;
            end;
        finally
            ARESTAdapter.Free;
        end;
    except on E: Exception do
        raise EhslException.Create(StringReplace(E.Message, 'RESTException: ', '', [rfIgnoreCase]));
    end;
评论