New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeDescriptor.AddAttributes() with TypeConverterAttribute not working in content importer #3387
Comments
It's probably because of this: MonoGame itself calls I assume there was a good reason why it's done this way in MonoGame. Without knowing the history, I'm not sure why we couldn't use EDIT: actually I can't find anywhere that MonoGame registers a |
I don't remember for certain why, but one potential issue is that WinRT doesn't support |
@tgjones As far as I know, calling AddAttributes for attributes already part of a class will replace them rather than be ignored. So even if MonoGame does this my change should have overwritten it for use in my importer. Also, I'm not migrating from XNA so that really isn't a factor in my case. This is a case of using MonoGame where AddAttributes() works correctly at runtime but not in the content pipeline. |
I've done some more looking and managed to find the solution. The issue is due to some quirk about how assemblies are loaded dynamically. So it's not a problem with MGCB, but it could be a potential problem for anyone else that might try to use their own type converter for content building. |
Hello. I am having the same issue on a Unity project but the solution provided by Inverness doesn't fix it. Any idea? Notice: Unity is working on mono environment and I asked the same question in here: http://answers.unity3d.com/questions/1274587/why-does-typedescriptoraddattributes-not-work-in-u.html |
@XtroTheArctic I see from the link that this seems to be a bug in how Mono retrieves type converters. If this is for JSON serialization you'll need to do a workaround by adding your own converters to the JsonSerializerSettings. |
Something I've done for quite some time in my game is use TypeDescriptor.AddAttributes() to specify type converters for common types like Vector2 and Rectangle so they're serialized and deserialized as a comma-delimited string.
When trying to use this same strategy in a content importer with MGCB, it fails to make any change to the converter returned with TypeDescriptor.GetConverter(). I'm mystified as to what could be causing this behavior.
Example:
The converter variable is the default TypeConverter instead of a RectangleConverter as it should be. At first I thought it was some oddity with JSON.NET but having the following GetConverter() call not return the proper type seems to indicate otherwise.
The text was updated successfully, but these errors were encountered: