I’m trying to write a FiveM resource in C#. Whole script setup will be done in Main.cs using Castle Windsor IoC framework. Now I managed to get it working on server side without any problems. However if I use the same approach on client side, I get the following error:
Override failure for Castle.MicroKernel.DefaultKernel:InitializeLifetimeService () over System.MarshalByRefObject:InitializeLifetimeService (). Override must be [SecurityCritical]
I tried setting in AssemblyInfo.cs, but it doesn’t help. [assembly: SecurityCritical]
Sample code of Main.cs (do note that I don’t even need to register anything in IoC for it to fail)
You’ll likely have to build existing libraries from source against the framework reference package since default metadata might be doing some things which aren’t supported in SL5 .NET API level.
Supposedly Castle Windsor supports .net 4.5 and Silverlight 5 ever since version 3.2
Or do you mean that FiveM artifact should be built?
E: I tried to build resource with 3.4.0 Windsor from NuGet, but it gives the same error.
In case of Autofac IoC framework error is following: System.MethodAccessException: Error verifying Autofac.Util.SequenceGenerator:GetNextUniqueSequence (): Method System.Threading.Interlocked:Read (long&) is not accessible at 0x0005
Thanks for the input! I tried to downgrade version to 3.2 and it produced the same error. The reason why I tried 3.4.0, was that it had the same major version, but more up to date library. I also tried to use Unity IoC framework. An old version of 2.0.0 didn’t crash the application. For the time being it seems that TypeScript with tsyringe is the way to go if you plan to write enterprise style resources in FiveM / RedM.
and it works with the code provided above. However upon class registration in container e.g.
var assembly = Assembly.GetExecutingAssembly();
foreach (Type type in assembly.GetTypes())
{
Debug.WriteLine(type.FullName); // this prints out all project files no system packages
}
// Register state machine
container.Register(
Classes
.FromAssembly(assembly)
.BasedOn<IZoneState>()
.WithService.FromInterface()
.LifestyleSingleton()
);
Results in
Exception loading assembly Client/bin/Debug/System.Windows: System.IO.FileNotFoundException: Unable to find the specified file