PostSharp.Sdk.CodeModel.BindingException - postsharp

When compiling my project, which is having a Postsharp aspect (OnMethodBoundaryAspect) getting the error as
"Unhandled exception (4.0.41.0, 32 bit, CLR 4.5, Release): PostSharp.Sdk.CodeModel.BindingException: Cannot get the reflection object".
But this error message appears only on few machines, and the same project file is compiling successfully on most of the other machines.
I am using Visual studio 2013 and .net framework 4.5.
Postsharp dll version is 4.0.41
Please suggest the possible reason for this or any fix for this.
Thank you

<dependentAssembly>
<assemblyIdentity name="PostSharp"
publicKeyToken="b13fd38b8f9c99d7"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.39.0"
newVersion="4.0.39.0" />
</dependentAssembly>
app.config is the first place I would look for errors of this nature. Make sure the references are correct.
Unfortunately though, I still get this error i some cases that I can't discover why yet.

Related

Impossible to migrate the "System.Directory.Services.Protocols" dll from version "4.0.0" to "5.0.1" with nuget (.net framework 4.8)

I have a project that uses the "System.Directory.Services.Protocols" dll which is in version 4.0 and references the framework:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.DirectoryServices.Protocols.dll.
I want to update the dll because there is a security hole in 5.0.0 fixed in 5.0.1.
But when I update with nuget (after removing the reference from my project), everything goes correctly (I don't get any error) but the referenced dll is still the one from framework 4.8.
I tried to reference it manually by adding it from the "net-standard 2.0" package directory
Packages\System.DirectoryServices.Protocols.5.0.1\lib
| net45\ <empty>
| netstandard2.0\System.DirectoryServices.Protocols.dll
but it doesn't work any better.
I thought the 4.8 framework was compatible with .net standard 2.0, so why doesn't it select this dll?
Encountered the same issue with fx4.8 and System.Directory.Services.Protocols nuget package version 6.0.1.
I think the problem is the incorrect package.
Try to bind version using app.config, for example:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.DirectoryServices.Protocols" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.1" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

Nunit3 shows System.AggregateException from an assembly that does not exist with that version

This is the error:
Message: System.AggregateException : One or more errors occurred.
----> System.IO.FileLoadException : Could not load file or assembly 'Microsoft.AspNet.SignalR.Client, Version=2.1.2.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The
located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)
We are only running version 2.3.0 of Microsoft.AspNet.SignalR.Client.
I ran a grep over the whole solution and could not find a single instance which does not use 2.3.0. or runs the version mentioned in the error
The test itself does not have a reference to this library
I deleted all bin folders, cleaned and rebuilded.
Update:
I am pretty sure the problem is not nunit. Rather it shows the symptons. How do you go about finding out where this reference is used? App.configs for example only show ranges:
<assemblyIdentity name="Microsoft.AspNet.SignalR.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.3.0.0" newVersion="2.3.0.0" />
I added an app.config in the test project and in the project that the test is running in which I declared:
<assemblyIdentity name="Microsoft.AspNet.SignalR.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.3.0.0" newVersion="2.3.0.0" />
Now the exception is gone. Still I don't think this is the right solution. Normally visual studio must know which assembly version is the right one without declaring an app.config every time.

MsTest ignoring assemblyRedirect in app.config

I have a project that I recently upgraded the json nuget package to v10.
The same project also has a reference to System.Net.Http.Formatting (via Microsoft.AspNet.WebApi.Client.5.2.3 package) - which references json v6.0 dll.
I have an app.config in the test project that has:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
When I run the tests in VS, all tests pass.
But when I run the same tests using MsTest command (ver 12 in C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE), a bunch of test methods fail with the exception:
System.IO.FileNotFoundException: System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified
This is the exact line in the test method where it fails:
HttpRequestMessage.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());
I have checked my entire solution and confirmed that none of the projects have any reference to json v6.
Is there a reason why the redirects are being ignored when I use MsTest ?
(I can see the testProjectName.dll.config with the redirect in the bin folder of the test project too)
Also, I read that using a testsettings file can resolve this issue, but I am unclear what I need to have in my testsettings file to redirect to the newer json.

Only NUnit error: Could not load file or assembly 'EntityFramework'

I get an error message in NUnit when I try to run a specific test. The error looks like this:
ChatProj.Tests.MessageRepositoryTests.Logg_LoggWorking_AssertView:
System.IO.FileLoadException : Could not load file or assembly 'EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Here is a picture
I've looked at the 2 projects in my solution, and I'm refrencing EF 6.0.0.0 in both. I've tried to look up the PublicKeyToken=b77a5c561934e089 and this is what I found in my solution. It's extra weird because I've no problem debugging or building the webapp, and the other unittests are testing within the same project (same EF version) and not reciving this error (as you can see in the picture from before).
Any idea what could be causing this problem?
UPDATE:
I think I figured it out. I was using nuget.org/packages/FakeDbSet which was using a command like : var mockItemList = new InMemoryDbSet { new Message {MessageID = 5000, Name ="Erland", MessageString ="Foo Bar", MessageDate = DateTime.Now} }; which somehow is an old way of faking entity framework code. Can be seen here: i.imgur.com/f6dnJbq.png
First, ensure that the EF DLL is actually getting pulled into the bin folder for the test application. If it is and the DLL is for EF v6, do you see version redirects for EF in your app.config for the test project? Something like this?
<configuration>
<!-- Leave the rest of the configuration file alone and just add the runtime area as follows: -->
<runtime>
<assemblyBinding>
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
If not, try pasting that into the app.config.
Sorry, it's hard to fully diagnose without more information.

Is it possible to use RIA Services and EntityFramework.Migrations together in a project?

On NuGet there are packages:
EntityFramework.Migrations
EF 4.3.1
EF 4.1
RIA Services, which depends on EF < 4.2.
EntityFramework.Migrations doesn't work, because it is now included in EF 4.3+
I'm using Code First approach, so I need the DbDomainService<> class, which is not available, when RIA Services aren't installed.
Are there any standalone downloads for the above to manually reference in my project?
EDIT:
I removed RIA from NuGet packages, updgraded EF to 4.3.1 and then referenced RIA EntityFramework lib from toolkit manually as suggested here: Can I use RIA Services with Entity Framework 4.3?
Unfortuately now I'm getting the following error:
The following exception occurred creating the MEF composition container:
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
The default code generator will be used.
I guess that your problem is related to the T4 code generator of Ria Services. You can however get an idea of the type it can't load attaching your debugger (if you use VS don't forget to "Break on ALL Thrown CLR Exception) to the compilation of client side assembly (msbuild MyClientProjectThatContainTheProxy.csproj. )
However, if you just want to "try something", put this
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="4.3.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
in your web.config, to tell the CLR how to resolve depndencies.
More info here: http://mcasamento.blogspot.it/2012/10/entity-framework-5-code-first-and-wcf.html