local assembly = (dotnetclass "System.Reflection.Assembly").Load ((dotnetclass "System.IO.File").ReadAllBytes "c:\\myDll.dll")
local type = assembly.GetType "myNameSpace.myClass"
local classInstance = (dotNetClass "activator").CreateInstance type
Now i just need to figure out how to use it with dotNetControls.
let’s start from the end of you post… the loading of DLL (assembly) as bytes array allows you to override the DLL because the DLL (as file) is not captured by MAX. That’s the goal. It makes debugging process much easier. My code above creates new assembly and you can use CreateInstance method to create a class from this assembly.
So it has to go as:
my_assemby = (see code above)
my_class = my_assembly.CreateInstance "MyClass"
after that you can use any method from the class…
you can create you own object from of your class (or any type defined in the class) but not a dotnetcontrol. Dotnetcontrol is not really .NET object, it makes sense in MAX only. Dotnetcontrol is MAX Script UI control wrapper and it uses .net object from first loaded assembly. So you can load your assembly using byte method and can create dotnetcontrol but only from assembly that was loaded first.
Damn i thought it worked but it doesn’t, I get “Cannot directly assign rollout controls” error. Oh well, it’s still a step forward if we can use dynamic dotnetclasses and objects, thanks a lot denisT
And dot net controls. IS there any known problems with this approach?
I will start to try some things, and read further into the information presented on t’web but just in case I am on a massive wild goose chase, please feel free to give me any info to stop me in my tracks!
I could only check 2009x64 and 2011x64, but the following “doesn’t crash”…
dotnet.loadassembly "System.Core.dll"
enum = dotnetclass "System.Linq.Enumerable"
r = enum.range 1 10
showproperties r
showmethods r
getProperty r "<>3__count"
getProperty r "<>3__start"
thank you biddle.
I just don’t understand why I can load “System.Core.dll” as assembly, I can add it to CompilerParams.ReferencedAssemblies, but compiler can’t find it.
fn CreateTestAssembly =
(
source = ""
source += "using System;
"
source += "using System.Linq;
"
source += "public class testClass
"
source += "{
"
source += "}
"
csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
compilerParams.ReferencedAssemblies.Add "System.dll"
compilerParams.ReferencedAssemblies.Add "System.Core.dll"
compilerParams.GenerateInMemory = true
compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
if (compilerResults.Errors.Count > 0 ) then
(
errs = stringstream ""
for i = 0 to (compilerResults.Errors.Count-1) do
(
err = compilerResults.Errors.Item[i]
format "Error:% Line:% Column:% %
" err.ErrorNumber err.Line err.Column err.ErrorText to:errs
)
MessageBox (errs as string) title: "Errors encountered while compiling C# code"
format "%
" errs
undefined
)
else
(
compilerResults.CompiledAssembly.CreateInstance "testClass"
)
)
global testClass = CreateTestAssembly()
that’s right. i do the same. but… why the assembly can be loaded right without the fullpath? of course i don’t have any problem to use dll compiled in the vstudio. that means MAX fully supports .net 3.5. i’m really puzzled.
Hej guys I am having a bit of problem, I cant get the proper encoding/buffer param done for my streamwriter. I wonder maybe somebody could help me out with it.
I was referering to this one > http://msdn.microsoft.com/en-us/library/72d9f8d5.aspx and it is a dontnet 2.0 constructor. Well In max 2010 dotnet 2.0 isnt it? There is only 3 params.
Anyway, thank you very much, this will do well too!
I know how to do it in C#, but I need to do it in Max using MaxScript. Just like one of the posters said, IEnumerable doesn’t have a .ToArray() extension. So it’s not as simple as that.