System.TypeLoadException
Asked Answered
A

3

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.

Allan answered 1/3, 2013 at 10:20 Comment(6)
Looks like a type generation happens somewhere in your or 3rd party code. Do you use any IoC- or DI-containers, ORM frameworks, which requires proxy types generation?Foggy
And CSLA with .net framework 4.5.Allan
Are you using AOP with CSLA, especially on non-virtual methods and/or properties?Foggy
In what context is this occurring? During a data portal call? During data binding? During data access?Arlyn
I have updated my question, please check there.Allan
when I use this with Nhibernate reason for this error, I declared entity properties not virtual, making them virtual fixes the errorMunniks
A
14

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!

Allan answered 5/3, 2013 at 7:30 Comment(0)
B
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.

Brout answered 9/6, 2017 at 8:39 Comment(0)
R
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

Reames answered 24/3, 2023 at 14:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.