Problems defining an enum

Posts   
 
    
mrpmorris
User
Posts: 26
Joined: 07-Jul-2017
# Posted on: 26-Sep-2017 13:26:32   

Version 5.2.3

My first problem is that LLBLGen locks the assembly specified in my BusinessDomain.typeimports file and doesn't relinquish the lock until I close the app. It's only a minor inconvenience, but I have to close your app to rebuild my C# project.

My second problem is that the enum I have defined in my code won't show up in my LLBLGen project. Here are the steps I followed

1: Create my enum in my project and build (dotnet core 2.0 class library) namespace Api.Models { public enum RecipientKind { Unspecified = 0, SpecifiedUsers = 1, Company = 2 } }

2: Create BusinessDomain.typeimports file <typeImports> <typeImport typeName="Api.Models.RecipientKind" assemblyFile="C:\PathToMyProbject\Api\bin\netstandard2.0\Api.dll"/> </typeImports>

3: Add my .typeimports file to my project Menu: [Project -> Settings] Option: [Entity Model] Additional type converter file = c:\PathToMyFile\BusinessDomain.typeimports

4: Re-import my typeimports Project explorer: [Root node "BusinessDomain"] Action: [Right click] Menu: [Re-scan for TypeConverters and .typeimports Files]

5: Check for imported enums Menu: [Tools] Option: [View Loaded External Tools]

Expected: An entry with my path + full name Actual: All entries are based in {ProgramFiles}\Solutions Design\LLBLGEN Pro v5.2\

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 26-Sep-2017 18:22:37   

What does the application output window say, does it report an error?

It can't load .net core dlls btw. The designer runs on .NET full, so you have to compile the enums against that too. It might work if you compile against .netstandard 1.3, but not sure if that works for you.

Frans Bouma | Lead developer LLBLGen Pro
mrpmorris
User
Posts: 26
Joined: 07-Jul-2017
# Posted on: 27-Sep-2017 10:05:16   

Otis wrote:

What does the application output window say, does it report an error?

No errors reported.

Otis wrote:

It can't load .net core dlls btw. The designer runs on .NET full, so you have to compile the enums against that too. It might work if you compile against .netstandard 1.3, but not sure if that works for you.

Do you have any plans to support this? My solution has quite a few projects already, I don't want to have to add another just to generate source code correctly.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 27-Sep-2017 10:41:19   

mrpmorris wrote:

Otis wrote:

What does the application output window say, does it report an error?

No errors reported.

Otis wrote:

It can't load .net core dlls btw. The designer runs on .NET full, so you have to compile the enums against that too. It might work if you compile against .netstandard 1.3, but not sure if that works for you.

Do you have any plans to support this? My solution has quite a few projects already, I don't want to have to add another just to generate source code correctly.

Well, the designer can't run on .net core, as .net core doesn't support a windows UI. It does run on .net 4.5.2 and higher so you should be able to use netstandard 1.3 I think.

All it does is reflect on the assembly, so if .net allows that it works, that's all it can do, really.

We do have plans to refactor the core away from type instances and towards type names, but that work hasn't been done yet so the current versions and upcoming version v5.3 still rely on type instances.

Frans Bouma | Lead developer LLBLGen Pro
mrpmorris
User
Posts: 26
Joined: 07-Jul-2017
# Posted on: 27-Sep-2017 10:46:33   

Otis wrote:

It might work if you compile against .netstandard 1.3, but not sure if that works for you.

Unfortunately not. The assembly won't compile against .netstandard 1.3 because we use the Dynamic type.

It is currently compiling as .netstandard 2.0 - Have you tested the feasibility of supporting that by upgrading your project's references?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 27-Sep-2017 17:17:54   

.net standard 2.0 is supported by .net 4.6.2 but we want to run the designer on a lower .net version as well, as not everyone migrates to .net 4.6.2 automatically.

In the llblgenpro.exe.config file, there's a line, like this one: <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>

if you change that to Version="v4.7", it should run on .NET 4.7 (if you have installed that) and support .net standard 2.0, but again, as we reflect over an assembly through the .net framework, if that fails to load it, it's not going to work. What's a bit odd is that the application output window doesn't report an error. Which likely means it's not seen as a valid dll at all (by .net full, the version the designer runs on)

I'll do some tests tomorrow to see if I can get it working here locally.

Frans Bouma | Lead developer LLBLGen Pro
mrpmorris
User
Posts: 26
Joined: 07-Jul-2017
# Posted on: 27-Sep-2017 17:29:54   

Otis wrote:

I'll do some tests tomorrow to see if I can get it working here locally.

I'll wait until you have looked into it. I look forward to reading your results.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 28-Sep-2017 14:25:03   

It fails because the .NET assembly loader tries to find netstandard2.0 dll, the shim dll which redirects code to the real implementations and this fails. So the type is simply returned as 'null' and thus ignored.

I can't find any evidence this should work as well, so I have no idea how to make it work. We could bind to a resolve event to resolve the missing assemblies, but where from?

So this isn't supported, the enum type dll has to be a .net full dll the moment. The best way to do this, is by using multi-targeting.

In your csproj file you have:


<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
...

change this to: (pay attention to the changed element name!)


<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
  </PropertyGroup>
...

You'll now get 2 dlls, for the enum projects one for netstandard2.0 and one for net452. Use the latter in your typeimports. This is low friction, you'll reference the netstandard2.0 one elsewhere, and it doesn't require any extra code.

Frans Bouma | Lead developer LLBLGen Pro
mrpmorris
User
Posts: 26
Joined: 07-Jul-2017
# Posted on: 28-Sep-2017 15:29:46   

That seems to have done the trick and was very painless indeed, thanks!

Now I see my custom enum type registered, how do I tell your app that this is the type I want generated for ClassX.PropertyY?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 28-Sep-2017 16:42:22   

Every imported enum gets a typeshortcut automatically, see Project settings -> Entity Model -> Type shortcuts. you can use the typeshortcut to specify the type for a field in quickmodel or in the entity editor. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
mrpmorris
User
Posts: 26
Joined: 07-Jul-2017
# Posted on: 28-Sep-2017 16:49:09   

Otis wrote:

Every imported enum gets a typeshortcut automatically, see Project settings -> Entity Model -> Type shortcuts. you can use the typeshortcut to specify the type for a field in quickmodel or in the entity editor. simple_smile

Hi

I had worked out as far as finding my entry in Type Shortcuts. My problem is that when I locate the field in question in the editor [Entities->Notification->NotificationType] I am not able to edit any properties or anything.

So, how do I tell your app that Notification.NotificationType (which is an integer in the DB) should be C# generated with its type as the enum BusinessDomain.Models.RecipientKind?

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 28-Sep-2017 19:25:09   

If you edit an entity, and go to the "Fields" tab, there you can change the "Type" of each field, to pick from available system types or type shortcuts.

mrpmorris
User
Posts: 26
Joined: 07-Jul-2017
# Posted on: 02-Oct-2017 12:54:01   

Walaa wrote:

If you edit an entity, and go to the "Fields" tab, there you can change the "Type" of each field, to pick from available system types or type shortcuts.

Ah, it was the right-click -> Edit Entity bit that I was unaware of. I expected to be able to right-click and edit the field itself.

Thanks!