Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-01-23
2
Medium Priority
?
462 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 41

Accepted Solution

by:
Kyle Abrahams earned 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Integration Management Part 2

971 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