Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

661 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