Solved

calling c# dll from VB.Net, setting a property of type list

Posted on 2014-01-23
2
456 Views
Last Modified: 2014-01-23
Hello.

I have a c# dll, and it has this class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CRPassThrough
{
    public class StringParams
    {
        public string ParamName { get; set; }
        public string ParamValue { get; set; }
    }
}

My plan is to use it like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Windows.Forms;

namespace CRPassThrough
{
    public class Main
    {
        public List<StringParams> SParams { get; set; }


        public bool Report()
        {
            try
            {
                if (SParams != null)
                {
                    foreach (StringParams SP in SParams)
                    {
                        -- do something with the parameters sent in --
                    }
                }

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
}



I am trying to call this dll from a VB.Net project:

    Private Sub bFull_Click(sender As Object, e As EventArgs) Handles bFull.Click

        Try
            Dim PT As New CRPassThrough.Main()

            Dim SParam As CRPassThrough.StringParams = New CRPassThrough.StringParams()
            SParam.ParamName = "Job_Number"
            SParam.ParamValue = Me.tJob.Text
            PT.SParams.Add(SParam)

        Catch ex As Exception
            Globals.WriteMessage(Me, "E", "Error Printing Report: " & ex.Message & vbCrLf, "frmPacklistReports,bFull_Click")
        End Try

    End Sub


At the line PT.SParams.Add(SParam), I get "Object Reference not set to an instance of an object.

PT.SParams is nothing, as the error would indicate.

However, when I try to create an instance of the object, e.g. with

Dim something as PT.SParams = new PT.SParams()

PT is not present (no intellisense, etc.)

What am I doing wrong, either in the dll or the VB project?



Thanks.
0
Comment
Question by:g_johnson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 39803965
public List<StringParams> SParams { get; set; }

The list is never instantiated.

In the Main Constructor add the following:

SParams = new List<StringParams>();
0
 
LVL 4

Author Closing Comment

by:g_johnson
ID: 39804275
Thanks.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question