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

Mocking classes doesn`t work #773

Closed
qbunia opened this issue Mar 5, 2019 · 4 comments
Closed

Mocking classes doesn`t work #773

qbunia opened this issue Mar 5, 2019 · 4 comments

Comments

@qbunia
Copy link

qbunia commented Mar 5, 2019

I cannot mock class because I got follow errors:

System.TypeInitializationException
The type initializer for 'Moq.ProxyFactory' threw an exception.
   at Moq.ProxyFactory.get_Instance()
   at Moq.Mock`1.InitializeInstancePexProtected() in C:\projects\moq4\src\Moq\Mock.Generic.cs:line 258
   at Moq.PexProtector.Invoke(Action action) in C:\projects\moq4\src\Moq\PexProtector.cs:line 21
   at Moq.Mock`1.InitializeInstance() in C:\projects\moq4\src\Moq\Mock.Generic.cs:line 228
   at Moq.Mock`1.OnGetObject() in C:\projects\moq4\src\Moq\Mock.Generic.cs:line 277
   at Moq.Mock.get_Object() in C:\projects\moq4\src\Moq\Mock.cs:line 151
   at Moq.Mock`1.get_Object() in C:\projects\moq4\src\Moq\Mock.Generic.cs:line 208
   at Moq.Mock.Of[T]() in C:\projects\moq4\src\Moq\Linq\Mock.cs:line 31
   at Tests.Db.when_extracting_icd10_from_excel_file_and_putting_it_into_database.<>c.<.ctor>b__5_0() in C:\Users\Me\Desktop\DoctorsOfficeGit\Tests\Db\ExtractingICD10FromExcelTest.cs:line 45

System.TypeInitializationException
The type initializer for 'Moq.CastleProxyFactory' threw an exception.
   at Moq.CastleProxyFactory..ctor()
   at Moq.ProxyFactory..cctor() in C:\projects\moq4\src\Moq\ProxyFactories\ProxyFactory.cs:line 14

System.TypeLoadException
Could not load type 'Castle.DynamicProxy.Generators.AttributesToAvoidReplicating' from assembly 'Castle.Core, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc'.
   at Moq.CastleProxyFactory..cctor()

Moq: 4.10.1
CastleCore 4.3.1

@stakx
Copy link
Contributor

stakx commented Mar 5, 2019

What does the class that you're trying to mock look like?

Could not load type 'Castle.DynamicProxy.Generators.AttributesToAvoidReplicating' from assembly 'Castle.Core, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc'.

At first glance, that assembly version looks suspicious. Do you have any assembly binding redirects configured for Castle.Core?

@stakx
Copy link
Contributor

stakx commented Mar 5, 2019

At first glance, that assembly version looks suspicious.

Yep, confirmed: Castle.Core 4.3.1 has an assembly version of 4.0.0.0 and your project is trying to load 1.0.3.0, so it appears to be misconfigured (e.g. with a bad assembly reference in your .csproj or a bad assembly binding redirect in App.config), or you have a bad Castle.Core assembly lying around somewhere—check your project's obj and bin directories, and any relevant caches such as your GAC, NuGet package cache, package fallback folder, etc, ASP.NET assembly shadow copy location.

However that may be, there's nothing wrong with Moq, so I'll close this issue.

@stakx stakx closed this as completed Mar 5, 2019
@qbunia
Copy link
Author

qbunia commented Mar 5, 2019

Got this in my csproj.

    <Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
      <HintPath>..\packages\Castle.Core.4.3.1\lib\net45\Castle.Core.dll</HintPath>
    </Reference>

My App.config is plain new and doesn`t have any binding redirect. The issue still occurs.

@deonclaassens
Copy link

deonclaassens commented Mar 7, 2019 via email

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

3 participants