System.MissingMethodException in NInject - c#

When running our unit tests on our TFS build server, we get this error:
SetUp : System.MissingMethodException : Method not found: 'Void
Ninject.ModuleLoadExtensions.Load(Ninject.IKernel, System.Reflection.Assembly[])'.
at Ninject.Extensions.Conventions.AssemblyScanner.Process(
Assembly assembly, IKernel kernel)
which, as far as I can tell, is saying that one part of NInject can't find another part of Ninject.
The problem occurs on all three of our build servers.
Locally, it works fine.
All systems (local & remote) appear to be using the correct version of all the Ninject assemblies (as well as all the other in the application)
Any ideas?
UPDATE: Ooops thought I mentioned this in the original message:
Ninject ver 2.2.0.0
Ninject.Extensions.Conventions ver 2.2.0.5

Moste likely you use different versions of Ninject.dll and Nnject.Extensions.Conventions. E.g Ninject 3.0.0 and Conventions 2.2.0
MissingMethod exception is a deployment problem. Use the Fusion log to check what is really loaded. E.g one assembly could be in the GAC.

OK, we figured it out.
TFS build server likes putting all DLLs in the same folder. This causes a problem if you have both .Net and Silverlight assemblies with the same name (such is the case with Ninject.dll)
The solution was to change the "Output Path" on the Silverlight projects' properties page (under the "Build" tab), from the standard "bin\Release\" to something like "bin\Release\Silverlight" so the DLLs are kept separate.

Related

Failed conversion from .net core 2.2 to 3.0

Last week I upgraded my .NET Core Web API from 2.2 to 3.0.
I had a lot of issues with packages and still struggling.
Case 1: What I have right now is that all of my tests are failing:
unit tests, integrations tests, etc.
I'm using:
Nunit (3.12.0)
NUnit3TestAdapter (3.15.1)
Moq 4.13.0
Microsoft.NET.Test.sdk (16.2.0)
Microsoft.AspNetCore.Mvc.Testing
When I start debugging my tests I get the following error message:
System.IO.FileNotFoundException HResult=0x80070002
Message=Could not load file or assembly 'Microsoft.IntelliTrace.Core, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Source=System.Private.CoreLib.
The error occurred in the RuntimeAssembly file (part of system.private.corelib), method InternalLoadAssemblyName.
When I continue I get this:
System.Reflection.ReflectionTypeLoadException: 'Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.IntelliTrace.Core, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.'
Case 2: When I'm not debugging my tests but just run my application en startup swagger, I can use every call but my output window is filled with thousands of Exceptions like thrown:
'System.InvalidCastException' in Swashbuckle.AspNetCore.SwaggerGen.dll
This happens when the Linq class Where.SpeedOpt.cs is used and the List.cs class of generic, also in System.Private.CoreLib.
Are case 1 and case 2 related to each other?
Anyone have a workaround or solution?
Case 1 also fixed:
When using .Net Core 3.0 and automapper
you should add automapper with additional parameter
services.AddAutoMapper(typeof(Startup));
In .Net core 2.2 i just had
services.AddAutoMapper();
He fails on this during unit and integrationtesting
not on normal startup
Case 2 (swagger error) is solved.
Seems there was a bug in the swagger 5.0.0 packages
That bug is solved in the 5.0.0-rc4 version
Case 1 is still open.
I tried to reproduce with different coding and see what the results are.
When i instantiate a new httpclient, there is no error.
Nevertheless, i can not call my api because it's secured and i get the "unathorized" error (normal behaviour)
When i instantiate a new httpclient with my webapplicationfactory, there is the error.
Is there something that is not initialized from startup when i run my tests
instead of running the core api thru normal startup and calling swagger?
Maybe a problem in startup that is only an issue in unit and integrationtests?
Regards
GSharp

Sytem.Reflection.Emit error when establishing XML client in Azure Function

Trying to establish an xmlrpc to a third party web service from my function app. It works fine from localhost, and indeed, it works in other functions but when published to Azure I'm getting this error:
System.MissingMethodException: Method not found: 'System.Reflection.Emit.AssemblyBuilder System.AppDomain.DefineDynamicAssembly(System.Reflection.AssemblyName, System.Reflection.Emit.AssemblyBuilderAccess)'.
at CookComputing.XmlRpc.XmlRpcProxyGen.BuildAssembly(Type itf, String assemblyName, String moduleName, String typeName, AssemblyBuilderAccess access)
at CookComputing.XmlRpc.XmlRpcProxyGen.Create(Type itf)
at CookComputing.XmlRpc.XmlRpcProxyGen.Create[T]()
It's failing at this line:
_serviceClient = XmlRpcProxyGen.Create<IServiceClient>();
IServiceClient is an interface that looks like this:
using CookComputing.XmlRpc;
using System;
namespace App.Core.Helpers.Service
{
[XmlRpcUrl("https://some.url")]
public interface IServiceClient : IXmlRpcProxy
// methods
}
I've manually added the System.Reflection.Emit package to the solution in an attempt to fix it, but no joy. The exact same code is running fine in other apps we have in Azure. The app is running .Net framework 4.6.1.
This is a problem which can occur when there is an old version of a DLL still lingering somewhere around. Make sure that the latest assemblies are deployed and no duplicated older assemblies are hiding in certain folders. Your best bet would be to delete every built item(Clean Build) and Rebuild/redeploy the entire solution.
In particular, be sure an old version is not in the GAC.
This can help to Remove an Assembly from the Global Assembly Cache.
I was facing same issue as you were facing.
What I found solution is that, I was using asp.net core framework So I have to change it into net 4.5 framework. And that's all.
Issue resolved.
So you may try that.

Could Not Load Type From Assembly on unused package version

I have a C# project that I just pulled down from version control on a new machine. I have all the dependencies installed in the project and when I try to run it I get to my dependency injection initialization (ninject) an System.TypeLoadException error on an internal library. The error says that it cannot load version 5.3.1.0 of the library, but I am not using that version. In my Web.config I am pointing to 5.4.5.0 and in my machine config I am pointing to version 4.9.1.0 - neither of which the error mentions. I search the project for the version that the error mentions and get nothing as well.
Is there anywhere else for me to look for this reference?

Azure Function referencing mixed-mode assembly

TL;DR: Is it possible to use mixed-mode assemblies in Azure Functions?
Details: I have an in-house mixed-mode assembly that I'm trying to use in an Azure Function. When I try to build, I get the following error:
------ Build started: Project: AzureDemo, Configuration: Debug x64 ------
AzureDemo -> C:\src\local\2017\AzureDemo\bin\x64\Debug\net462\bin\AzureDemo.dll
C:\Users\hugh\.nuget\packages\microsoft.net.sdk.functions\1.0.2\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(31,5): error : Could not load file or assembly 'file:///C:\src\local\2017\AzureDemo\bin\x64\Debug\net462\bin\AzureDemo.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Done building project "AzureDemo.csproj" -- FAILED.
For clarity, the in-house library is x64 and my demo project is also x64, so it's not an x86/x64 problem.
Also, when I take the code out of the Azure Function project and put it in a plain old .NET Core 2.0 project, it builds just fine. edit: it builds fine, but it still doesn't run (System.EntryPointNotFoundException: A library name must be specified in a DllImport attribute applied to non-IJW methods.). So I may be in deeper water than I thought.
I'm kind of afraid Azure Functions won't work with mixed-mode assemblies... but I haven't found any definitive statement to that effect.
I'm also a little concerned that the fact that it's using netstandard1.0 might have something to do with it.
The error is happening at build time when the SDK launches the build task to generate the build artifacts/function metadata.
I've opened this issue with the details to track the bug: https://github.com/Azure/azure-functions-vs-build-sdk/issues/131
Actual x64 CLI releases would also be required for successful local testing, and this is tracked here: https://github.com/Azure/azure-functions-cli/issues/117

BadImageFormatException when migrating from ASP.Net Core 1.1 to 2.0

I just migrated an ASP.Net Core 1.1 application to the new 2.0 version that was just released. Now I get the following exception:
System.BadImageFormatException: 'Could not load file or assembly
'dotnet-aspnet-codegenerator-design' or one of its dependencies. An
attempt was made to load a program with an incorrect format.'
The exception is thrown on the following line (AddMvc):
public IServiceProvider ConfigureServices(IServiceCollection services)
{
...
services.AddMvc(options =>
{
options.Filters.Add(new MiddlewareFilterAttribute(typeof(LocalizationPipeline)));
})
.AddJsonOptions(options =>
{
// Maintain property names during serialization. See:
// https://github.com/aspnet/Announcements/issues/194
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
})
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
.AddDataAnnotationsLocalization();
}
I'm targeting the .Net Framework 4.7, using AnyCPU target platform. I'm using the win10-x64 RID if this is of any help.
Every Nuget package is up to date etc.
Any idea? I've got no luck by googling.
the same exception occurred when I switched from x86 to x64 (after upgrading from core 1.1 to 2.0).
Since dotnet-aspnet-codegenerator-design is not really needed at runtime, I removed that reference. But then an identical exception occurred with the Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv assembly.
Luckily, that problem was related to the fact I didn't change the .NET Core Runtime Identifier (RID). This was still set on win7-x86, so I changed it to win7-x64 and the Libuv devepency could load.
I hope there will be some fix for dotnet-aspnet-codegenerator-design since that dependency is probably necessary for scaffolding controllers and views...
Update: there is an issue for this on Github (https://github.com/aspnet/Scaffolding/issues/601)
There's a chance that the dependency is corrupted. You can use a tool like Everything (https://filehippo.com/download_everything/) to search and find the corrupt dependency. There's a good chance it will be somewhere in this folder (C:\Program Files\dotnet\shared). Once you find it, try to google and redownload it(there's a good chance, you'll find a nuget for it) and then replace the old\corrupt version (be sure to back up).
If you're having trouble finding a replacement for the dependency online, simply publish your project on to a folder, all the dependencies would be copied to that folder. If you publish your project, and you run dotnet PROJECTNAME.dll and you still get the same error, you might have to run a clean install or repair on Visual Studio.
I hope this saves someone a lot of time, this error can take a while to debug.
I was getting this error too on SmarterASP.NET hosting. I couldn't try all the file updates suggest here, but found another solution, prior to which I tried compiling to several targets without success. Finally, it all just started working when I targeted for Portable. On Smarter it is now running nicely as a Framework Dependent Deployment, ASP 2.2 Core, Portable. Sometimes I find getting Core running is like having to get out the ol' trial-and-error chops. As always, your mileage may vary.

Categories