Upgrade issue from v 1.7.0.0 to v 1.7.2.0

Topics: General, Installing Orchard
Jun 25, 2014 at 9:11 PM
I am trying to update a sie from Orchard v1.7.0.0 to v1.7.2 and running into an error which is confusing. We have a custom module "AdvancedLucene" which extends the standard Orchard.Lucene module, compiles and runs fine with v1.7 but throws the following error when I try to launch v1.7.2 of framework. Method "WithinRange" is definitely implemented in the Services class. Exception message is below, followed by truncated C# class in question. Any help would be appreciated.

2014-06-19 09:49:08,671 [5] Orchard.Environment.Extensions.ExtensionManager - Error loading extension 'AdvancedLucene'
System.TypeLoadException: Method 'WithinRange' in type 'AdvancedLucene.Services.AdvancedLuceneSearchBuilder' from assembly 'AdvancedLucene, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()
at Orchard.Environment.Extensions.Loaders.PrecompiledExtensionLoader.LoadWorker(ExtensionDescriptor descriptor) in c:\Development\Websites\OrchardUpdate-1.7.2\src\Orchard\Environment\Extensions\Loaders\PrecompiledExtensionLoader.cs:line 232
at Orchard.Environment.Extensions.Loaders.ExtensionLoaderBase.Load(ExtensionDescriptor descriptor) in c:\Development\Websites\OrchardUpdate-1.7.2\src\Orchard\Environment\Extensions\Loaders\ExtensionLoaderBase.cs:line 37
at Orchard.Environment.Extensions.ExtensionManager.BuildEntry(ExtensionDescriptor descriptor) in c:\Development\Websites\OrchardUpdate-1.7.2\src\Orchard\Environment\Extensions\ExtensionManager.cs:line 160
at Orchard.Environment.Extensions.ExtensionManager.<>c__DisplayClass1c.<LoadFeature>b__16(AcquireContext1 ctx) in c:\Development\Websites\OrchardUpdate-1.7.2\src\Orchard\Environment\Extensions\ExtensionManager.cs:line 110
at Orchard.Caching.Cache
2.CreateEntry(TKey k, Func2 acquire) in c:\Development\Websites\OrchardUpdate-1.7.2\src\Orchard\Caching\Cache.cs:line 57
at Orchard.Caching.Cache
2.AddEntry(TKey k, Func2 acquire) in c:\Development\Websites\OrchardUpdate-1.7.2\src\Orchard\Caching\Cache.cs:line 27
at Orchard.Caching.Cache
2.<>c__DisplayClass2.<Get>b__0(TKey k) in c:\Development\Websites\OrchardUpdate-1.7.2\src\Orchard\Caching\Cache.cs:line 19
at System.Collections.Concurrent.ConcurrentDictionary2.AddOrUpdate(TKey key, Func2 addValueFactory, Func3 updateValueFactory)
at Orchard.Caching.Cache
2.Get(TKey key, Func2 acquire) in c:\Development\Websites\OrchardUpdate-1.7.2\src\Orchard\Caching\Cache.cs:line 17
at Orchard.Caching.DefaultCacheManager.Get[TKey,TResult](TKey key, Func
2 acquire) in c:\Development\Websites\OrchardUpdate-1.7.2\src\Orchard\Caching\DefaultCacheManager.cs:line 33
at Orchard.Environment.Extensions.ExtensionManager.LoadFeature(FeatureDescriptor featureDescriptor) in c:\Development\Websites\OrchardUpdate-1.7.2\src\Orchard\Environment\Extensions\ExtensionManager.cs:line 109

-----*
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using AdvancedLucene.Models;
using Lucene.Net.Index;
using Lucene.Net.Search;
using Lucene.Net.Store;
using Lucene.Net.Util;
using Orchard.Indexing;
using Orchard.Logging;
using Lucene.Net.Documents;
using Lucene.Net.QueryParsers;

namespace AdvancedLucene.Services
{
public class AdvancedLuceneSearchBuilder : ISearchBuilder {

    private const int MaxResults = Int16.MaxValue;

    private readonly Directory _directory;

    private readonly List<BooleanClause> _clauses;
    private readonly List<BooleanClause> _filters;
    private int _count;
    private int _skip;
    private string _sort;
    private int _comparer;
    private bool _sortDescending;
    private bool _asFilter;

    // pending clause attributes
    private Occur _occur;
    private bool _exactMatch;
    private float _boost;
    private Query _query;
    private bool _fuzzy;

    public ILogger Logger { get; set; }

    public AdvancedLuceneSearchBuilder(Directory directory) {
        _directory = directory;
        Logger = NullLogger.Instance;

        _count = MaxResults;
        _skip = 0;
        _clauses = new List<BooleanClause>();
        _filters = new List<BooleanClause>();
        _sort = String.Empty;
        _comparer = 0;
        _sortDescending = true;

        InitPendingClause();
    }

    public ISearchBuilder Parse(string defaultField, string query, bool escape) {
        return Parse(new[] {defaultField}, query, escape);
    }

    public ISearchBuilder Parse(string[] defaultFields, string query, bool escape) {
        if (defaultFields.Length == 0) {
            throw new ArgumentException("Default field can't be empty");
        }

        if (String.IsNullOrWhiteSpace(query)) {
            throw new ArgumentException("Query can't be empty");
        }

        if (escape) {
            query = QueryParser.Escape(query);
        }

        var analyzer = AdvancedLuceneIndexProvider.CreateAnalyzer();
        foreach (var defaultField in defaultFields) {
            CreatePendingClause();
            _query = new QueryParser(AdvancedLuceneIndexProvider.LuceneVersion, defaultField, analyzer).Parse(query);
        }

        return this;
    }

    public ISearchBuilder ParseFuzzy(string[] defaultFields, double[] fuzziness, string query, bool escape)
    {
        if (defaultFields.Length == 0)
        {
            throw new ArgumentException("Default field can't be empty");
        }

        if (String.IsNullOrWhiteSpace(query))
        {
            throw new ArgumentException("Query can't be empty");
        }

        if (escape)
        {
            query = QueryParser.Escape(query);
        }

        var analyzer = AdvancedLuceneIndexProvider.CreateAnalyzer();
        int i = 0;
        foreach (var defaultField in defaultFields)
        {
            CreatePendingClause();
            if(fuzziness[i] < 1)
                _query = new QueryParser(AdvancedLuceneIndexProvider.LuceneVersion, defaultField, analyzer).Parse(query + "~" + fuzziness[i]);
            else
                _query = new QueryParser(AdvancedLuceneIndexProvider.LuceneVersion, defaultField, analyzer).Parse(query);
            i++;
        }

        return this;
    }

    public ISearchBuilder WithField(string field, int value) {
        CreatePendingClause();
        _query = NumericRangeQuery.NewIntRange(field, value, value, true, true);
        return this;
    }

    public ISearchBuilder WithinRange(string field, int min, int max) {
        CreatePendingClause();
        _query = NumericRangeQuery.NewIntRange(field, min, max, true, true);
        return this;
    }

    public ISearchBuilder WithField(string field, double value) {
        CreatePendingClause();
        _query = NumericRangeQuery.NewDoubleRange(field, value, value, true, true);
        return this;
    }

    public ISearchBuilder WithinRange(string field, double min, double max) {
        CreatePendingClause();
        _query = NumericRangeQuery.NewDoubleRange(field, min, max, true, true);
        return this;
    }

    public ISearchBuilder WithField(string field, bool value) {
        return WithField(field, value ? 1 : 0);
    }

    public ISearchBuilder WithField(string field, DateTime value) {
        CreatePendingClause();
        _query = new TermQuery(new Term(field, DateTools.DateToString(value, DateTools.Resolution.MILLISECOND)));
        return this;
    }

    public ISearchBuilder WithinRange(string field, DateTime min, DateTime max) {
        CreatePendingClause();
        _query = new TermRangeQuery(field, DateTools.DateToString(min, DateTools.Resolution.MILLISECOND), DateTools.DateToString(max, DateTools.Resolution.MILLISECOND), true, true);
        return this;
    }

    public ISearchBuilder WithinRange(string field, string min, string max) {
        CreatePendingClause();
        _query = new TermRangeQuery(field, QueryParser.Escape(min.ToLower()), QueryParser.Escape(max.ToLower()), true, true);
        return this;
    }

    public ISearchBuilder WithField(string field, string value) {
        CreatePendingClause();

        if (!String.IsNullOrWhiteSpace(value)) {
            _query = new TermQuery(new Term(field, QueryParser.Escape(value.ToLower())));
        }

        return this;
    }

    public ISearchBuilder Mandatory() {
        _occur = Occur.MUST;
        return this;
    }

    public ISearchBuilder Forbidden() {
        _occur = Occur.MUST_NOT;
        return this;
    }

    public ISearchBuilder ExactMatch() {
        _exactMatch = true;
        return this;
    }

    public ISearchBuilder Weighted(float weight) {
        _boost = weight;
        return this;
    }

    private void InitPendingClause() {
        _occur = Occur.SHOULD;
        _exactMatch = false;
        _query = null;
        _boost = 0;
        _asFilter = false;
        _sort = String.Empty;
        _comparer = 0;
        _fuzzy = false;
    }

    private void CreatePendingClause() {
        if (_query == null) {
            return;
        }

        // comparing floating-point numbers using an epsilon value
        const double epsilon = 0.001;
        if (Math.Abs(_boost - 0) > epsilon) {
            _query.Boost = _boost;
        }
Jul 7, 2014 at 7:06 PM
Solved by adding additional method imlementations for more overloads of WithinRange method in ISearchBuilder. It is silly but exactly what the compiler complained about.
Marked as answer by cinnaman on 7/7/2014 at 11:06 AM