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

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.

Related

HostingEnvironment.QueueBackgroundWorkItem method is missing

I am working in .NET framework 4.8 (correction: my Visual Studio installation was 4.8, the application was targeting 4.5 - this was the source of the problem, which is now solved) and trying to use the QueueBackgroundWorkItem method of the HostingEnvironment class, but when I write it into my code, I get this message:
BC30456: 'QueueBackgroundWorkItem' is not a member of 'HostingEnvironment'.
I have used Imports System.Web.Hosting at the top of my script. System.Web.Hosting imports OK and the HostingEnvironment class shows up highlighted in my code, as it should. The class HostingEnvironment is recognised and has methods, but QueueBackgroundWorkItem isn't one of them.
I get a similar error when I try to use this method in C#.
CS0426: The type name 'QueueBackgroundWorkItem' does not exist in the type 'HostingEnvironment'.
I've searched for the System.Web.Hosting library in NuGet to see if there were any updates, but nothing came up. Google searches for these errors haven't got me anywhere, other than to links explaining how to use the HostingEnvironment method.

AppCenter analytics not starting for WPF

I try to use AppCenter for measuring crashes and telemetrics in my application.
The application is a WPF application, using .NET framework 4.7.2.
I register AppCenter the following way:
AppCenter.Start("MY_KEY", typeof(Analytics), typeof(Crashes));
Directly after the registration I see the following output message:
ERROR: Failed to start service 'Analytics'; skipping it.
Microsoft.AppCenter.AppCenterException: Service type does not contain static 'Instance' property of type IAppCenterService. The service is either not an App Center service or it's unsupported on this platform or the SDK is used from a .NET standard library and the nuget was not also added to the UWP/WPF/WinForms project.
vid Microsoft.AppCenter.AppCenter.StartInstance(Type[] services)
I have the following NuGet versions of AppCenter installed:
Microsoft.AppCenter.Analytics: 3.4.2
Microsoft.AppCenter.Crashes: 3.4.2
Has anybody faced the same problem and knows how to solve this?
Thanks in advance.
The issue is located and corrected.
The cause of this issue was caused by a namespace conflict, another package named Analytics.
Refering the correct namespace with full name, resolved this issue:
AppCenter.Start("MY_KEY", typeof(Microsoft.AppCenter.Analytics.Analytics), typeof(Crashes));

Method 'ExecuteAsync' in type 'System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy' does not have an implementation

I am newer about using Code First in c#.
After I enabled Migration in my project and launch my site, I get an Error:
Method 'ExecuteAsync' in type 'System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy' from assembly 'EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' does not have an implementation.
I have defined the context class as below.
namespace MyOA.Migration.Contexts
{
public class OADBContext : DbContext
{
public OADBContext() { }
}
}
and I tried to create the DB in Global.asax as below.
protected void Application_Start()
{
// Forces initialization of database on model changes.
using (var context = new Migration.Contexts.OADBContext())
{
context.Database.Initialize(force: true);
}
}
I tried to search the reason but got no idea.
Any suggestions?
Thanks in advance.
If you check the .NET version of the two asseblies:
EntityFramework (v4.5)
EntityFramework.SqlServer (v4.0)
You will see that EntityFramework.SqlServer has v4.0 .NET dependency, but EntityFramework uses v4.5. That is the root of the issue. I use dotpeek tool for checking the assembly version (there are other options from stack overflow to check .net vestion of an assembly).
Note: and really when you decompile EntityFramework.SqlServer.dll using jetBrains reflector tool you will find that there is no ExecuteAsync method.
What we have to do to fix the issue is to use nuget.exe (from visual studio or from stand alone nuget executable: please find "latest nuget.exe"). And run it from command line:
cd "[path to your nuget.exe]"
nuget Install EntityFramework
A set of EF 6 assemblis will be downloaded. Use the EntityFramework and EntityFramework.SqlServer from .net v4.5 folder.
I +1'd #Spirit's answer for pointing me at the root of the issue, but I was able to fix it for myself by searching through all of the *.csproj files in the solution and replacing
packages\EntityFramework.6.1.3\lib\net40\EntityFramework.dll
^^^^^
with
packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll
^^^^^
I had a mix of usages in the projects. My symptom was that NCruch would get the exception on a test, but running the same test from NUnit test runner would pass just fine.
I faced this issue in my work, and tried suggested solutions with no luck, but the solution that worked out for us was to use a relatively older version of Entity Framework, we used version 6.0.0 while the latest (as of the time I'm writing down this answer) is 6.1.3
The issue with me was that my project was targeting .Net Framework 2.0, and suddenly when upgraded to .Net Framework 4.6.1 a warning appeared so I tried to update Entity Framework package which was on the latest 6.1.3, but it stopped working properly, and got the exception mentioned above.
Hope this will help somebody later.
I had this same problem but the cause was different. In the "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files" folder, there were several versions of the entityframe dlls. No doubt older versions. I had already recycled the iis pool and restarted the computer but that didn't work. I had to delete all the files in that folder and that did the trick.
Since all similar S/O questions are being directed to this one, I'll leave another idea to consider. Check to make sure that EntityFramework hasn't been installed into you GAC by chance. IIS will take the GAC version over your bin version leading to some serious head scratching.

System.MissingMethodException in NInject

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.

ASP.NET: ICollection Constructor Not Found?

I have a ASP.NET application running on a remote web server and I just started getting this error. I can't seem to reproduce it in my development environment:
Method not found: 'Void System.Collections.Generic.ICollection`1..ctor()'.
Could this be due to some misconfiguration of .NET Framework or IIS 6?
Update:
I disassembled the code in the DLL and it seems like the compiler is incorrectly optimizing the code. (Note that Set is a class that implements a set of unique objects. It inherits from IEnumerable.) This line:
Set<int> set = new Set<int>();
Is compiled into this line:
Set<int> set = (Set<int>) new ICollection<CalendarModule>();
The Calendar class is a totally unrelated class!! Has anyone ever noticed .NET incorrectly compiling code like this before?
Are the .NET versions on both systems the same inc. the same service pack?
Is your IIS setup to use .NET 2.0? If not, change it to 2.0. If you can't see 2.0 in the list then you'll need to run aspnet_regiis from the 2.0 framework directory.
This was caused by a bug in the aspnet merge tool which incorrectly merged optimized assemblies. It can be solved by either not merging the assemblies or not optimizing them.

Categories