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

The type initializer for "Lucene.Net.Diagnostics.Debugging" threw an exception #889

Open
1 task done
Plexois37 opened this issue Nov 28, 2023 · 1 comment
Open
1 task done
Labels

Comments

@Plexois37
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I get the following Exception:

System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for "Lucene.Net.Diagnostics.Debugging" threw an exception.
Source=Lucene.Net
StackTrace:
at Lucene.Net.Store.BaseDirectory.SetLockFactory(LockFactory lockFactory)
at Lucene.Net.Store.FSDirectory.SetLockFactory(LockFactory lockFactory)
at Lucene.Net.Store.FSDirectory..ctor(DirectoryInfo path, LockFactory lockFactory)
at Lucene.Net.Store.MMapDirectory..ctor(DirectoryInfo path, LockFactory lockFactory, Int32 maxChunkSize)
at Lucene.Net.Store.MMapDirectory..ctor(DirectoryInfo path, LockFactory lockFactory)
at Lucene.Net.Store.MMapDirectory..ctor(DirectoryInfo path)
...

Inner Exception 1:
FileLoadException: Could not load file or assembly "Microsoft.Extensions.Configuration.Abstractions, Version=1.1.2.0, Culture=neutral,
PublicKeyToken=adb9793829ddae60" or one of its dependencies. The located assembly's manifest definition does not match the assembly referencen. (Exception from HRESULT: 0x80131040)

I'm using beta16 and .Net Framework 4.8.1

It happens when I try to open a directory:

_IndexPath = FSDirectory.Open(new DirectoryInfo(Path.GetFullPath(Path.Combine(indexRootPath, subDir))));
or
_IndexPath = new MMapDirectory(new DirectoryInfo(Path.GetFullPath(Path.Combine(indexRootPath, subDir))));

I tried Version 1.1.2 of Microsoft.Extensions.Configuration.Abstractions and Microsoft.Extensions.Configuration
but that didn't help.

I use several projects in my solution. I searched for "Microsoft.Extensions.Configuration.Abstractions.dll" and these are all instances that were found:
[0] {[D:\TestProgram\Index\IndexSearch\bin\Debug\Microsoft.Extensions.Configuration.Abstractions.dll, {Microsoft.Extensions.Configuration.Abstractions, Version=1.1.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60}]} System.Collections.Generic.KeyValuePair<string, System.Reflection.AssemblyName>
[1] {[D:\TestProgram\packages\Microsoft.Extensions.Configuration.Abstractions.1.1.2\lib\netstandard1.0\Microsoft.Extensions.Configuration.Abstractions.dll, {Microsoft.Extensions.Configuration.Abstractions, Version=1.1.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60}]} System.Collections.Generic.KeyValuePair<string, System.Reflection.AssemblyName>

Expected Behavior

_IndexPath = FSDirectory.Open(new DirectoryInfo(Path.GetFullPath(Path.Combine(indexRootPath, subDir))));
should open the directory instead of producing an exception

Steps To Reproduce

use beta16 and .Net Framework 4.8.1 (also happens with lower versions)

try to open a directory:
private FSDirectory _IndexPath;

_IndexPath = FSDirectory.Open(new DirectoryInfo(Path.GetFullPath(Path.Combine(indexRootPath, subDir))));
or
_IndexPath = new MMapDirectory(new DirectoryInfo(Path.GetFullPath(Path.Combine(indexRootPath, subDir))));

Exceptions (if any)

System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for "Lucene.Net.Diagnostics.Debugging" threw an exception.
Source=Lucene.Net
StackTrace:
at Lucene.Net.Store.BaseDirectory.SetLockFactory(LockFactory lockFactory)
at Lucene.Net.Store.FSDirectory.SetLockFactory(LockFactory lockFactory)
at Lucene.Net.Store.FSDirectory..ctor(DirectoryInfo path, LockFactory lockFactory)
at Lucene.Net.Store.MMapDirectory..ctor(DirectoryInfo path, LockFactory lockFactory, Int32 maxChunkSize)
at Lucene.Net.Store.MMapDirectory..ctor(DirectoryInfo path, LockFactory lockFactory)
at Lucene.Net.Store.MMapDirectory..ctor(DirectoryInfo path)
...

Inner Exception 1:
FileLoadException: Could not load file or assembly "Microsoft.Extensions.Configuration.Abstractions, Version=1.1.2.0, Culture=neutral,
PublicKeyToken=adb9793829ddae60" or one of its dependencies. The located assembly's manifest definition does not match the assembly referencen. (Exception from HRESULT: 0x80131040)

Lucene.NET Version

Lucene.Net 4.8.0-beta00016

.NET Version

.Net Framework 4.8.1 (also happens with lower versions)

Operating System

Windows 10

Anything else?

No response

@NightOwl888
Copy link
Contributor

This issue happens when you have a version conflict between the version of Microsoft.Extensions.Configuration.Abstractions that we target and other libraries in your project. Unfortunately, the version resolution on these older packages doesn't work well and manual fixup is often required when you pull in another dependency that depends on Microsoft.Extensions.Configuration.Abstractions or any of the other libraries in Microsoft.Extensions.Configuration.

The solution is to go through your project dependencies to determine the lowest version of Microsoft.Extensions.Configuration.Abstractions that can be targeted to resolve the conflict. You may use a higher version than this and it will work (in the master branch we are currently targeting 3.1.6, which seems to solve this).

You can then either add a direct reference to Microsoft.Extensions.Configuration.Abstractions and all of the other Microsoft.Extensions.Configuration packages to your project or use assembly binding redirects to do the same.

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

No branches or pull requests

2 participants