Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore the exception when unity is starting #691

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 41 additions & 7 deletions src/NuGetForUnity/Editor/UnityPreImportedLibraryResolver.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using JetBrains.Annotations;
@@ -82,8 +83,23 @@ private static HashSet<string> GetAlreadyImportedLibs()
#else
const AssembliesType assemblyType = AssembliesType.Player;
#endif
var projectAssemblies = CompilationPipeline.GetAssemblies(assemblyType)
.Where(playerAssembly => playerAssembly.flags != AssemblyFlags.EditorAssembly);
IEnumerable<Assembly> projectAssemblies;
var failedToGetAssembliesFromUnity = false;
try
{
projectAssemblies = CompilationPipeline.GetAssemblies(assemblyType)
.Where(playerAssembly => playerAssembly.flags != AssemblyFlags.EditorAssembly);
}
catch (Exception exception)
{
// ignore the 'Must set an output directory through SetCompileScriptsOutputDirectory before compiling'
// error that seems to happen if this method is called before unity is started completely
NugetLogger.LogVerbose(
"Failed to get assemblies from the compilation pipeline with error: {0}. We ignore the error and try it the next time.",
exception);
projectAssemblies = Array.Empty<Assembly>();
failedToGetAssembliesFromUnity = true;
}

// Collect all referenced assemblies but exclude all assemblies installed by NuGetForUnity.
var projectReferences = projectAssemblies.SelectMany(playerAssembly => playerAssembly.allReferences);
@@ -101,9 +117,20 @@ private static HashSet<string> GetAlreadyImportedLibs()
// the compiler / language is available by default
alreadyImportedLibs.Add("Microsoft.CSharp");

var editorOnlyAssemblies = CompilationPipeline.GetAssemblies(AssembliesType.Editor)
.Where(assembly => assembly.flags == AssemblyFlags.EditorAssembly)
.ToList();
IEnumerable<Assembly> editorOnlyAssemblies;
try
{
editorOnlyAssemblies = CompilationPipeline.GetAssemblies(AssembliesType.Editor)
.Where(assembly => assembly.flags == AssemblyFlags.EditorAssembly);
}
catch (Exception exception)
{
NugetLogger.LogVerbose(
"Failed to get assemblies from the compilation pipeline with error: {0}. We ignore the error and try it the next time.",
exception);
editorOnlyAssemblies = Array.Empty<Assembly>();
}

alreadyImportedEditorOnlyLibraries = new HashSet<string>();

// com.unity.visualscripting uses .net 4.8 so it implicitly has System.CodeDom
@@ -116,7 +143,14 @@ private static HashSet<string> GetAlreadyImportedLibs()
NugetLogger.LogVerbose("Already imported libs: {0}", string.Join(", ", alreadyImportedLibs));
NugetLogger.LogVerbose("Already imported editor only libraries: {0}", string.Join(", ", alreadyImportedEditorOnlyLibraries));

return alreadyImportedLibs;
var returnAlreadyImportedLibs = alreadyImportedLibs;
if (failedToGetAssembliesFromUnity)
{
// set to null so it is not cached -> we retry the next time this method is called
alreadyImportedLibs = null;
}

return returnAlreadyImportedLibs;
}
}
}

Unchanged files with check annotations Beta

{
// Mono doesn't have a Certificate Authority, so we have to provide all validation manually. Currently just accept anything.
// See here: http://stackoverflow.com/questions/4926676/mono-webrequest-fails-with-https
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;

Check warning on line 29 in src/NuGetForUnity/Editor/Helper/WebRequestHelper.cs

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

'ServicePointManager' is obsolete: 'WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead. Settings on ServicePointManager no longer affect SslStream or HttpClient.' (https://aka.ms/dotnet-warnings/SYSLIB0014)
try
{
#pragma warning disable SYSLIB0014 // Type or member is obsolete
return updates;
}
private static void CopyIsManuallyInstalled(List<INugetPackage> newPackages, ICollection<INugetPackage> packagesToUpdate)

Check warning on line 523 in src/NuGetForUnity/Editor/PackageSource/NugetPackageSourceV2.cs

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

Check warning on line 523 in src/NuGetForUnity/Editor/PackageSource/NugetPackageSourceV2.cs

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

Check warning on line 523 in src/NuGetForUnity/Editor/PackageSource/NugetPackageSourceV2.cs

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

{
foreach (var newPackage in newPackages)
{