TypeLoadException after loading .NET 4.5 C# DLL into Unity 2018.2.5 - unity3d

I want to be able to feed the camera frames from a webcam into Unity. I made a .NET 4.5 C# DLL using MediaFrameReader and event listeners. Here is some other user's implementation for accessing the Hololens camera frames: Hololens - Access Camera Frames.
When I import the DLL into my 2018.2.5 Unity project, it gives me the following error:
Unloading broken assembly "....", this assembly can cause crashes in the runtime
TypeLoadException: Could not find method due to a type load error
The C# plugin built successfully many times on Visual Studio. Also, I have properly set the Api Compatibility Level (in player settings) to .NET 4.x. What could be the fix to this?
All the other SO answers related to this I have already taken a look, but does not seem to help the problem. Thanks for all the help.
EDIT: https://issuetracker.unity3d.com/issues/unity-fails-to-load-net-4-dot-6-assemblies-with-typeloadexception is the most relatable post, but had no solution.

I have few possible solutions for you to explore.
DLLs issues:
Workaround:
Comment your UWP code (the part that uses the DLL), then build it in UNITY without the DLL. In the generated UWP solution, install the package from nuget or manually import the dll, then uncomment your code and finish your development. This is a short-term solution.It is going to be annoying as you re-build your solution many times and have to comment/uncomment then re-add dlls and so on.
Other possible solutions:
Failed to run reference rewriter with command error with unity error when adding a DLL to the assets folder
Your exact need
From your description, you really do not need everything in the link you referenced (Hololens - Access Camera Frames). You need much simpler version. I recently created MediaCapture solution for HoloLens as a workaround because PhotoCapture in Unity is not working in the HoloLens and everything is working without any additional DLLs. I will post for you few links to see if it may help you:
MediaCapture Unity & HoloLens: https://github.com/MSAlshair/HoloLensMediaCapture
This maybe a good start for you. You can combine it with your original reference. Use this project as starting point to make sure your project is building correct, then use the necessary code from the other resource that you posted to accomplish the task that you desire. You may need to download Unity 2018.2.12f1 because I didn't test it in 2018.2.5
MediaCapture & PhotoCapture: Hololens font camera
Good Luck!

Related

How do I export a steam game into a unity package

I've been wanting to mod hollow knight for a while now and since I have recently gained experience with the unity game engine I thought I would try it out. The only problem is I can't really find a way to export the files into unity and so far have found no tutorials online maybe exporting it into a package is not the answer so I'm just curious on how to import the files into unity.
That's not really how game modding works. You won't be able to import the compiled game's assets into Unity. If the game uses the Mono runtime (not IL2CPP), you can find the DLL files that contain the game's logic, decompile them (using a decompiler like dotPeek), make modifications to the game's source code (for example, adding your own logic to change behavior and load additional assets), recompile the code, and replace the game's original DLLs with your modified version.

How to integrate xBim in Unity?

I have installed xBim using NuGet for unity, and it is working well until I try to use the GeometryEngine to create 3D shapes:
using (IfcStore model = IfcStore.Open(filename, null))
{
var context = new Xbim3DModelContext(model);
context.CreateContext();
}
context.CreateContext(); causes an error. At first I got:
FileNotFoundException: Could not load file or assembly 'Xbim.Geometry.Engine.dll' or one of its dependencies
Which is a bit strange since I did install the geometry engine in NuGet, but then I tried to compile the DLLs for the github project here:
https://github.com/xBimTeam/XbimGeometry
And copied them into the plugins folder. Now I do not get any error message, but Unity will crash to desktop on execution of context.CreateContext();
I have been searching online, but have been unable to find any workaround. Any suggestions are appreciated.
I don't have the answer (currently also trying to use xBim in Unity), but what I found looking throught the topics listed here:
https://github.com/xBimTeam/XbimGeometry/issues?utf8=%E2%9C%93&q=unity+
is that there is not direct solution for this. The workaround, mentioned in a couple of places, is to make the conversion from .ifc to .weBIM in an small external .NET support program. See this:
https://github.com/xBimTeam/XbimGeometry/issues/109
Hope this somewhat helps. If you have another solution I would like to hear it.

Is it possible to navigate to assemblies definitions inside Visual Studio Code

I'm using VS Code several days as MonoDevelop replacement in Unity3D on Mac OS. I installed mono via homebrew as suggested to let VS Code to parse system assemblies. Everything works almost great, but I can't navigate definitions that are not part of my code. For example I can't go to definition of System.String or UnityEngine.Vector3 to see methods signatures. MonoDevelop has Assembly browser but I miss it in VS Code. Does anybody know if VS Code has such feature? Maybe I need to setup something for that?
PS: I've posted feature request. If you're interested in this feature vote for it, please.
https://visualstudio.uservoice.com/forums/293070-visual-studio-code/suggestions/14698887-implement-net-assembly-browser
It seems VS Code now can do that with the new extension ms-vscode for C# support. Previously it was recommended to use Legacy C# Support for Unity3D. I don't know exactly if this recommendation is still valid, but I tried to uninstall legacy and to install normal one. After some background work OmniSharp parsed my files and now it can open classes from assemblies! Look at this picture, it has open AnimationCurve class as [metadata]!
I'm trying it with Unity3D 5.5.0b2 beta now, so I'm not sure if this will work with production release of Unity3D. By the way I also removed VSCode plugin from dotBunny out of project as Unity3D 5.5 supports Visual Studio Code self.

React Native with Unity

Does anyone have any experience combining React Native and Unity? I'm looking to start a Unity project that's very UI Heavy and I'm thinking about using React Native to take advantage of its UI capabilities on mobile and web.
I'm curious what the workflow for such an approach would be.
Finally after a lot of trials managed to do this. These are the steps.
1) Using this link, export android project for Gradle.
Select Gradle in the Build Settings window and check the Export Project checkbox.
Click Export and select the destination folder.
2) Import the generated folder in Android studio. Select ok whenever prompted. In this process, you will encounter following issues
2a) Gradle Sync Failed due to org.gradle.api.internal.tasks issues. Resolve using this link
3) Create React Native App using this link
4) Start Integrating Android exported folder inside created react native app using this link. Don't upgrade Gradle as Android studio will ask you again and again. You will encounter following issues. Don't go through "Test Integration" until you are finished with #5 here.
4a) While configuring maven, use this url for maven url "$rootDir/../node_modules/react-native/android" .
4b) While configuring maven, if you encounter problem related to javax.inject:javax.inject". Use this link.
4c) You may also encounter this error "Conflict with dependency 'com.google.code.findbugs:jsr305'". You can solve this link.
4d) During Code integration section of this link, focus on the following section: If you are using a starter kit for React Native, replace the "HelloWorld" string with the one in your index.android.js file (it’s the first argument to the AppRegistry.registerComponent() method). Here you have to replace with project name.
5) Before going through "Test your Integration" section, you have to add code to call MyReactActivity from UnityActivity. This link will help.
6) Go through "Test your Integration" section of link provided in #4. You may encounter following problems.
6a) unable to load script from assets index.android.bundle. Use this link.
6b) could not connect to development server on android. Use this link.
Check my article on Medium
I've shown with an example on How to integrate react native with Unity 3D step by step. My aim was to use the react native within the Unity3D like a module which is quite convenient if you're gonna heavily work on Unity 3D. Hope this helps for someone who comes here later.
I'm unsure as how a Unity game is built for iOS, if it uses Cocoa Touch for rendering its core classes.
If it does, and you have access or ability to render a UIViewController then you can render your React Native application. The only thing you would have to facilitate is setting up communication between the two applications.
Here is an example of rendering a native UI Component inside a React Native app that may help. http://moduscreate.com/leverage-existing-ios-views-react-native-app/
I was curious as well, and created an example project of how to do this for Android: https://github.com/marijnz/unity-react.
If this is a viable option, at least depends on:
How long the project will be running, both React and Unity have to be updated and this gets probably tougher over time.
The amount of sdk's/dependencies the project has.
If you want to do iOS as well.
In general, I'd probably avoid going this way.
Even though the example seems pretty simple now, it was a pain to get to that (as Shaunak's answer already hints at ;))

Find out why Xcode has decided to link to a particular library

I'm using the Unity 3D engine to build an iPhone app, and when I go to generate my Xcode project for compilation, it includes a few fairly large libraries: Mono.Security.dll.s, System.dll.s, System.Core.dll.s, etc.
I don't know if this question is really an Xcode question or a Unity question, but I'm trying to figure out why each of those libraries is being linked - which functions / classes are being referenced - ideally so that I can rewrite my code to remove as many of the dependencies as possible. Does anybody know a way to find this information out?
Are you using any external assemblies? If so you should get the source code for them and check what they are including. Sometimes it's possible to disable stuff in external assemblies to remove unneeded dependencies.
Go into the "project settings->player" menu in Unity and make sure that stripping level is set as high as possible. Stripping will attempt to swap System.Core with mscorlib, which doesn't include stuff like Linq.
A way to find out why a particular assembly is being included is to open up the references section of your MonoDevelop solution, and double-click on an assembly. This will open the assembly browser and you'll be able to get an idea of the namespaces that depend on a particular assembly.
This DLL stuff is added to project by Unity3D, Xcode has nothing to do with this. What version of Unity3D do you use? Try to tweak Optimization options in project settings (Inspector), especially 'Stripping'.