Error: System.UriFormatException: Invalid URI: The URI is empty.

Unanswered Error: System.UriFormatException: Invalid URI: The URI is empty.

  • Friday, December 16, 2011 7:53 AM
     
     

    Hi 

    I am able to load the assmeblies in SQL Server. However, when I execute my SQL Server function that loads the assmebly, I get this error below. 

     

    Please do note that we have a  DLL "nsoftware.inpay" and our wrapper DLL works perfectly as a .NET application but only when it is loaded into SQL Server as an assembly it gives me this error,  I am making a reference to nsoftware.inpay dll, and when I take out the line of code that instatiated a new instance of  nsoftware.inpay.icharge, it works fine. 

     

    Please help as this is very urgent!

     

     

    Error:

    System.UriFormatException: Invalid URI: The URI is empty.     at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)     at System.Uri..ctor(String uriString)     at System.ComponentModel.Design.RuntimeLicenseContext.GetLocalPath(String fileName)     at System.ComponentModel.Design.RuntimeLicenseContext.GetSavedLicenseKey(Type type, Assembly resourceAssembly)     at nsoftware.InPay.IchargeExtraValues.GetLicense(LicenseContext context, Type type, Object instance, Boolean allowExceptions)     at System.ComponentModel.LicenseManager.ValidateInternalRecursive(LicenseContext context, Type type, Object instance, Boolean allowExceptions, License& license, String& licenseKey)     at System.ComponentModel.LicenseManager.ValidateInternal(Type type, Object instance, Boolean allowExceptions, License& license)     at System.ComponentModel.LicenseManager.Validate(Type type, Object instance)     at nsoftware.InPay.Icharge..ctor(IContainer container, String rtk)     at nsoftware.InPay.Icharge..ctor()     at ePayment_CC_Assembly.EPI_CC..ctor()     at ePayment_CC_Assembly.EPI_Payment_CC_Assembly.SubmitCCPayment(Object obj, Int32& Paymentresult, String& ConfirmationNo, String& FailureMessage, String& InternalErrMsg)

All Replies

  • Friday, December 16, 2011 8:33 AM
    Moderator
     
     
    I'm not sure from your description what you are doing inside the SQL function that causes the error. If you are trying to load an external assembly (i.e. one that's not already cataloged to SQL Server with CREATE ASSEMBLY) into SQL Server in your SQL function code, this will work in a .NET program but will not work in a SQLCLR function. SQL Server only allows loading of assemblies that already exist in the database's catalog, not from outside, for security reasons. If this is not what you're doing, you need to provide more information, for example the code that fails. Cheers, Bob
  • Friday, December 16, 2011 11:48 AM
     
     
    Hii
    this is my wrapper dll class libraray code:
    <SqlFunction(FillRowMethodName:="SubmitCCPayment", systemdataaccess:=SystemDataAccessKind.Read, DataAccess:=DataAccessKind.Read)> _
        Public Shared Function ProcessCCPayment(ByVal SQLClientConnectionString As String, ByVal PaymentProcessor As Integer, ByVal AccountNo As Integer, ByVal SubAccountNumber As String, ByVal Amount As Double, _
            ByVal CCNo As String, ByVal ExpMonth As String, ByVal ExpYr As String, _
            ByVal CSCode As String, ByVal Address1 As String, ByVal City As String, ByVal State As String, ByVal ZipCode As String, ByVal InterfaceOpt As Integer, _
            ByVal ClientIPAddress As String, ByVal IsAutoPay As String, _
            ByVal InvoiceNo As String, ByVal RunSequence As String, ByVal TransactionType As Integer, _
            ByVal CCHardHolderName As String, Optional ByVal COMMENT1 As String = "", Optional ByVal COMMENT2 As String = "", _
            Optional ByVal INsertToPayment As Boolean = True, Optional ByVal IsDeposit As Boolean = False, Optional ByVal TransId As String = "") As IEnumerable
            Dim Paymentdt As New DataTable
            Paymentdt.Columns.Add("ConnectionString", GetType(String))
            Paymentdt.Columns.Add("PaymentProcessor", GetType(Integer))
            Paymentdt.Columns.Add("AccountNo", GetType(Long))
            Paymentdt.Columns.Add("SubAccountNumber", GetType(String))
            Paymentdt.Columns.Add("Amount", GetType(Double))
            Paymentdt.Columns.Add("CCNo", GetType(String))
            Paymentdt.Columns.Add("CCHolderName", GetType(String))
            Paymentdt.Columns.Add("ExpMonth", GetType(String))
            Paymentdt.Columns.Add("ExpYr", GetType(String))
            Paymentdt.Columns.Add("CSCode", GetType(String))
            Paymentdt.Columns.Add("Address1", GetType(String))
            Paymentdt.Columns.Add("City", GetType(String))
            Paymentdt.Columns.Add("State", GetType(String))
            Paymentdt.Columns.Add("ZipCode", GetType(String))
            Paymentdt.Columns.Add("InterfaceOpt", GetType(Integer))
            Paymentdt.Columns.Add("ClientIPAddress", GetType(String))
            Paymentdt.Columns.Add("IsAutoPay", GetType(Integer))
            Paymentdt.Columns.Add("InvoiceNo", GetType(String))
            Paymentdt.Columns.Add("RunSequence", GetType(String))
            Paymentdt.Columns.Add("TransactionType", GetType(Integer))
            Paymentdt.Columns.Add("COMMENT1", GetType(String))
            Paymentdt.Columns.Add("COMMENT2", GetType(String))
            Paymentdt.Columns.Add("INsertToPayment", GetType(Boolean))
            Paymentdt.Columns.Add("IsDeposit", GetType(Boolean))
            Paymentdt.Columns.Add("TransId", GetType(String))
            Dim dr As DataRow = Paymentdt.NewRow
            dr("ConnectionString") = SQLClientConnectionString
            dr("PaymentProcessor") = PaymentProcessor
            dr("AccountNo") = AccountNo
            dr("SubAccountNumber") = SubAccountNumber
            dr("Amount") = Amount
            dr("CCNo") = CCNo
            dr("CCHolderName") = CCHardHolderName
            dr("ExpMonth") = ExpMonth
            dr("ExpYr") = ExpYr
            dr("CSCode") = CSCode
            dr("Address1") = Address1
            dr("City") = City
            dr("State") = State
            dr("ZipCode") = ZipCode
            dr("InterfaceOpt") = InterfaceOpt
            dr("ClientIPAddress") = ClientIPAddress
            dr("IsAutoPay") = IsAutoPay
            dr("InvoiceNo") = InvoiceNo
            dr("RunSequence") = RunSequence
            dr("TransactionType") = TransactionType
            dr("COMMENT1") = COMMENT1
            dr("COMMENT2") = COMMENT2
            dr("INsertToPayment") = INsertToPayment
            dr("IsDeposit") = IsDeposit
            dr("TransId") = TransId
            Paymentdt.Rows.Add(dr)
            Return Paymentdt.Rows
        End Function
        <Microsoft.SqlServer.Server.SqlFunction(systemdataaccess:=SystemDataAccessKind.Read, DataAccess:=Microsoft.SqlServer.Server.DataAccessKind.Read)> _
        Public Shared Sub SubmitCCPayment(ByVal obj As Object, <Out()> ByRef Paymentresult As Integer, <Out()> ByRef ConfirmationNo As String, <Out()> ByRef FailureMessage As String, <Out()> ByRef InternalErrMsg As String)
            'Public Shared Sub SubmitCCPayment(ByVal obj As DataRow, <Out()> ByRef Paymentresult As Integer, <Out()> ByRef ConfirmationNo As String, <Out()> ByRef FailureMessage As String, <Out()> ByRef InternalErrMsg As String)
            Try
                Dim PaymentProcessor As Integer
                Dim Amount As Double
                'Dim sqlcon As SqlConnection = Nothing
                Dim COnnectionString As String = ""
                Dim TransactionType As Integer
                Dim Paydr As DataRow = DirectCast(obj, DataRow)
                'PaymentProcessor = obj.gatewayid
                'Amount = obj.TransactionAmount
                'COnnectionString = obj.connectionstring
                'TransactionType = obj.transtype
                PaymentProcessor = eutils.Nz(Paydr("PaymentProcessor"), 0)
                Amount = eutils.Nz(Paydr("Amount"), 0)
                COnnectionString = eutils.Nz(Paydr("ConnectionString"), "")
                TransactionType = eutils.Nz(Paydr("TransactionType"), 0)
                If PaymentProcessor = 0 Then
                    Paymentresult = 2
                    ConfirmationNo = 0
                    FailureMessage = "Invalid payment processor."
                    InternalErrMsg = ""
                    'resultdr = PopulateRsltRow(resultDt, Paymentresult, ConfirmationNo, FailureMessage, InternalErrMsg)
                    'resultDt.Rows.Add(resultdr)
                    'Return resultDt.Rows'
                    Exit Try
                End If
                If TransactionType = 0 Then
                    Paymentresult = 2
                    ConfirmationNo = 0
                    FailureMessage = "Invalid transaction method."
                    InternalErrMsg = ""
                    Exit Try
                End If
                'If Amount <= 0 Then
                '    Paymentresult = 2
                '    ConfirmationNo = 0
                '    FailureMessage = "Invalid payment amount."
                '    InternalErrMsg = ""
                '    'resultdr = PopulateRsltRow(resultDt, Paymentresult, ConfirmationNo, FailureMessage, InternalErrMsg)
                '    'resultDt.Rows.Add(resultdr)
                '    'Return resultDt.Rows
                '    Exit Try
                'End If
                'If PaymentProcessor = 1 Then
                Dim epi As New EPI_CC      // This EPI_CC is a public class included in Code library, here i am 
    getting an Error when creating the instance of EPI_CC
                'Dim icharge As New nsoftware.InPay.Icharge ////This is a dll included in Code library, here i am 
    getting an Error when creating the instance of Icharge 
                'icharge.Gateway = 1
                InternalErrMsg = epi.CCpaymentresult(TransactionType, Paydr, COnnectionString, ConfirmationNo, InternalErrMsg)
                ' Paymentresult = 1 ' Authorize_CC_Lib.ProcessCCPayment(Paydr, COnnectionString, ConfirmationNo, FailureMessage, InternalErrMsg)
                '  Else
                ' FailureMessage = "Processor Not Found"
                '  End If
            Catch excp As Exception
                ConfirmationNo = "0"
                FailureMessage = excp.ToString()    '.Message.ToString()
                InternalErrMsg = ""
                Paymentresult = 2
            Finally
                'If Not IsNothing(sqlcon) Then
                '    If sqlcon.State <> ConnectionState.Closed Then
                '        sqlcon.Close()
                '    End If
                '    sqlcon = Nothing
                'End If
            End Try
        End Sub
    ******************************
    Table valued Function is:
    Create FUNCTION [ePayment].[EPI_Submit_CC_Payment_Using_Assembly](@SQLClientConnString [nvarchar](255), @PaymentProcessor [int], @account_no [int], @sub_account_no [nvarchar](50), @amount [float], @ccno [nvarchar](20), @expMonth [nvarchar](2), @expYear [nvarchar](4), @pnlCode [nvarchar](10), @Address1 [nvarchar](250), @city [nvarchar](50), @state [nvarchar](10), @ZipCode [nvarchar](10), @InterfaceOpt [int], @IPAddress [nvarchar](50), @IsAutoPay [nvarchar](50), @InvoiceNo [nvarchar](50), @RunSequence [nvarchar](50), @TransactionMethod [int], @CCHardHolderName [nvarchar](50), @Comment1 [nvarchar](250), @Comment2 [nvarchar](250), @inserttoPayment [bit], @is_deposit [bit], @TransId [nvarchar](50))
    RETURNS  TABLE (
     [Paymentresult] [int] NULL,
     [ConfNumber] [nvarchar](50) NULL,
     [ErrMsg] [nvarchar](4000) NULL,
     [InternalErrMsg] [nvarchar](500) NULL
    ) WITH EXECUTE AS CALLER
    AS 
    EXTERNAL NAME [ePayment_CC_Assembly].[ePayment_CC_Assembly.EPI_Payment_CC_Assembly].[ProcessCCPayment]
    Please help me as soon as possible.
    Thanks
    Ankit

    • Edited by Ankit_MCL Friday, December 16, 2011 11:49 AM
    •  
  • Friday, December 16, 2011 6:16 PM
    Moderator
     
     
    Hi Ankit,
     
    The error that you are getting is “System.UriFormatException: Invalid URI: The URI is empty”, but I don’t see anything in your .NET code that passes the URI in or initializes it at all. Does your called component expect to find a URI somewhere (like a config file)? If so, you can try putting it in sqlserver.exe.config, subject to the limitation that, while this works now, using a config file with SQLCLR is not guaranteed to work in future.
     
    But by looking at the error message (but not the code that produces it), I can’t figure out when the called component expects to find its URI.
     
    Hope this helps,
    Cheers,
    Bob
  • Monday, December 19, 2011 7:29 AM
     
     

    Hi  Bob,

     

    Thanks a lot for your response.

    Here nsoftware.Inpay is a third party dll, when we are creating any instance of the class used in that Dll in our Wrapper dll, there it creates the Error. When i told them regarding that, they told me to download the Licence file and include it in the bin folder . I did the same but that Error not Removed. 

    Please help me asap

    Thanks

    Ankit

  • Tuesday, June 12, 2012 11:30 AM
     
     

    Hi, it is a long time. I think, that I have exactly the same problem with some else third party library. It is licensed by licx file too. Inside SQL Server CLR procedure it crash with System.UriFormatException ...

    Did you solve it somehow?