Solved

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

Posted on 2014-01-23
2
454 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
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

803 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