Skip to content

Fix potential Serilog load error, enable debug logging into msbuild#40

Merged
Lordfirespeed merged 6 commits intoEvaisaDev:mainfrom
wherget:msbuild-task-improvements
Jun 22, 2024
Merged

Fix potential Serilog load error, enable debug logging into msbuild#40
Lordfirespeed merged 6 commits intoEvaisaDev:mainfrom
wherget:msbuild-task-improvements

Conversation

@wherget
Copy link
Contributor

@wherget wherget commented May 20, 2024

As is, Default.LoadFromAssemblyName may fail to load the Serilog dependency when using the MSBuild SDK, leading to exceptions like:

Sdk.targets(6,5): error : [15:53:41 FTL] Netcode patching failed! 
Sdk.targets(6,5): error : System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. 
Sdk.targets(6,5): error :    at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr) 
Sdk.targets(6,5): error :    at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
Sdk.targets(6,5): error :    at NetcodePatcher.MSBuild.NetcodePatchTask.<>c__DisplayClass32_0.<Execute>g__RunPatch|0(ITaskItem patchSpecifier) in /home/runner/work/UnityNetcodePatcher/UnityNetcodePatcher/NetcodePatcher.MSBuild.Tasks/NetcodePatchTask.cs:line 96 
Sdk.targets(6,5): error :    at NetcodePatcher.MSBuild.NetcodePatchTask.Execute() in /home/runner/work/UnityNetcodePatcher/UnityNetcodePatcher/NetcodePatcher.MSBuild.Tasks/NetcodePatchTask.cs:line 105 
Sdk.targets(6,5): error : Caused by: System.IO.FileNotFoundException: Could not load file or assembly 'Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10'. The system cannot find the file specified. 
Sdk.targets(6,5): error :  
Sdk.targets(6,5): error :    at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor) 
Sdk.targets(6,5): error :    at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr) 
Sdk.targets(6,5): error : Caused by: System.IO.FileNotFoundException: Could not load file or assembly 'Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10'. The system cannot find the file specified. 
Sdk.targets(6,5): error :  
Sdk.targets(6,5): error :    at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound) 
Sdk.targets(6,5): error :    at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName) 
Sdk.targets(6,5): error :    at NetcodePatcher.Tools.Common.PatcherLoadContext.Load(AssemblyName assemblyName) in /home/runner/work/UnityNetcodePatcher/UnityNetcodePatcher/NetcodePatcher.Tools.Common/PatcherLoadContext.cs:line 30 
Sdk.targets(6,5): error :    at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName) 
Sdk.targets(6,5): error :    at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName) 

This PR adds code to attempt to manually resolve the assembly from the PatcherCommonAssemblyDir before deferring to the Default Context.

Additionally it changes the LoggingConfiguarion for the MSBuild Task to also emit Debug messages. These are only shown when MSBuild'ing with verbosity detailed or higher anyway, but filtering them out in the Task leaves them completely inaccessible.

@wherget
Copy link
Contributor Author

wherget commented May 28, 2024

Would any of you mind having a look at this PR @EvaisaDev or @Lordfirespeed?
You can check my usage from the mentioned PR in LLL. If this is indeed an issue (and I'm not just weirdly holding it wrong, I feel like I can't be the first person to use the MSBuild patcher o.O), is this even the right way to go about fixing it?

@Lordfirespeed Lordfirespeed merged commit 3a46743 into EvaisaDev:main Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants