andrewlock / StronglyTypedId

A Rosyln-powered generator for strongly-typed IDs
MIT License
1.52k stars 79 forks source link

Possible Bug #24

Closed matthewblott closed 2 years ago

matthewblott commented 4 years ago

When I tried to access a route in ASP.NET with a strongly typed paramter I kept getting the following error:

Model bound complex types must not be abstract or value types and must have a parameterless constructor.

I had real trouble finding the problem as I had the code working prior to using the StronglyTypedId library itself. After much hunting I found the offending line:

https://github.com/andrewlock/StronglyTypedId/blob/4b533c1552cc06d11b12f6cd8843cc3a089dc54d/src/StronglyTypedId.Generator/templates/IntId.cs#L34

In the example on your website here typeof(string) is used in place of typeof(int). The example is for a Guid and not an int but the behaviour is the same when used with ASP.NET routes (which is what I thought that snippet was for). FWIW the Long template also references int. Shall I fix?

andrewlock commented 3 years ago

Sorry for the delay, this one slipped past me!

Just to clarify, you say this error is in ASP.NET routes, is that ASP.NET as in pre-ASP.NET Core? I've not tied it in there, but I don't think they will work at all based on that error message, as it implies you can't use structs (which is required in the library at the moment)

matthewblott commented 3 years ago

No, this is specifically ASP.NET Core (3.1).

andrewlock commented 3 years ago

Urgh, looks like an SDK update has broken the build, will have to try and fix that first before I can fix this 😭

matthewblott commented 3 years ago

Urgh, looks like an SDK update has broken the build, will have to try and fix that first before I can fix this 😭

No worries, thanks for the update :-)

andrewlock commented 3 years ago

This took rather too long to address, sorry 😳

I've released a beta version of a major update to the library converts to using Source generators. There's quite a few breaking changes in the release, so please make sure to check the release notes for how to update, but I'd appreciate any feedback you have before I do a final release! It fixes this issue too.

I've also written a blog post announcing the update that goes into a bit more details: https://andrewlock.net/rebuilding-stongly-typed-id-as-a-source-generator-1-0-0-beta-release

Thanks! 🙂

andrewlock commented 2 years ago

I believe this is solved in the latest betas, so I'll close it for now. Feel free to reopen if you still have any issues