Comments (3)
Thank you.
To fully apply Native AOT, a fundamental understanding may be necessary.
Currently, we're only applying stopgap measures.
from memorypack.
This also occurs in a Blazor WebAssembly Standalone project. I have attached a minimal reproduction project in .NET 8.
This may be more related to trimming than it is AOT. There are attributes such as the DynamicDependencyAttribute
that can be applied to types to flag them as dynamically accessible, but it gets pretty nuanced. I'm not clear on what is trying to be accessed dynamically that is failing. From the stack trace it appears to try and call a Constructor ctor
on the interface IBob
?
What is going on here that it is trying to call a constructor on the interface? Is this normal behavior for MemoryPack, or would it be expected that it would normally identify the underlying derived concrete type and try to construct it instead?
at BlazorAppMemoryPackBug.IBob..cctor()
You can set a breakpoint in the catch block, or open the browser debug console as this is where WebAssembly Console.WriteLine outputs to:
MemoryPack.MemoryPackSerializationException: BlazorAppMemoryPackBug.IBob is failed in provider at creating formatter.
blazor.webassembly.js:1 ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
blazor.webassembly.js:1 ---> System.TypeInitializationException: The type initializer for 'BlazorAppMemoryPackBug.IBob' threw an exception.
blazor.webassembly.js:1 ---> System.BadImageFormatException: Method has no body
blazor.webassembly.js:1 File name: 'MemoryPack.Core'
blazor.webassembly.js:1 at MemoryPack.MemoryPackFormatterProvider.Register[IBob]()
blazor.webassembly.js:1 at BlazorAppMemoryPackBug.IBob..cctor() in C:\Users\Aaron\source\repos\BlazorAppMemoryPackBug\obj\Debug\net8.0\MemoryPack.Generator\MemoryPack.Generator.MemoryPackGenerator\BlazorAppMemoryPackBug.IBob.MemoryPackFormatter.g.cs:line 31
blazor.webassembly.js:1 --- End of inner exception stack trace ---
blazor.webassembly.js:1 at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
blazor.webassembly.js:1 at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
blazor.webassembly.js:1 --- End of inner exception stack trace ---
blazor.webassembly.js:1 at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
blazor.webassembly.js:1 at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
blazor.webassembly.js:1 at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
blazor.webassembly.js:1 at MemoryPack.MemoryPackFormatterProvider.TryInvokeRegisterFormatter(Type type)
blazor.webassembly.js:1 at MemoryPack.MemoryPackFormatterProvider.Cache`1[[BlazorAppMemoryPackBug.IBob, BlazorAppMemoryPackBug, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]..cctor()
blazor.webassembly.js:1 --- End of inner exception stack trace ---
blazor.webassembly.js:1 at MemoryPack.MemoryPackSerializationException.ThrowRegisterInProviderFailed(Type type, Exception innerException)
blazor.webassembly.js:1 at MemoryPack.ErrorMemoryPackFormatter`1[[BlazorAppMemoryPackBug.IBob, BlazorAppMemoryPackBug, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].Throw()
blazor.webassembly.js:1 at MemoryPack.ErrorMemoryPackFormatter`1[[BlazorAppMemoryPackBug.IBob, BlazorAppMemoryPackBug, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].Serialize[ReusableLinkedArrayBufferWriter](MemoryPackWriter`1& writer, IBob& value)
blazor.webassembly.js:1 at MemoryPack.MemoryPackSerializer.Serialize[IBob](IBob& value, MemoryPackSerializerOptions options)
blazor.webassembly.js:1 at BlazorAppMemoryPackBug.Program.Main(String[] args) in \source\repos\BlazorAppMemoryPackBug\Program.cs:line 30
from memorypack.
I was able to workaround this by registering programmatically with MemoryPackFormatterProvider.Register(
@carmichaelalonso Does this approach work in your case?
[MemoryPackable]
public partial class Bob: IBob
{
public string Name { get; set; }
}
[MemoryPackable]
[MemoryPackUnion(0, typeof(Bob))]
public partial interface IBob
{
string Name { get; set; }
}
public class Program
{
public static async Task Main(string[] args)
{
var formatter = new DynamicUnionFormatter<IBob>(
(0, typeof(Bob))
);
MemoryPackFormatterProvider.Register(formatter);
var bob = new Bob() { Name = "Bob"};
var ibob = (IBob)bob;
MemoryPackSerializer.Serialize(ibob);
from memorypack.
Related Issues (20)
- [Request] Error with parameters in class that are not Deserialized
- TypeScript generator is generating files with mixed line endings
- Memory<T> support for TypeScript generator
- TypeScript generator is a bit too eager to generate the file HOT 1
- Support Orleans HOT 1
- Compilation errors on Unity 2022.3.36f1 when adding v1.21.1 to package.json HOT 1
- C# Multiple inheritance types lost on Serialization/Deserialization HOT 2
- Is there anything like a non-generic IMemoryPackable? HOT 1
- Error Occured in Quick Start case HOT 1
- Proposal: Replace 'in' with 'ref' in Serialize method when using TBufferWriter HOT 1
- Init-only property in CircularReference class is not Deserialized HOT 1
- Unity console log file links do not navigate to generated files HOT 1
- SortedList<long,float?> and SortedList<long,double?> Deserializes incorrectly HOT 1
- [MemoryPackIgnore] for field in unmanaged struct does not wok. HOT 1
- [SuppressDefaultInitialization] for field in TypeScript does not wok. HOT 1
- Make GenerateTypeScript support GenerateType.VersionTolerant HOT 1
- MONO interpreter: NIY encountered in method MemoryPack.IMemoryPackable.Deserialize HOT 1
- DynamicUnionFormatter syntax gives compile error HOT 1
- How to Use Distributed Cache with SizeLimit in MemoryCache HOT 1
- Feature Request: Add support for MemoryPackUnion for non-abstract, non-interface classes.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from memorypack.