tzainten
tzainten
CC#
Created by tzainten on 1/4/2023 in #help
❔ Confused about Assembly.Load (Hotloading CSharp Assemblies)
I've also modified the host's code to look like this:
public static void Main()
{
try
{
FunctionLibrary.Module.Test = true;

Assembly userLibrary = LoadAssembly( @"W:\\Visual Studio 2022\\UserLibrary\\bin\\Debug\\net7.0\\UserLibrary.dll" );
Type? userModule = userLibrary.GetType( "MyLibrary.MyModule" );
MethodInfo entryPoint = userModule?.GetMethod( "OnStartup", BindingFlags.Static | BindingFlags.Public );
entryPoint.Invoke( null, null ); // Print out the value of FunctionLibrary.Module.Test, expected to == true
}
catch ( Exception ex )
{
Console.WriteLine( ex );
}
}
public static void Main()
{
try
{
FunctionLibrary.Module.Test = true;

Assembly userLibrary = LoadAssembly( @"W:\\Visual Studio 2022\\UserLibrary\\bin\\Debug\\net7.0\\UserLibrary.dll" );
Type? userModule = userLibrary.GetType( "MyLibrary.MyModule" );
MethodInfo entryPoint = userModule?.GetMethod( "OnStartup", BindingFlags.Static | BindingFlags.Public );
entryPoint.Invoke( null, null ); // Print out the value of FunctionLibrary.Module.Test, expected to == true
}
catch ( Exception ex )
{
Console.WriteLine( ex );
}
}
Which again, works if I just compile the host as a .exe and run it on it's own. But it does not work if I try compiling it as a .dll and loading it with HostFXR, it produces the error above.
9 replies
CC#
Created by tzainten on 1/4/2023 in #help
❔ Confused about Assembly.Load (Hotloading CSharp Assemblies)
Well what I'm doing is using the HostFXR API to host a C# runtime so I can interop with C++ functions. I've changed the project to output to a .exe just for testing purposes, and it prints out the expected result of "True". However, when I switch the project back to "Class Library" and try to load the library with HostFXR, it prints out this error:
"System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.IO.FileNotFoundException: Could not load file or assembly 'FunctionLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified."
"System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.IO.FileNotFoundException: Could not load file or assembly 'FunctionLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified."
9 replies
CC#
Created by tzainten on 1/4/2023 in #help
❔ Confused about Assembly.Load (Hotloading CSharp Assemblies)
Hmm alright. Is it possible to only have one instance of FunctionLibrary.dll and have everything reference that same instance?
9 replies