ASP.NET MVC 4 Website won't start - Could not load type 'System.Reflection.AssemblyMetadataAttribute' - asp.net-mvc-4

I deployed my ASP.NET MVC 4 web app to a Windows Server 2003 (IIS 6). But it will not start.
Originally I had developed the project for .NET 4.5, but had to rebuild it for .NET4 when I found out that .NET 4.5 is not supported on Windows Server 2003.
This meant removing all the third party references (with NuGet), changing the build target in project properties to .NET4, then adding the references back.
The references were to Ninject, EF and Automapper.
When I try to load a page I get the following error:
Could not load type 'System.Reflection.AssemblyMetadataAttribute' from
assembly 'mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'. Description: An unhandled exception
occurred during the execution of the current web request. Please
review the stack trace for more information about the error and where
it originated in the code.
Exception Details: System.TypeLoadException: Could not load type
'System.Reflection.AssemblyMetadataAttribute' from assembly 'mscorlib,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[TypeLoadException: Could not load type
'System.Reflection.AssemblyMetadataAttribute' from assembly 'mscorlib,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.]
System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken,
IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs,
Int32 methodInstCount, ObjectHandleOnStack type) +0
System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module,
Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext,
RuntimeTypeHandle[] methodInstantiationContext) +180
System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken,
Type[] genericTypeArguments, Type[] genericMethodArguments) +192
System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord
caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly,
RuntimeModule decoratedModule, MetadataToken decoratedToken,
RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[]
attributes, IList derivedAttributes, RuntimeType& attributeType,
IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean&
isVarArg) +115
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule
decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount,
RuntimeType attributeFilterType, Boolean mustBeInheritable, IList
derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) +426
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly
assembly, RuntimeType caType) +103
System.Reflection.RuntimeAssembly.GetCustomAttributes(Type
attributeType, Boolean inherit) +64
WebActivator.AssemblyExtensions.GetActivationAttributes(Assembly
assembly) +113
WebActivator.ActivationManager.RunActivationMethods() +216
WebActivator.ActivationManager.RunPreStartMethods() +28
WebActivator.ActivationManager.Run() +55
[InvalidOperationException: The pre-application start initialization
method Run on type WebActivator.ActivationManager threw an exception
with the following error message: Could not load type
'System.Reflection.AssemblyMetadataAttribute' from assembly 'mscorlib,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'..]
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1
methods) +423
System.Web.Compilation.BuildManager.CallPreStartInitMethods() +306
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager
appManager, IApplicationHost appHost, IConfigMapPathFactory
configMapPathFactory, HostingEnvironmentParameters hostingParameters,
PolicyLevel policyLevel, Exception appDomainCreationException) +677
[HttpException (0x80004005): The pre-application start initialization
method Run on type WebActivator.ActivationManager threw an exception
with the following error message: Could not load type
'System.Reflection.AssemblyMetadataAttribute' from assembly 'mscorlib,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'..]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9164848
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)
+258
Any ideas?
EDIT: Website developed using VS2012

Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly mscorlib
Yes, this technically can go wrong when you execute code on .NET 4.0 instead of .NET 4.5. The attribute was moved from System.Core.dll to mscorlib.dll in .NET 4.5. While that sounds like a rather nasty breaking change in a framework version that is supposed to be 100% compatible, a [TypeForwardedTo] attribute is supposed to make this difference unobservable.

Related

Swagger Failed to load API Definition when using Newtonsoft Serialization

I'm using Swashbuckle.AspNetCore package to document my API. I had it working for weeks until I started JSON serialization of some classes. Now I get an error in the Swagger UI :
"Failed to load API definition" - Fetch error Internal Server Error /swagger/v1/swagger.json
My log files show the following error:
System.IO.FileLoadException: Could not load file or assembly
'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral,
PublicKeyToken=30ad4fe6b2a6aeed'. The located assembly's manifest
definition does not match the assembly reference. (Exception from
HRESULT: 0x80131040)
I updated to Newtonsoft.Json v12.0.1.
Does the Swagger NuGet package depend on a previous version of Newtonsoft?
I tried updating my entire solution to use Newtonsoft.Json v12.0.1.
I also searched for any possible dependencies Swagger may have with Newtonsoft, but I did not see anything explicit.
2019-03-26 17:17:34.573 -04:00 [Information] Request starting HTTP/1.1 GET http://localhost:8080/swagger/index.html
2019-03-26 17:17:34.680 -04:00 [Information] Request finished in 108.7888ms 200 text/html
2019-03-26 17:17:34.876 -04:00 [Information] Request starting HTTP/1.1 GET http://localhost:8080/swagger/v1/swagger.json
2019-03-26 17:17:34.898 -04:00 [Information] Request starting HTTP/1.1 GET http://localhost:8080/swagger/favicon-32x32.png
2019-03-26 17:17:34.916 -04:00 [Information] Sending file. Request path: '"/favicon-32x32.png"'. Physical path: '"N/A"'
2019-03-26 17:17:34.917 -04:00 [Information] Request finished in 18.8478ms 200 image/png
2019-03-26 17:17:35.032 -04:00 [Error] Connection ID ""16573246634629012016"", Request ID ""80001a32-0001-e600-b63f-84710c7967bb"": An unhandled exception was thrown by the application.
System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
at System.Reflection.CustomAttribute.IsCustomAttributeDefined(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Int32 attributeCtorToken, Boolean mustBeInheritable)
at System.Reflection.CustomAttribute.IsDefined(RuntimePropertyInfo property, RuntimeType caType)
at Newtonsoft.Json.Serialization.DefaultContractResolver.GetSerializableMembers(Type objectType)
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateProperties(Type type, MemberSerialization memberSerialization)
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType)
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type)
at Swashbuckle.AspNetCore.SwaggerGen.SchemaRegistry.CreateSchema(Type type, Queue`1 referencedTypes)
at Swashbuckle.AspNetCore.SwaggerGen.SchemaRegistry.GetOrRegister(Type type)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreateResponse(ApiResponseType apiResponseType, ISchemaRegistry schemaRegistry)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreateResponses(ApiDescription apiDescription, ISchemaRegistry schemaRegistry)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreateOperation(ApiDescription apiDescription, ISchemaRegistry schemaRegistry)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreatePathItem(IEnumerable`1 apiDescriptions, ISchemaRegistry schemaRegistry)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreatePathItems(IEnumerable`1 apiDescriptions, ISchemaRegistry schemaRegistry)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath, String[] schemes)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()
2019-03-26 17:17:35.058 -04:00 [Information] Request finished in 182.3632ms 500
I expect the swagger page to list my HTTP methods as usual.

Could not load file or assembly 'MvcSiteMapProvider

I added the provider via nuget console Install-Package MvcSiteMapProvider.MVC4.
The install looked good:
Successfully added 'MvcSiteMapProvider.MVC4 4.6.22' to XYZ.
When I execute the application I get this error message any suggestions on troubling shooting?
Server Error in '/XYZ' Application.
Could not load file or assembly 'MvcSiteMapProvider, Version=4.6.22.0, Culture=neutral, PublicKeyToken=1923abe4657913cc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileLoadException: Could not load file or assembly 'MvcSiteMapProvider, Version=4.6.22.0, Culture=neutral, PublicKeyToken=1923abe4657913cc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'MvcSiteMapProvider, Version=4.6.22.0, Culture=neutral, PublicKeyToken=1923abe4657913cc' could not be loaded.
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Stack Trace:
[FileLoadException: Could not load file or assembly 'MvcSiteMapProvider, Version=4.6.22.0, Culture=neutral, PublicKeyToken=1923abe4657913cc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule, IRuntimeMethodInfo pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs) +0
System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule module, IRuntimeMethodInfo ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs) +38
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) +571
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) +103
System.Reflection.RuntimeAssembly.GetCustomAttributes(Boolean inherit) +37
Owin.Loader.DefaultLoader.SearchForStartupAttribute(String friendlyName, IList1 errors, Boolean& conflict) +106
Owin.Loader.DefaultLoader.GetDefaultConfiguration(String friendlyName, IList1 errors) +46
Owin.Loader.DefaultLoader.LoadImplementation(String startupName, IList1 errorDetails) +75
Owin.Loader.DefaultLoader.Load(String startupName, IList1 errorDetails) +21
Microsoft.Owin.Host.SystemWeb.OwinBuilder.GetAppStartup() +115
Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint() +28
System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) +115
Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication context) +106
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +534
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +352
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): Could not load file or assembly 'MvcSiteMapProvider, Version=4.6.22.0, Culture=neutral, PublicKeyToken=1923abe4657913cc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9947380
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +261
Assuming you actually have the Nuget package installed, that error is most usually an issue with binding redirects in your Web.config. You can try to resolve the issue manually, by finding the appropriate binding redirect and making sure the version numbers are correct. I find it easier to just force remove the package and reinstall it. That will usually fix the problem:
> uninstall-package MvcSiteMapProvider.MVC4 -Force
> install-package MvcSiteMapProvider.MVC4
Make sure your Web.config is not open in your documents pane, or if it is, that you allow it to reload. If you save over it without refreshing from the filesystem after installing a Nuget package, you'll often bork things like binding redirects, leading to this issue.

Missing reference to Microsoft.scripting.ExtensionAttrribute.dll

We intermittently get this error on our .net 4 web forms web site. Recycling the app pool seems typically resolves it.
The only references i can find to it seem to be related to either using Umbraco, or the Dynamic language Runtime. Neither of which applies to us.
The only useful link I have found is this: http://support.frozenmountain.com/entries/23667761-Compatibility-issue-using-ASP-Net-4-0-Extensions-and-ScriptManager
Any other solutions, other than adding the unnecesary reference?
System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Scripting.ExtensionAttribute, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. File name: 'Microsoft.Scripting.ExtensionAttribute, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) at System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean isDecoratedTargetSecurityTransparent) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) at System.Web.UI.AssemblyCache.GetAjaxFrameworkAssemblyAttribute(Assembly assembly) at System.Web.UI.ScriptManager.get_DefaultAjaxFrameworkAssembly() at System.Web.UI.ScriptManager..ctor() at ASP.masterpages_safarinow_master.__BuildControlMasterScriptManager() at ASP.masterpages_safarinow_master.__BuildControlfrmMain() at ASP.masterpages_safarinow_master.__BuildControlmasterBodyTag() at ASP.masterpages_safarinow_master.__BuildControlTree(masterpages_safarinow_master __ctrl) at System.Web.UI.MasterPage.CreateMaster(TemplateControl owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection) at System.Web.UI.Page.ApplyMasterPage() at System.Web.UI.Page.PerformPreInit() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Although you said that you're not using the DLR, that's the only place this file exists. The error message strongly suggests that you're using an older version of IronPython (or IronRuby or some other DLR-based thing) which was built for .NET 2.0-3.5. Somewhere, there are files with names like "Microsoft.Dynamic.dll", "Microsoft.Scripting.Core.dll", and "Microsoft.Scripting.dll". Whatever is using this should be updated with a version of the DLR which was built specifically for .NET 4.0.

NHibernate Version Issue

I'm having a go at getting a test project up and running. I've nabbed a load of code from this article.....
Fluent NHibernate Automap with NHibernate Facility in ASP.NET MVC
Problem is that I'm getting the following error....
Could not load file or assembly 'NHibernate, Version=3.0.0.1001,
Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its
dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)
I've downloaded all the latest and greatest from NHibernate, Castle Project, and FluentNHibernate. I've looked at the version of the NHibernate.dll that I am referencing in the project and it's 3.0.0.400. Where and why is the solution complaining about 3.0.0.1001??????
For future use, I'd like to know how I find out what the problem is as well as the solution if possible.
Many thanks,
ETFairfax
MORE INFO.......
Exception Details: System.IO.FileLoadException: Could not load file or
assembly 'NHibernate, Version=3.0.0.1001, Culture=neutral,
PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. The
located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)
Source Error:
Line 45: if (container == null)
Line 46: {
Line 47: container = new WindsorContainer()
Line 48: .Install(
Line 49: Configuration.FromAppConfig(),
Source File: C:\Users\Public\Documents\TestCompany\Source\TestCompany.TestModule\MvcApplication2\Global.asax.cs Line: 47
Assembly Load Trace: The following information can be helpful to determine why the assembly 'NHibernate, Version=3.0.0.1001, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' could not be loaded.
=== Pre-bind state information ===
LOG: User = ETFairfax-TestCompany\ETFairfax
LOG: DisplayName = NHibernate, Version=3.0.0.1001, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
(Fully-specified)
LOG: Appbase = file:///C:/Users/Public/Documents/TestCompany/Source/TestCompany.TestModule/MvcApplication2/
LOG: Initial PrivatePath = C:\Users\Public\Documents\TestCompany\Source\TestCompany.TestModule\MvcApplication2\bin
Calling assembly : ClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Public\Documents\TestCompany\Source\TestCompany.TestModule\MvcApplication2\web.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: NHibernate, Version=3.0.0.1001, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
LOG: Attempting download of new URL file:///C:/Users/ETFairfax/AppData/Local/Temp/Temporary ASP.NET Files/root/25bf06cc/f1f41498/NHibernate.DLL.
LOG: Attempting download of new URL file:///C:/Users/ETFairfax/AppData/Local/Temp/Temporary ASP.NET Files/root/25bf06cc/f1f41498/NHibernate/NHibernate.DLL.
LOG: Attempting download of new URL file:///C:/Users/Public/Documents/TestCompany/Source/TestCompany.TestModule/MvcApplication2/bin/NHibernate.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Revision Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
Stack Trace:
[FileLoadException: Could not load file or assembly 'NHibernate, Version=3.0.0.1001, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.RuntimeTypeHandle._GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, Boolean loadTypeFromPartialName) +0
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) +64
System.RuntimeType.PrivateGetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) +58
System.Type.GetType(String typeName) +50
Castle.Facilities.NHibernateIntegration.NHibernateFacility.RegisterDefaultConfigurationBuilder() +133
Castle.Facilities.NHibernateIntegration.NHibernateFacility.RegisterComponents() +29
Castle.Facilities.NHibernateIntegration.NHibernateFacility.Init() +196
Castle.MicroKernel.Facilities.AbstractFacility.Init(IKernel kernel, IConfiguration facilityConfig) +61
Castle.MicroKernel.DefaultKernel.AddFacility(String key, IFacility facility) +182
Castle.Windsor.WindsorContainer.AddFacility(String key, IFacility facility) +49
Castle.Windsor.Installer.DefaultComponentInstaller.SetUpFacilities(IConfiguration[] configurations, IWindsorContainer container) +242
Castle.Windsor.Installer.DefaultComponentInstaller.SetUp(IWindsorContainer container, IConfigurationStore store) +89
Castle.Windsor.WindsorContainer.Install(IWindsorInstaller[] installers) +268
MvcApplication2.MvcApplication.InitializeWindsor() in C:\Users\Public\Documents\TestCompany\Source\TestCompany.TestModule\MvcApplication2\Global.asax.cs:47
MvcApplication2.MvcApplication.Application_Start() in C:\Users\Public\Documents\TestCompany\Source\TestCompany.TestModule\MvcApplication2\Global.asax.cs:62
Version Information: Microsoft .NET Framework Version:2.0.50727.4952; ASP.NET Version:2.0.50727.4955
Fluent was probably built with a later version than the NHibernate asselbly you downloaded.
Theres a bundle of Fluent/NH3.0 at Fluent NHibernate website.
http://fluentnhibernate.org/downloads

Adding Unity dll reference to Silverlight 4 project

This morning I had an unusual issue with my Silverlight 4 app. I have been a big fan of IoC frameworks, so decided I will use Unity for my project. But as soon as I added the assembly to my project, I got this following error.
System.Windows.Markup.XamlParseException occurred
Message=Could not load type 'System.Security.AllowPartiallyTrustedCallersAttribute' from assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
StackTrace: at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean isDecoratedTargetSecurityTransparent)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
at System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit)
at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit)
at MS.Internal.XamlSchemaContext.ProcessXmlnsDefinitions(Assembly assembly, String assemblyName)
at MS.Internal.XamlSchemaContext.EnsureManagedAssemblyAttributesLoaded()
InnerException:
Now if I remove the dll my app works absolutely fine. I have been scratching my head since morning and not having much luck with StackOverflow search or Google.
Any help is much appreciated.
Cheers---Jag
Please verify that you're actually referencing the Silverlight assembly rather than the desktop one. The AllowPartiallyTrustedCallersAttribute class isn't in the Silverlight version.
Are you using Unity 2.0? If so, the DLL is named "Microsoft.Practices.Unity.Silverlight.dll". Is that the DLL you've added? If the ".Silverlight" isn't in the file name, then you're referencing the desktop dll instead.
This article might provide some useful information. It basically says that:
"the limitation when using Unity in a
partial trust environment is that you
cannot register and use mappings using
the RegisterType methods where the
target class is internal (C#), Friend
(Visual Basic .NET), private (C#), or
Private (Visual Basic .NET)."
Doing a clean build followed by a full rebuild fixed this issue for me.