DeanoCalver

I've got a bit of code that loads an assembly dynamically and invokes a constructor working fine in PC XNA but I can't find the equivilent under .Net Compact on the 360...

PC
Assembly assembly = Assembly.LoadFrom(s);
Type mainClosure = assembly.GetType(scriptName + ".MainFunction");
LuaClosure cl = (LuaClosure)Activator.CreateInstance(mainClosure, new object[] { L.Globals });

Attempt on 360

Assembly assembly = Assembly.LoadFrom(s);
Type mainClosure = assembly.GetType(scriptName + ".MainFunction");
ConstructorInfo ctor = mainClosure.GetConstructor(
BindingFlags.Instance | BindingFlags.Public, null, new Type[] { typeof(LuaReference) }, null);
LuaClosure cl = (LuaClosure)ctors[0].Invoke(new Object[] { L.Globals });

Which fails... Anybody got any ideas AFAICT its the same but clearly not...

Thanks,
Deano


Re: XNA Framework Activator.CreateInstance on .Net compact

Shawn Hargreaves - MSFT

Where exactly is it failing Is the ctor coming back null by any chance

I'm not sure if BindingFlags.Instance is the right option for constructor methods - isn't there a special binding flag for constructors





Re: XNA Framework Activator.CreateInstance on .Net compact

DeanoCalver

Yeah, ctor comes back null, I've tried a few combinations of parameters but haven't looked at a specific constructor binding flag yet. I'll check into that tonight.

I've also tried using GetConstructors() (the plural version) and invoking the first ctor that comes back (by using the debugger to check its the right one). That then fails at the Invoke with ArgumentException

The docs do mention a security setting can disallow this working. I'm hoping this isn't turned on the 360... Going to try getting this method on the PC and then trying that code on the 360 to ensure its not that.

Thanks Shawn, few more things to try tonight :)

Deano




Re: XNA Framework Activator.CreateInstance on .Net compact

Shawn Hargreaves - MSFT

There's no CLR security stuff turned on at all on Xbox, so that's not your problem.

I'm guessing it's the binding flags - I don't understand these enough to be sure but it usually takes me a few tries to figure out the right combinations!





Re: XNA Framework Activator.CreateInstance on .Net compact

Shawn Hargreaves - MSFT

Note: I've never used the overload of GetConstructor you are trying there, but I have code that uses the simple version that just takes an array of argument types, which avoids the question of what binding flags to specify. It seems like that one would actually be enough for you anyway





Re: XNA Framework Activator.CreateInstance on .Net compact

Arrakis777

It looks like you're trying to use a Lua library I thought this wasn't possible to do if you didn't have the source code to the entire DLL (and it would have to be writen in C# )

Chris





Re: XNA Framework Activator.CreateInstance on .Net compact

DeanoCalver

I'm in the last steps of releasing a version of Lua for XNA. Lua compiled to CLR IL runs fine on the 360 including source level debugging :D

I've just hit a stumbling block in my dynamic binding sample on the 360...
Which is nothing to do with Lua or XNA and everything to do with my stupidity I'm sure...




Re: XNA Framework Activator.CreateInstance on .Net compact

DeanoCalver

Okay I think I have it down to the way assembly's are namespaced. I assumed that a types name was what you see in C#

I.e.
namespace Lua2IL
{
publc class LuaReference{}
}

would be Lua2IL.LuaReference, however in realitys its assembly name first so Lua2IL.dll the full name of that type is
Lua2IL.Lua2IL.LuaReference

Now due to the way my content pipeline is setup, i need the PC version of Lua2IL.dll in the 360's binary folder (cos currently I can't figure out how to get the output directory from the content pipeline, so was using the location of the pipeline assembly), but thought that naming the 360 Lua2IL as Lua2ILX.dll wouldn't matter as the names and types were the same... but I was wrong.

The problem I have is that the PC version of Lua2IL.dll will work on the 360 if compiled as a PC library but won't as a 360 because it contain things like IL.Emit (which are defined out of existance on the 360 version).

So... My problem can be solved by handling the paths properly in the content pipeline and therefore NOT requiring the rename of the Lua2IL 360 version...

So least I'm not going mad but means reworking my content pipeline plugin... Doh!
I'll post another question with specific problems I having, tho I'm sure it will be you Shawn who will answer it LOL

I really I'm learning more than I ever wanted to know about how the CLR assembly system works...

Thanks Alot,
Deano




Re: XNA Framework Activator.CreateInstance on .Net compact

Arrakis777

So you're managing to get the DLL to load on the XBox, even though it is compiled for the PC That's pretty interesting. I am very interested in getting Lua to work on the XBox. Let me know if I can help, or if you need a tester! :)

Chris

( chris@chrisdrivesafastcar.com )





Re: XNA Framework Activator.CreateInstance on .Net compact

DeanoCalver

Well any pure CLR assembly that doesn't reference a non compact NET type will work on 360. However that's not the approach I've used, as the LuaInteface project used native C++ which won't work on 360.
However a while back a research project call Lua2IL was done. This is a Lua 5.0 byte code to CLR IL converter, what I've done is cleaned up a bit, ported it to .NET Compact, write a content pipeline to do the conversion automatically and write most a bunch of the Lua standard libraries.
So you add the content pipeline to your XNA project and then you can add .lua files to your project and it just works including source code level debugging.

My blog has some notes on where I'm at. With a bit luck the first (properly buggy) release will be this weekend.

Deano




Re: XNA Framework Activator.CreateInstance on .Net compact

Arrakis777

I am very excited to see your project. I guess it's time for me to learn Lua! :) I have a book called Programming Game AI by Example which has a whole section on using Lua for game AI.

Chris