Access denied when loading sentis model

Hello! I am dealing with an issue with my app. I basically can’t load my sentis model in specific conditions.

When I install and run the app in a protected folder such as Program Files, programs don’t have write access by default which makes sense. So I noticed my sentis model isn’t being loaded since its access is denied by Windows. But if I launch the app in Unity or in a folder with more access such as the Download folder, I don’t have this issue and everything is working perfectly. FYI, my sentis model is located in the StreamingAssets and is being loaded like so:

ModelLoader.Load(Path.Combine(Application.streamingAssetsPath, ModelName + ".sentis"))

I tried to investigate and I realized Sentis is loading the model like so:

    public static Model Load(string path)
    {
        using var fileStream = File.Open(path, FileMode.Open);
        return Load(fileStream);
    }

And then calls this:

public static FileStream Open(string path, FileMode mode)
{
    return Open(path, mode, (mode == FileMode.Append) ? FileAccess.Write : FileAccess.ReadWrite, FileShare.None);
}

Since we call File.Open with filemode=FileMode.Open, then fileAccess=FileAccess.ReadWrite. I don’t understand why Write access is required to read the file.

Unless I’m completely wrong, am I missing something ?

I can’t really get over this issue unless I run the app as admin.

Thank you in advance,
Matteo

I already found a solution to this problem but I think it’s more of a hack than a fix.

I replaced ModelLoader.Load(Path.Combine(Application.streamingAssetsPath, ModelName + ".sentis")) with ModelLoader.Load(File.OpenRead(Path.Combine(Application.streamingAssetsPath, ModelName + ".sentis")))

Instead of loading the model with the path, I manually open the model file through a Read-Only Filestream and then I can use it to load the model.

It feels more like a hack than a solution so I’m leaving the bug report as unsolved until I get an answer from a dev.

Thank you, we will take a look.

1 Like

Thank you for noticing this! We will change File.OpenRead.

1 Like