C# project adding dll have error.

#1
Hi there. CE 5.4. Trying add to my C# project some packages Reactive Extension. And i always have error like:

Code: Select all

System.IO.FileNotFoundException: Could not load file or assembly 'System.Reactive.Linq, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263' or one of its dependencies. File name: 'System.Reactive.Linq, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263'
I tried search about this issue in Reactive forums but didn't help. May be in Cry projects there is no way to add some other packages

Re: C# project adding dll have error.

#4
add exe another dll search path at runtime.

Code: Select all

class MypluginClass{ static MyPluginClass() { string currentPath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Process); string dllPath = Environment.CurrentDirectory + Path.DirectorySeparatorChar + "Assets" + Path.DirectorySeparatorChar + "Plugins"; if(currentPath.Contains(dllPath) == false) { Environment.SetEnvironmentVariable("PATH", currentPath + Path.PathSeparator + dllPath, EnvironmentVariableTarget.Process); } } } } //END YOUR CODE uint id = 0; void Start () { MyPluginClass plug = new MyPluginClass (); //So instantiate a call to your class which calls the constructor automagically id = SS.uStart (); //static dll function calls. }

Re: C# project adding dll have error.

#9
I would like to raise this topic again, because the team I working in has just got into similar problem.

I don't see actual solution in the above comments, and the latest post by the topic starter is unfortunately rather confusing to me -
Finally understood how make this work. I thought that this dlls i should place in folder with project, BUT all dlls must be placed in bin/win_64/ (couse im working on this platform) folder of EDITOR not project


To elaborate on the issue again:
We are using CryEngine 5.4, and working on a C# game plugin.
Recently we had a need to add another C# dll as a dependency (reference) to our plugin. That dll is a 3rd party utility library, not directly related to CryEngine.
When launching the game it crashes at startup, and following error may be found in the log:

Code: Select all

System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded. at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (System.Reflection.Assembly,bool) at System.Reflection.Assembly.GetTypes () [0x00000] in C:\j\workspace\v\repos\mono\mcs\class\corlib\System.Reflection\Assembly.cs:402 at CryEngine.Engine.ScanAssembly (System.Reflection.Assembly assembly) [0x00006] in D:\jk\gamesdk_release\Code\CryManaged\CESharp\Core\Engine.cs:121
Moving ahead, I linked another random C# DLL to the project for a test, and it gives different error, similar to the one that topic starter had (noted in the first post):

Code: Select all

System.IO.FileNotFoundException: Could not load file or assembly '<Random Library Name>, Version=3.4.2.1, Culture=neutral, PublicKeyToken=null' or one of its dependencies. File name: '<Random Library Name>, Version=3.4.2.1, Culture=neutral, PublicKeyToken=null' at CryEngine.Projects.Game.Game.Initialize () [0x00019] in <filename unknown>:0 at CryEngine.Projects.Game.MyPlugin.Initialize () [0x00019] in <filename unknown>:0

The difference in errors may be related to how and when the contents of DLLs are used (whether we use a variable of some type, or simply put "using namespace" somewhere), but that's only my guess.


So, we did some research, and found that when game is launched, CryEngine copies C# plugins to the temporary folder, located at C:\Users\<Username>\AppData\Local\Temp\CE_ManagedBinaries.
We found, that if we manually copy the new dependencies there, then the game runs successfully, which hints that engine expects to find these dlls there, instead of the game's bin folder.

My question is this: what is the correct way to add dependencies to the C# plugins when working with Cry project, and what we may be missing or doing wrong (project configuration, or else)?

Almost forgot, I tried using a solution mentioned above, one with SetEnvironmentVariable("PATH"), but it did not work for me (or maybe I don't use it correctly...).

Re: C# project adding dll have error.

#10
Have you tried adding your 3rd party plugin to the plugins section in the project file yet? Just open the .cryproject file with a text editor like Notepad++ or Visual Studio Code and add the plugin like this:

Code: Select all

[...]
"plugins": [
{ "type": "EPluginType::Native", "path": "CryDefaultEntities" },
{ "type": "EPluginType::Native", "path": "CrySensorSystem" },
{ "type": "EPluginType::Native", "path": "CryPerceptionSystem" },
{ "type": "EPluginType::Managed", "path": "bin/Game.dll" },
{
"type": "EPluginType::Native",
"path": "CryGamePlatform",
"platforms": [ "PS4" ]
},
{ "type": "EPluginType::Managed", "path": "bin/MyThirdPartyPlugin.dll" }
]
[...]
Make sure the .dll file is located in the bin folder and the engine should copy it over to the temporary directory for you.

Who is online

Users browsing this forum: No registered users and 1 guest