-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
TypeLoadException when attempting serialization of value type defined in referenced .NET Framework class library #2981
Comments
workarounds:
namespace System.Runtime.CompilerServices {
[AttributeUsage(AttributeTargets.All, Inherited = false)]
sealed class IsReadOnlyAttribute : Attribute {
public IsReadOnlyAttribute() { }
}
}
|
Closing, as the workarounds are sufficient. Why does this happen only on |
I think it's the new 'readonly member' feature in C#8, and only structs can have readonly members. Seems like you're compiling your code with the latest Roslyn compiler. |
@0xd4d Even when I explicitly set the compiler version to 7.3, and to 7.0, in both the .NET Framework and .NET Core projects, I still get the same error, and not while serializing the class, only when serializing the struct. |
Yes, you could report it to roslyn, I'm not sure if it's a feature or a bug to add [IsReadOnly] to the getter. https://github.com/dotnet/roslyn/issues |
I have the following project dependency structure:
Fx
contains two types:struct EndNodeData
class TestClass
Serializing an instance of
TestClass
succeeds:but serializing a value of
EndNodeType
fails:with the following exception:
Commenting out the
string
properties doesn't help.Sample code
Related StackOverflow question
Running Windows 10 Home 1903 64-bit.
dotnet --version
prints2.2.300
Using these functions I get the following output:
The text was updated successfully, but these errors were encountered: