-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
Getting TypeLoadException when trying to access FlatSharp types #385
Comments
FlatSharp supports both. The these are generally hidden behind I've just checked in on the generated code, and the static definitions are indeed hidden behind preprocessor checks: #if NET7_0_OR_GREATER
static ISerializer<FlatSharpEndToEndTests.TableMembers.StringTable> IFlatBufferSerializable<FlatSharpEndToEndTests.TableMembers.StringTable>.LazySerializer { get; } = new FlatSharp.Compiler.Generated.N23CE084EA646E303A1AA88FAF338FAD75CE055E8444E3104C8E29DF9CDC39319.Serializer().AsISerializer(global::FlatSharp.FlatBufferDeserializationOption.Lazy);
#endif
#if NET7_0_OR_GREATER
static ISerializer<FlatSharpEndToEndTests.TableMembers.StringTable> IFlatBufferSerializable<FlatSharpEndToEndTests.TableMembers.StringTable>.GreedySerializer { get; } = new FlatSharp.Compiler.Generated.N23CE084EA646E303A1AA88FAF338FAD75CE055E8444E3104C8E29DF9CDC39319.Serializer().AsISerializer(global::FlatSharp.FlatBufferDeserializationOption.Greedy);
#endif
#if NET7_0_OR_GREATER
static ISerializer<FlatSharpEndToEndTests.TableMembers.StringTable> IFlatBufferSerializable<FlatSharpEndToEndTests.TableMembers.StringTable>.GreedyMutableSerializer { get; } = new FlatSharp.Compiler.Generated.N23CE084EA646E303A1AA88FAF338FAD75CE055E8444E3104C8E29DF9CDC39319.Serializer().AsISerializer(global::FlatSharp.FlatBufferDeserializationOption.GreedyMutable);
#endif
#if NET7_0_OR_GREATER
static ISerializer<FlatSharpEndToEndTests.TableMembers.StringTable> IFlatBufferSerializable<FlatSharpEndToEndTests.TableMembers.StringTable>.ProgressiveSerializer { get; } = new FlatSharp.Compiler.Generated.N23CE084EA646E303A1AA88FAF338FAD75CE055E8444E3104C8E29DF9CDC39319.Serializer().AsISerializer(global::FlatSharp.FlatBufferDeserializationOption.Progressive);
#endif There are a couple of things to check here:
|
Additionally, it would be enormously helpful if you could share a solution file that reproduces the issue. Thanks! |
I created a repro solution. Schemas dll (netstandard2.1) and a mstest project (Net7) Please let met know if something is wrong in the setup |
We are shipping our own schemas library so adding a secondary target framework isn't really what we want to do because if will also increase the size of our nugets and the idea behind netstandard2.1 is long term compatibility so I would expect FlatSharp to do the same. Isn't there a possibility to just disable these static interfaces otherwise we would be forced to use FlatSharp6 or stay with the Google library that we are currently using |
By a very small amount. The
FlatSharp does support
I'm a solo developer here, and I don't want to be in the business of maintaining and testing different builds of FlatSharp for every possible permutation of language features. Disabling static interfaces touches more than the codegen, since it also requires a new build of |
I understand its more a NuGet issue than a FlatSharp issue. As a developer its always tempting to use the latest language features like these static interfaces, but functional wise it doesn't add anything new. Anyway I will probably go for the duplicate targetframeworks for the time-being hoping that Microsoft will resolve this issue. Maybe we can create a defect out of this for the Roslyn project? |
@jamescourtney switching to multiple frameworks makes my tests pass, but it more or less breaks Visual Studio. When using this approach I get Ambiguous references erros in the IDE and it breaks things like refactoring options eg resolve usings. Maybe the Net7 code generation can be a FlatSharp compiler switch or attribute that is default on, but can be disabled in my case? |
Hi @njannink -- I've unintentionally discovered a solution for this problem. It's a little bit complicated, but will work. For the record, I continue to see this as a NuGet issue, but there is a way for you to reference Update your test csproj to contain the following: <!-- Define a dependency on FlatSharp.Runtime but don't take an assembly reference -->
<ItemGroup>
<PackageReference Include="FlatSharp.Runtime" Version="7.6.0" GeneratePathProperty="true" ExcludeAssets="all" />
</ItemGroup>
<!-- Take the assembly reference yourself so you can set the version -->
<ItemGroup>
<Reference Include="FlatSharp.Runtime">
<HintPath>$(PkgFlatSharp_Runtime)\lib\netstandard2.1\FlatSharp.Runtime.dll</HintPath>
<Private>true</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FlatSharp.Schemas\FlatSharp.Schemas.csproj" />
</ItemGroup> |
I'm trying to migrate from Google flatbuffers nuget to FlatSharp (7.1.1) and I run into a problem.
Situation
My netstandard2.0 project is compilated without issues, but when I try to run my unittest code I get the following exceptions:
System.TypeLoadException: Virtual static method 'get_LazySerializer' is not implemented on type 'xxx' from assembly 'yyy'.
I guess this has to do with Net7 the static definitions on interfaces, but in a mixed scenario that might not work?
The text was updated successfully, but these errors were encountered: