NetFabric/NetFabric.Hyperlinq

unity engine throws error, can be fody or too high .net version not sure

Closed this issue ยท 12 comments

Unity engine throws error

"Unloading broken assembly Assets/Plugins/NetFabric.Hyperlinq.dll, this assembly can cause crashes in the runtime"

Not sure, what the reason. it can be fody or too high .net version.

Old hyperlinq version dll did work with Unity3d without errors, not sure which version it was but i can upload it
NetFabric.Hyperlinq-master.zip

Hi @friuns2

To build the project, follow theses steps:

  • You don't have the latest version. Please pull the latest commit.
  • Fody is used to automatically add methods to existing classes. Intellisense uses the base code and not the generated assembly so, it won't find the added methods. Unfortunately, this means you have to use command line to run unit tests and benchmarks:
    • Open your favorite shell on the base folder of the project. Execute the command: dotnet build -c Release. This compiles all projects in the solution by the correct order.
    • To perform the unit tests, move into the NetFabric.Hyperlinq.UnitTests folder and execute the command: dotnet test - Release. This executes the tests for all target platforms, currently: net461 and netcoreapp2.1.
    • To perform the benchmarks, move into the NetFabric.Hyperlinq.Benchmarks folder and execute the command: dotnet run -c Release. Select from the menu the benchmark to run.

ok I will try to build it maybe it helps

Hi again @friuns2

I was reading once more your issue description and, I'm very sorry to say that I got it all wrong. ๐Ÿ˜ฒ
You are using Unity. Are you adding the assembly to the project or the source code?
Because of Fody, I don't think adding the source code will work.
Add the assembly instead. Use "nuget for Unity": https://assetstore.unity.com/packages/tools/utilities/nuget-for-unity-104640
Get the latest version of the NetFabric. Hyperlink package. Currently is 3.0.0-beta5. You need to allow preview versions.

sorry i was tired when i was writing it so had to edit and make more readable it latter :D

yes it was dll, now i installed through nuget for Unity but still getting same error.
Unloading broken assembly Assets/Packages/NetFabric.Hyperlinq.3.0.0-beta5/lib/net461/NetFabric.Hyperlinq.dll, this assembly can cause crashes in the runtime

Sorry but can only test that next week.

Hi, i updated unity to 2019.2, there now more informative error message
Error: Could not load signature of NetFabric.Hyperlinq.DictionaryBindings:Count due to: Invalid generic method parameter index 2, max index is 2 assembly:NetFabric.Hyperlinq type:<unknown type> member:(null) signature:<none>

Sorry for taking so long. I can now reproduce the same error message. Unfortunately the message is not very helpful. Dictionary bindings and the Count() implementations are generated directly by the compiler. These don't involve Fody.
Still, I tested with an assembly version where Fody was not used and no issues were found. ๐Ÿ˜ฐ
I'll have to dig deeper into the generated code.

Hi @friuns2
Sorry once again for the long silence. I want to assure you that I haven't forgotten about this issue.
I have done multiple refactorings to the Fody weaver with no success. Somehow, Unity is more strict loading assemblies than others.
For now, Unity won't be supported but I'll keep researching alternatives.

ah ok Thanks for trying, no hurry i will use linq for now.

i checked on new unity now it gives different error

Assembly 'Assets/NetFabric.Hyperlinq.dll' will not be loaded due to errors:
Unable to resolve reference 'NetFabric.Hyperlinq.Interfaces'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.

@friuns2 Finally I have a version that works on Unity!...

In case you are still willing to try, the easiest way to add it to a Unity project is by using NuGetForUnity. Add then the NetFabric.Hyperlinq 3.0.0-beta7 package. Follow then the instruction on how to use it instead of LINQ.

Let me explain why it took 5 months...

To avoid allocations on the heap, I'm using generic constraints. That means that the type of enumerator has to be passed as a generic parameter on every method call. This would not be acceptable so I was writing non-generic methods on every enumerable calling the generic versions, to allow composition just like when using LINQ. This is next to exponential and very error prone.

The best solution is to have a source generator that automatically performs that for me. I had previously contributed to the development of a Fody weaver so I decided to write a new one for this task. The methods to be generated have to handle a lot of generics mapping and the rules ended up a lot more complex than I thought. Fody uses Mono.Cecil which requires the generation of IL directly. This is very powerful but can easily generate invalid assemblies. Unity seems to be more strict and was complaining much more than my unit testing and benchmarking projects.

After many attempts, and thoughts of giving up, I found Uno.SourceGeneration. This allows the generation of C# source code before the compilation of the project. This generated code is easier to read than IL and the compiler gives me much more helpful error messages. It took me a while to get the mapping rules to work but, here it is.

In between, I fixed many bugs, added more operators and added support for async streams and Span<T>. This last one is still not supported on Unity.

There is still some work to be done before I can call it version 3.0. Just a few more operators for async streams and improve the unit testing coverage.

Thank you for you patience and I hope it's been worth the wait...

Hi Thanks! i tested on unity 2019 no errors