machinelearning
machinelearning copied to clipboard
System.Threading.ThreadAbortException: "System error."
System information
- Win10 V.1909:
- 5.0.101:
Issue
- What did you do? The model is embedded as a resource in the singe file build and gets extracted to the user's temp directory. For the use in the ConsumerModel (here: RLNModel)
- What happened? At the execution of the model,
- What did you expect? To run like before, when the model is in the directory of the executable. Accessed over Directory.GetCurrentDirectory() + "RLN.zip";
Source code / logs
System.Threading.ThreadAbortException
HResult=0x80131530
Message=System error.
Source=System.Private.CoreLib
StackTrace:
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Microsoft.ML.Runtime.ComponentCatalog.LoadableClassInfo.CreateInstanceCore(Object[] ctorArgs)
at Microsoft.ML.Runtime.ComponentCatalog.LoadableClassInfo.CreateInstance(IHostEnvironment env, Object args, Object[] extra)
at Microsoft.ML.Runtime.ComponentCatalog.TryCreateInstance[TRes](IHostEnvironment env, Type signatureType, TRes& result, String name, String options, Object[] extra)
at Microsoft.ML.Runtime.ComponentCatalog.TryCreateInstance[TRes,TSig](IHostEnvironment env, TRes& result, String name, String options, Object[] extra)
at Microsoft.ML.ModelLoadContext.TryLoadModelCore[TRes,TSig](IHostEnvironment env, TRes& result, Object[] extra)
at Microsoft.ML.ModelLoadContext.TryLoadModel[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, Entry ent, String dir, Object[] extra)
at Microsoft.ML.ModelLoadContext.LoadModel[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, Entry ent, String dir, Object[] extra)
at Microsoft.ML.ModelLoadContext.LoadModelOrNull[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, String dir, Object[] extra)
at Microsoft.ML.ModelLoadContext.LoadModel[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, String dir, Object[] extra)
at Microsoft.ML.ModelOperationsCatalog.Load(Stream stream, DataViewSchema& inputSchema)
at Microsoft.ML.ModelOperationsCatalog.Load(String filePath, DataViewSchema& inputSchema)
at ****.****.BaseProcessor.RLNModel.RLNModel.CreatePredictionEngine() in C:\Users\hoffm\source\repos\****:****\****.*****.BaseProcessor\RLNModel.cs:line 29
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Please paste or attach the code or logs or traces that would be helpful to diagnose the issue you are reporting.
public class RLNModel
{
private static Lazy<PredictionEngine<ModelInput, ModelOutput>> PredictionEngine = new Lazy<PredictionEngine<ModelInput, ModelOutput>>(CreatePredictionEngine);
public static string _modelFile;
public static ModelOutput Predict(ModelInput input)
{
ModelOutput result = PredictionEngine.Value.Predict(input); // Throws here ################
return result;
}
public static PredictionEngine<ModelInput, ModelOutput> CreatePredictionEngine()
{
MLContext mlContext = new MLContext();
string userTempPath = Path.GetTempPath();
string extractedModelsPath = userTempPath + "****.****.BaseProcessor\\";
var fileDir = extractedModelsPath + "****.****.BaseProcessor.RLN.zip";
ITransformer mlModel = mlContext.Model.Load(fileDir, out var modelInputSchema); # Line 29
var predEngine = mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(mlModel);
return predEngine;
}
}
Hi CreedsCode, is there a way for you to verify that the extraction finishes before the model loaded?
For anyone else arriving from Google: I wasn't actually seeing this with ML.Net at all, but I was seeing it in a different situation with Lazy and only in debug mode, and only when certain breakpoints are set. Seems like Lazy will throw ThreadAbortException when attempting to access the Value in debug mode sometimes.