Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MetadataTypeAttribute not available in DNX Core 5.0

Tags:

asp.net-mvc

I want to use the MetaDatatType attribute in a MVC6 project and it does't seem to be available yet. I am using 7.0.0-rc1-final so it should the latest.

Does anyone know if it is in another assembly? I get the error, The type or namespace name MetadataType could not be found.

like image 726
forwheeler Avatar asked Oct 19 '22 16:10

forwheeler


1 Answers

After some googling it seems like this attribute is not available in MVC 6. You can use it in the full DNX, but it is unavailable in DNX Core.

Of course, you can decorate your code with

#if DNXCORE50
...
#endif

so that you get no errors when compiling for the full DNX, but it looks like the attribute does not do what it is expected. For example, DisplayName(Name = "...") does not work (I didn't check the other options like Required etc.).

IMHO, Fluent MetadataProvider may be a solution to this, only I do not know if it was ported to vNext. I am going to contact the author(s) and if they are not able to port it soon I'll fork it and will make an attempt to port it myself.

EDIT: ModelMetadataType replaces MetadataType. You must reference Microsoft.AspNet.Mvc.Core. I am not quite sure but maybe you'd need Microsoft.AspNet.Mvc.DataAnnotations too.

Anyway, my thoughts about Fluent Data Annotations (Fluent MetadataProvider) are still valid. You may also need to read an interesting article about this: Why You Don't Need ModelMetadata.Attributes by Brad Wilson.

like image 53
Alexander Christov Avatar answered Nov 15 '22 08:11

Alexander Christov