473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Error dynamically invoking vb.net dll from C# test application

Hi all,
I have test application written in C# from which I am trying to dynamically
invoke a DLL. I have two dll's the only difference being one is written in C#
and the other in VB.NET. The test application is able to sucessfully invoke
the dll written in C#. However when attempting to invoke the VB.NET version
of the dll the following error message occurs:

Unhandled Exception: System.ArgumentNullException: Value cannot be null.
Paramater name: Type at System.Activator.CreateInstance(Type type, Boolean
nonPublic) at ConsoleApplication1.Program.Main(String[] args ) line 30.
Would anyone have any ideas why this is occuring? any help / comments
greatly appreicated (please see source code below).

TEST APPLICATION
============
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Reflection;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{

string className = "proclaim";
string enServer = "http://gis/mcity";
string enXML = "100.xml";

//string className = "enIntegration";
string appdll = className + ".dll";
object i = null;

//use reflection to invoke the Translator component
// Load the generated assembly into the ApplicationDomain
Assembly asm = Assembly.LoadFrom(appdll);

Type mm = asm.GetType(className + "." + className);

object o = Activator.CreateInstance(mm);

//Invoke a non-static method with parameters
object[] par = new object[] { enServer, enXML };

i = (String)mm.InvokeMember("Translate", BindingFlags.Default |
BindingFlags.InvokeMethod, null, o, par);
Console.WriteLine(i);
}
}
}
C# version of DLL
==========
using System;
using System.Collections.Generic;
using System.Text;

namespace proclaim
{
class proclaim
{

public string Translate(string enServer,string enXML)
{
return "Success";
}
}
}

VB.NET version of dll
==============
Imports System
Imports System.Collections.Generic
Imports System.Text

Namespace proclaim
Class proclaim

Public Function Translate(ByVal enServer As String, ByVal enXML As
String) As String
Return "Success"
End Function
End Class
End Namespace
Apr 20 '06 #1
1 1861
Lorraine <Lo******@discussions.microsoft.com> wrote:
Hi all,
I have test application written in C# from which I am trying to dynamically
invoke a DLL. I have two dll's the only difference being one is written in C#
and the other in VB.NET. The test application is able to sucessfully invoke
the dll written in C#. However when attempting to invoke the VB.NET version
of the dll the following error message occurs:

Unhandled Exception: System.ArgumentNullException: Value cannot be null.
Paramater name: Type at System.Activator.CreateInstance(Type type, Boolean
nonPublic) at ConsoleApplication1.Program.Main(String[] args ) line 30.
Would anyone have any ideas why this is occuring? any help / comments
greatly appreicated (please see source code below).


Well, the exception shows that Assembly.GetType has returned null. My
guess is that your VB.NET project has a "default namespace" which it
puts everything under - so your class isn't actually proclaim.proclaim,
but ProjectName.proclaim.proclaim. (I hope you don't really use the
same name for the namespace and the class, by the way - it's a really
bad idea.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 20 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Kevin Little | last post by:
#!/usr/bin/env python ''' I want to dynamically add or replace bound methods in a class. I want the modifications to be immediately effective across all instances, whether created before or...
11
by: Steven D'Aprano | last post by:
Suppose I create a class with some methods: py> class C: .... def spam(self, x): .... print "spam " * x .... def ham(self, x): .... print "ham * %s" % x .......
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
3
by: Bill Cohagan | last post by:
I'm writing a console app in c# and am encountering a strange problem. I'm trying to use redirection of the standard input stream to read input from a (xml) file. The following code snippet is from...
6
by: Ken | last post by:
When running a program in the debugger, what would cause it to crash without any error messages? I get "The program has exited with code 0 (0x0)". The program is a MDI app with threading for...
9
by: bill | last post by:
I keep getting Object reference not set to an instance of an object error when trying to run my application on an installed client machine. I installed it on several others and it runs fine. I...
5
by: Rakesh Rathod | last post by:
Hi, I need to invoke a web service dynamically at runtime without adding a web reference. I need to do this through a C# application (.NET 2.0). At runtime my application will get the url of the...
0
by: Ned Balzer | last post by:
I have a puzzling problem. I am using some code I found in another thread here to output the results of a gridview to excel. Here is the subroutine: Sub SendToExcel(ByVal Source As Object,...
2
by: =?Utf-8?B?SmltIE93ZW4=?= | last post by:
Hi John, Hopefully this post will find its way back to you - or perhaps be answered by someone else. As I mentioned in my last post on the earlier portion of this thread, changing the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.