eXpand icon indicating copy to clipboard operation
eXpand copied to clipboard

WorldCreator Module in .Net Core Framework

Open huncu16 opened this issue 2 years ago โ€ข 13 comments

๐—ค๐˜‚๐—ฒ๐˜€๐˜๐—ถ๐—ผ๐—ป Hi Tolis, When i convert our projects framework to .NetCore wich uses WorldCreator Module it doesn't compile the generated code becouse of using cSharpCodeProvider.CompileAssemblyFromSource(compilerParameters, code); code doesn't supported in .Net Core.

I've two question 1-Do you plan to fix this neartime 2-For System.Drawing.Image typed properties and also doesn't support in .Net Core for We platform. Do you advice to convert it any type for easiest way?

Thanx for answers by now. And tell a way to buy you a cup of coffe ;)

huncu16 avatar Sep 19 '23 15:09 huncu16

Hi,

Without a sample really I can only make guesses. Also unfortuately WC has no tests nor is used from other modules to verify it works on same level. However we have this Xpand.Extensions.Compiler.CodeCompiler.Compile which is used from the ModelMapper module and has tests for .NET Core.

So your options currently are

  1. Try to use this extensions instread with WC and post your modified sources so I can include it for others
  2. Wait until 23.2 is out so I can have a look my self given you post a sample I can repro the case.

Coffees or boost in my todo queque available at https://github.com/sponsors/apobekiaris

apobekiaris avatar Sep 19 '23 15:09 apobekiaris

Ok thanks for answer, We are waiting for your solution about this, we are in aggrieved position about that we cannot update our projects framework to .Net Core. Please notify us wich coffeer type is appropriate for you.

Best wishes.

huncu16 avatar Oct 23 '23 08:10 huncu16

please get in contact with me 2 [email protected] and provide a sample app

apobekiaris avatar Oct 23 '23 08:10 apobekiaris

I checked this case and in general WorldCreator is not at all trivial to get it to comply with the latest changes in XAF architecutre. In addition to non available tests/docs for the package I have no other option as to redesign it from scratch under the Reactive.XAF. So if there are interested sponsors get in touch with me.

apobekiaris avatar Nov 06 '23 16:11 apobekiaris

Tolis, hello again i've changed the method from CSharpCodeProvider.CompileAssemblyFromSource to CSharpCompilation.Emit

I put all assemblies our generated code needed and wich u add in Xpand.Extensions.Compiler.CodeCompiler.Compile method use this CSharpCompilation.Emit method. But the line we generate

public class DynamicDocumentLibraryModule: DevExpress.ExpressApp.ModuleBase{ }

gives error like below

"CS0012: The type 'Component' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ComponentModel.Primitives, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'"

if code generator skip to generate DynamicDocumentLibraryModule:DevExpress.ExpressApp.ModuleBase{} line Emit method compile it successfully but then i cannot get moduleType with code below

assembly.GetTypes().First(type => typeof(ModuleBase).IsAssignableFrom(type)); for adding it to ApplicationModulesManager

do u have an idea what am i missing?

huncu16 avatar Jan 12 '24 15:01 huncu16

do u have an idea what am i missing?

I bet u miss this :)

You must add a reference to assembly 'System.ComponentModel.Primitives, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

I am not sure if a missleading message though, it might refer to .net6 runtime rather to this specific assembly. In any case I would first verify that the assembly dependecy is there

apobekiaris avatar Jan 12 '24 16:01 apobekiaris

as far as I remember there was a parse of all dependecies on the runtime and automatically added to the dynamic assembly so in theory u should not go add dependecies manually.

apobekiaris avatar Jan 12 '24 16:01 apobekiaris

But if i donโ€™t add them CSharpCompilation gives assembly missing error.

Its very clear that it needs system.component ๐Ÿ˜€

Even i add System.Conponent and System.Component.Primitives dlls manually and nothing change.

huncu16 avatar Jan 13 '24 09:01 huncu16

look I am suggesting out of my mind, so I might be totally wrong cause no test no gain. Anyway these are core assemblies which points towards a .netframework version problem rather than specific assemblies

apobekiaris avatar Jan 13 '24 10:01 apobekiaris

Yes i can see, so do you know anyone else using this for .net core successfull or another xpand module generating bussines class assemblies in run time with xaf blazor?

huncu16 avatar Jan 13 '24 17:01 huncu16

Xpand generates assmblies at runtime with the Xpand.Extensions.Compiler.CodeCompiler.Compile extension in many places, in the RX repository at:

Search target
    Xpand.Extensions.Compiler.CodeCompiler.Compile(this SyntaxTree syntaxTree, params string[] references) : MemoryStream
Found usages  (3 usages found)
    <Editors>\<ProgressBarViewItem>\<Xpand.XAF.Modules.ProgressBarViewItem>  (1 usage found)
        Xpand.XAF.Modules.ProgressBarViewItem  (1 usage found)
            ProgressBarViewItemModule  (1 usage found)
                (55: 71)  using var memoryStream = CSharpSyntaxTree.ParseText(code).Compile(references);
    <Model>\<ModelMapper>\<Xpand.XAF.Modules.ModelMapper.Tests>  (1 usage found)
        Xpand.XAF.Modules.ModelMapper.Tests  (1 usage found)
            ModelMapperCommonTest  (1 usage found)
                (71: 60)  using var st= CSharpSyntaxTree.ParseText(code).Compile(typeof(object).Assembly.Location,typeof(AssemblyVersionAttribute).Assembly.Location);
    <Model>\<ModelMapper>\<Xpand.XAF.Modules.ModelMapper>  (1 usage found)
        Xpand.XAF.Modules.ModelMapper.Services.TypeMapping  (1 usage found)
            TypeMappingService  (1 usage found)
                (40: 75)  using var memoryStream = CSharpSyntaxTree.ParseText(code).Compile(references.ToArray());

ModelMapper works for .netcore. The dependecy collection is pretty similar to what I previously said (from the runtime) however is not a blazor module not that it matters and does not create Bussiness objects but rather maps any class to a model interface. You can get a lot of guidance from its codebase.

apobekiaris avatar Jan 13 '24 20:01 apobekiaris

i've checked ur ModelMapper Module. And i think its DBFirst based and if i use it i must model DB at first then get it to my application. Am i wrong?

huncu16 avatar Jan 15 '24 08:01 huncu16

the packages generates assemblies with dependecies for .netcore you can look how we did it there and apply it to your case

apobekiaris avatar Jan 15 '24 08:01 apobekiaris

Closing issue for age. Feel free to reopen it at any time.

.Thank you for your contribution.

expand avatar Mar 15 '24 21:03 expand