Activator.CreateInstance not able to create object in .net console application

sabinofz

New member
Joined
Dec 22, 2024
Messages
3
Programming Experience
10+
I have a solution with several vb projects and one console application in .net
In console application y have references as projects the vb projects.
When i run the console application and I execute :

C#:
aAccion = Activator.CreateInstance(Type.GetType("BP.CN.MPIion" + sTokens(0)), oParameters)

I get an error that console application is not able to create the object. The dll that manage
this object in in a the vb projects referenced.

I checked if the dll is loaded when i run console application and is not loaded.
I loaded manyally the dell with code in init of console application and it doesn´t work also.
I tried to add dlls directrly as referenced and it doesn´t work also.
Any idea or solution?
 
Last edited by a moderator:
Please post the exact error message you are getting.

It's usually better to break-up your code into multiple lines so that you can potentially see what the issue is. So you should have something like:
C#:
var typeName = "BP.CN.MPIion" + sTokens(0);
var type = Type.GetType(typeName);
aAccion = Activator.CreateInstance(type, oParameters);

You can then step through your code with a debugger to see the values along each stage of the way, as well as identify which step is failing. If I were to guess, the Type.GetType() is returning null. In my mind, this is partly confirmed by your report that the DLL is not loaded.

Don't be tricked into thinking that less lines is more efficient. The compiler is very good at folding code when building release builds.

Not related to your problem: Don't use Hungarian notation when writing C# code. This is stated Microsoft's naming conventions.
 
Last edited:
Looks like your question was closed in StackOverflow because you didn't do enough to provide debugging information. You'll not get much engagement here either without sufficient information.
 
Please post the exact error message you are getting.

It's usually better to break-up your code into multiple lines so that you can potentially see what the issue is. So you should have something like:
C#:
var typeName = "BP.CN.MPIion" + sTokens(0);
var type = Type.GetType(typeName);
aAccion = Activator.CreateInstance(type, oParameters);

You can then step through your code with a debugger to see the values along each stage of the way, as well as identify which step is failing. If I were to guess, the Type.GetType() is returning null. In my mind, this is partly confirmed by your report that the DLL is not loaded.

Don't be tricked into thinking that less lines is more efficient. The compiler is very good at folding code when building release builds.

Not related to your problem: Don't use Hungarian notation when writing C# code. This is stated Microsoft's naming conventions.

And what solution suggest?
 
Please post the exact error message you are getting.

It's usually better to break-up your code into multiple lines so that you can potentially see what the issue is. So you should have something like:
C#:
var typeName = "BP.CN.MPIion" + sTokens(0);
var type = Type.GetType(typeName);
aAccion = Activator.CreateInstance(type, oParameters);

You can then step through your code with a debugger to see the values along each stage of the way, as well as identify which step is failing. If I were to guess, the Type.GetType() is returning null. In my mind, this is partly confirmed by your report that the DLL is not loaded.

Don't be tricked into thinking that less lines is more efficient. The compiler is very good at folding code when building release builds.

Not related to your problem: Don't use Hungarian notation when writing C# code. This is stated Microsoft's naming conventions.

1734893360120.png

Here the error
 
Back
Top Bottom