6

I'm receiving the following error in my WPF application:

Declaration referenced in a method implementation cannot be a final method.

And the only thing I have found states that the problem is that a non-virtual method is being overridden, but I checked and could not find any in my object.

The error is not thrown when compiling but only when I debug.

Does anyone have a suggestion that I might try?

-- UPDATE

I get the error in my App.Xaml.cs OnStartup override when calling:

var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new DirectoryCatalog(localDir));
_container = new CompositionContainer(catalog);

On the _container I receive 15 LoaderException after upgrading to CSLA 4.5.10.

Chrisjan Lodewyks
  • 1,162
  • 4
  • 13
  • 25

3 Answers3

13

Okay I have found my issue. I hope that posting it here might help someone else find the issue that I have been searching for so long.

In the code I have posted above the localDir points to a directory on my local machine where the projects are built to and then fetched with the MEF. The problem for me here was that there was a .dll to a different project that was still referencing an old version of CSLA and there Save(), was still being overridden although it is not allowed annymore.

So in short it was a .dll mismatch in my MEF directory, so be sure to check for something like that.

Hope this helps someone!

Chrisjan Lodewyks
  • 1,162
  • 4
  • 13
  • 25
0

This happened to me as well, I was running my tests and was getting the same error message.

The problem was that I had an updated nuget package in one of the projects and in the Test project that nuget package was outdated and therefor generating this issue.

Updating the packages in all the projects fixed the issue.

Fernando Moreira
  • 785
  • 4
  • 16
0

This generally occurs due to DLL contract mismatches. In DLL A you have a method

public void MyTestMethod() {}

but in DLL B you have:

public virtual void MyTestMethod() {}

Now it the application you have code which overrides the method:

public override void MyTestMethod() {}

Now your application is referencing DLL B, however a separate project dependency references DLL A.

This can be fixed by consolidating dlls or nuget packages between the projects so that the underlying code is the same

johnny 5
  • 19,893
  • 50
  • 121
  • 195