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

instantiating a DB instance fails for 3.2+ #1679

Open
tejs-code opened this issue Nov 18, 2024 · 4 comments
Open

instantiating a DB instance fails for 3.2+ #1679

tejs-code opened this issue Nov 18, 2024 · 4 comments

Comments

@tejs-code
Copy link

tejs-code commented Nov 18, 2024

Library Version

3.2.1

.NET Runtime

.Net 8

Operating System / Device Details

Windows 11 24H2

Details

I have a .net WPF project that uses couchbase and was attempting to upgrade it from 3.1.9 to 3.2.1 but creating the database object fails. The target framework for it is net8.0-windows10.0.19041.0.

Expected behavior

call to new Couchbase.Lite.Database("dbname") should succeed

Actual behavior

throws exception
System.InvalidOperationException: 'Operation is not valid due to the current state of the object.'

Callstack
[Exception] WinRT.Runtime.dll!WinRT.ExceptionHelpers.ThrowExceptionForHR.__Throw|38_0(int hr) Unknown
[Exception] WinRT.Runtime.dll!WinRT.ExceptionHelpers.ThrowExceptionForHR(int hr) Unknown
[Exception] Microsoft.Windows.SDK.NET.dll!ABI.Windows.Storage.IApplicationDataStaticsMethods.get_Current(WinRT.IObjectReference _obj) Unknown
[Exception] Microsoft.Windows.SDK.NET.dll!Windows.Storage.ApplicationData.Current.get() Unknown
[Exception] Couchbase.Lite.dll!Couchbase.Lite.Support.DefaultDirectoryResolver.DefaultDirectory() Unknown
[Exception] Couchbase.Lite.dll!Couchbase.Lite.DatabaseConfiguration.DatabaseConfiguration() Unknown

I don't see the error if the targetframework is just 'net8.0-windows'

In my case, I know what the directory I want to specify, so I init the DB using something like this
new Couchbase.Lite.Database(dbName, new Couchbase.Lite.DatabaseConfiguration() { Directory = directory });
_directory in DatabaseConfiguration could be made into a lazy eval to skip the logic completely unless a default is not provided.

Steps To Reproduce

  1. Create a blank WPF project
  2. Update target framework in csproj file to net8.0-windows10.0.19041.0
  3. add this line of code " var db = new Couchbase.Lite.Database("dbName");
  4. Run. Sample project attached.
    WpfApp1.zip
@borrrden
Copy link
Member

I suppose this is because WPF creates "unpackaged" apps right? I've only ever tested WinUI with packaged apps. I can probably change the evaluation to be lazy but it won't fix the underlying problem for most people. I wonder if there is a way to detect packaged vs unpackaged or if I should just try and catch the exception....

@borrrden
Copy link
Member

borrrden commented Nov 19, 2024

Opened CBL-6481 to address this.

@tejs-code
Copy link
Author

Yup. WPF by default runs as unpackaged, though it can be packaged as well.
https://learn.microsoft.com/en-us/windows/msix/detect-package-identity has some pointers on figuring out if the process is running as packaged.

Lazy eval would atleast bypass this exception when a default is already provided. I was unable to test out if anything else would break after since I couldn't get past DB init.

@borrrden
Copy link
Member

borrrden commented Nov 20, 2024

There is one thing that you can try doing to get unblocked. Since the default directory resolver is a public interface you could register your own implementation of Couchbase.Lite.DI.IDefaultDirectoryResolver via Couchbase.Lite.DI.Service.Register. I haven't tried doing that but I think it is set up to allow late registrations. It could return any old thing if you are not using it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants