Solved

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

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

Accepted Solution

by:
Kyle Abrahams earned 500 total points
Comment Utility
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
Comment Utility
Thanks.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now