[Mono-list] Could not lookup zero argument constructor for class Ninject.StandardKernel
mimi
zachary.xu at jomediainc.com
Wed Mar 4 19:04:41 UTC 2015
@RobertJordan: After receiving your msg, I did more analyses. Here is the c#
code:
namespace ClassLibrary1
{
public class Class1
{
Class2 mClass2 = new Class2();
public Class1() { Console.WriteLine("Class1 constructor called!\n");
}
public void GreetPeople(string sInput1, string sInput2)
{
Console.WriteLine(sInput1 + "\n");
StandardKernel instanceStandardKernel = new StandardKernel();
mClass2.HelloWorld(sInput2 + "\n");
}
}
}
I tested it in Visual Studio and it works. Then I embedded it to my c++
code:
MonoDomain * domain = mono_jit_init_version ("Domain",
"v4.0.30319");
MonoAssembly * assembly = NULL;
assembly = mono_domain_assembly_open (domain,
"/Users/mac1/Downloads/zachary/TestLib/libs/TestZachary/ClassLibrary1.dll");
MonoImage * image = NULL;
image = mono_assembly_get_image(assembly);
MonoClass* classHandle = NULL;
classHandle = mono_class_from_name(image, "ClassLibrary1",
"Class1");
MonoObject* instanceClass1 = NULL;
instanceClass1 = mono_object_new(domain, classHandle);
if (!instanceClass1)
{
printf("Get object error\n");
}
else
{
printf("Get object successfully\n");
}
mono_runtime_object_init(instanceClass1);
const char* descAsString =
"ClassLibrary1.Class1:GreetPeople(string,string)";
MonoMethodDesc* description =
mono_method_desc_new(descAsString,true);
MonoMethod* method = mono_method_desc_search_in_class(description,
classHandle);
if (!method)
{
printf("method is NULL\n");
}
else
{
printf("Get method successfully\n");
}
void* args[2];
args[0] = mono_string_new(domain, "Greeting from a good friend!");
args[1] = mono_string_new(domain, "Hello My Mono World!");
mono_runtime_invoke(method, instanceClass1, args, NULL);
printf("Here we are, Cool!\n");
mono_jit_cleanup(domain);
The following are console outputs:
Debugging starts
Get object successfully
Class1 constructor called!
Get method successfully
Greeting from a good friend!
Unhandled Exception:
System.ArgumentNullException: Argument cannot be null.
Parameter name: path1
at System.IO.Path.Combine (System.String path1, System.String path2)
[0x00000] in <filename unknown>:0
at Ninject.Modules.ModuleLoader+<>c__DisplayClassb.<NormalizePaths>b__a
(System.String baseDirectory) [0x00000] in <filename unknown>:0
at
System.Linq.Enumerable+<CreateSelectIterator>c__Iterator10`2[System.String,System.String].MoveNext
() [0x00000] in <filename unknown>:0
at
System.Linq.Enumerable+<CreateSelectManyIterator>c__Iterator12`2[System.String,System.String].MoveNext
() [0x00000] in <filename unknown>:0
at
System.Linq.Enumerable+<CreateSelectManyIterator>c__Iterator12`2[System.String,System.String].MoveNext
() [0x00000] in <filename unknown>:0
at
System.Linq.Enumerable+<CreateGroupByIterator>c__Iterator5`2[System.String,System.String].MoveNext
() [0x00000] in <filename unknown>:0
at Ninject.Modules.ModuleLoader.LoadModules (IEnumerable`1 patterns)
[0x00000] in <filename unknown>:0
at Ninject.KernelBase.Load (IEnumerable`1 filePatterns) [0x00000] in
<filename unknown>:0
at Ninject.KernelBase..ctor (IComponentContainer components,
INinjectSettings settings, Ninject.Modules.INinjectModule[] modules)
[0x00000] in <filename unknown>:0
at Ninject.KernelBase..ctor (Ninject.Modules.INinjectModule[] modules)
[0x00000] in <filename unknown>:0
at Ninject.StandardKernel..ctor (Ninject.Modules.INinjectModule[] modules)
[0x00000] in <filename unknown>:0
at ClassLibrary1.Class1.GreetPeople (System.String sInput1, System.String
sInput2) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentNullException: Argument
cannot be null.
Parameter name: path1
at System.IO.Path.Combine (System.String path1, System.String path2)
[0x00000] in <filename unknown>:0
at Ninject.Modules.ModuleLoader+<>c__DisplayClassb.<NormalizePaths>b__a
(System.String baseDirectory) [0x00000] in <filename unknown>:0
at
System.Linq.Enumerable+<CreateSelectIterator>c__Iterator10`2[System.String,System.String].MoveNext
() [0x00000] in <filename unknown>:0
at
System.Linq.Enumerable+<CreateSelectManyIterator>c__Iterator12`2[System.String,System.String].MoveNext
() [0x00000] in <filename unknown>:0
at
System.Linq.Enumerable+<CreateSelectManyIterator>c__Iterator12`2[System.String,System.String].MoveNext
() [0x00000] in <filename unknown>:0
at
System.Linq.Enumerable+<CreateGroupByIterator>c__Iterator5`2[System.String,System.String].MoveNext
() [0x00000] in <filename unknown>:0
at Ninject.Modules.ModuleLoader.LoadModules (IEnumerable`1 patterns)
[0x00000] in <filename unknown>:0
at Ninject.KernelBase.Load (IEnumerable`1 filePatterns) [0x00000] in
<filename unknown>:0
at Ninject.KernelBase..ctor (IComponentContainer components,
INinjectSettings settings, Ninject.Modules.INinjectModule[] modules)
[0x00000] in <filename unknown>:0
at Ninject.KernelBase..ctor (Ninject.Modules.INinjectModule[] modules)
[0x00000] in <filename unknown>:0
at Ninject.StandardKernel..ctor (Ninject.Modules.INinjectModule[] modules)
[0x00000] in <filename unknown>:0
at ClassLibrary1.Class1.GreetPeople (System.String sInput1, System.String
sInput2) [0x00000] in <filename unknown>:0
Debugging has finished
My understanding is that, in Visual Studio, 'new StandardKernel()' invokes
the first ctor of StandardKernal class without passing anything and it
works.
public class StandardKernel : KernelBase
{
public StandardKernel(params INinjectModule[] modules) :
base(modules)
{
}
public StandardKernel(INinjectSettings settings, params
INinjectModule[] modules) : base(settings, modules)
{
}
......
}
For Mono, if I insert 'mono_runtime_object_init(instanceStandardKernel)', we
are trying to execute default argument-less ctor of StandardKernel that
doesn't exist and I got the error which is normal.
Here, how Mono will parse 'new StandardKernel()'? Default ctor or first ctor
without passing anything? Are error messages I got related to this?
Thanks!
Zachary
--
View this message in context: http://mono.1490590.n4.nabble.com/Could-not-lookup-zero-argument-constructor-for-class-Ninject-StandardKernel-tp4665563p4665568.html
Sent from the Mono - General mailing list archive at Nabble.com.
More information about the Mono-list
mailing list