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.
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.
I have a very strange issue. I have added a reference to System.Management.Automation in my project and I am trying to call the following code:
using (Powershell ps = Powershell.Create())
{
ps.AddScript("Get-AppxPackage");
ps.Invoke();
}
Note that I can run other powershell commands in this way fine, it is only the Appx commands that are raising an exception. Running the Get-AppxPackage command results in an ItemNotFoundException. The error is:
Exception thrown: 'System.Management.Automation.ItemNotFoundException' in System.Management.Automation.dll
Additional information: Cannot find path 'C:\Users\xxxx\Documents\WindowsPowerShell\Modules' because it does not exist.
My first assumption was that this may be a working directory thing, so I explicitly set the working directory before calling the command, but that did not change anything. I then checked, and that directory did not exist, so I created it just to see what would happen. After creating the directory and running the code again I got this error:
Exception thrown: 'System.Management.Automation.ItemNotFoundException' in System.Management.Automation.dll
Additional information: Cannot find path 'C:\windows\system32\windowspowershell\v1.0\Modules\Appx\Microsoft.Windows.Appx.PackageManager.Commands' because it does not
I honestly have no idea what is going on here. To make the issue even stranger, I tried this on another computer and the code works fine. So there must be something wrong with Visual Studio or my project on that one computer.
I've tried deleting the debug and obj folder, the suo and all of that. I've removed the reference to System.Management.Automation and re-added it, even rebooting in between. I am at a loss, I have no idea why this is happening or what else I can do to figure it out.
Note: I am able to run the Appx commands in Powershell ISE fine, so there is no issue on the computer. The problem is only with calling that command through the System.Management.Automation dll.
Any help would be greatly appreciated.
OK, it appears that this issue was caused by installing the incorrect version of System.Management.Automation as a nuget package via the package manager. I had uninstalled this and then added a reference to the latest version of the DLL manually before I started getting the issue described above.
But the uninstall for the nuget package clearly didn't work properly as the project continued to reference this version, and nothing I tried could get it to use the new one.
To solve the issue, I created a new project, added the source files, added a reference directly to the new version of System.Management.Automation and the error stopped occuring.
I can only assume that the installing and uninstalling the wrong version with the package manager corrupted the first project.
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.
I am using Snarl C# API to send notifications to snarl.
Now I have saved the content of above url in a file named SnarlNetwork.cs and the content of my test.cs file are:
using SnarlNetworkProtocol;
using System;
class test
{
public static void Main(String[] args)
{
SNP snarl_object = new SNP();
string hostname = "localhost";
string hostport = "9887";
string appName = "Spotify";
bool val = snarl_object.register(hostname, hostport, appName);
if (val == true)
{
string title = "hello";
string message = "world";
string timeout = "5";
bool newval = snarl_object.notify(hostname, hostport, appName, null, title, message, timeout);
if (newval == true)
{
Console.WriteLine("sucessfull");
}
}
}
}
Now when I try to compile my test.cs file using csc test.cs I get the following error:
C:\Users\Noob\csharp>csc test.cs
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.4926
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.
test.cs(1,7): error CS0246: The type or namespace name 'SnarlNetworkProtocol' could not be found (are you missing a using directive or an assembly reference?)
So, what am I doing wrong here because according to me I am not missing any using directive.
I was using .NET Framework 4.5 but my new library had .NET Framework 4.5.2 and I got the same issue when I tried to build. I solved it by updating my project from 4.5 to 4.5.2 (same as my library).
On the Solution Explorer tab right click and select Properties
Resolve this issue by updating the Target Framework in the project application settings.
For instance, In my case the project was compiling with .net framework version 4.5.1 but the dll which were referenced were compiled with the version 4.6.1.
So have updated the my project version. I hope it works for you.
This is the problem:
C:\Users\Noob\csharp>csc test.cs
You haven't added a reference to the DLL. You need something like:
C:\Users\Noob\csharp>csc test.cs /r:SnarlNetwork.dll
(or whatever the assembly is called).
Alternatively, if you haven't got it as a separate library, just compile both files:
C:\Users\Noob\csharp>csc test.cs SnarlNetwork.cs
If you haven't compiled an assembly but want to, you can use:
csc /target:library /out:SnarlNetwork.dll SnarlNetwork.cs
csc Test.cs /r:SnarlNetwork.dll
(In fact, specifying the output file is unnecessary in this particular case, but it's still clearer...)
Edit: Oh ignore me, you're not using Visual Studio.
Have you added the reference to your project?
As in this sort of thing:
It might be due to "client profile" of the .NET Framework.
Try to use the "full version" of .NET.
This usually happens to me when I have a using statement but have forgotten to reference the assembly that defines the namespace.
But in your case, as the namespace is defined in a file in your project, you have forgotten to tell the compiler about the snarlnetwork.cs file.
See csc compiler examples
I had this error on a MVC Project. And after a long research i found out that the .cs file containing some of the classes i referenced in the main project had a Build Actions set to "Content" ...
After changing it "Content"->"Compile" the error disappeared.
most of the problems cause by .NET Framework. So just go to project properties and change .Net version same as your reference dll.
Done!!!
Hope it's help :)
I resolved this by making sure my project shared the same .Net Framework version as the projects/libraries it depended on.
It turned out the libraries (projects within the solution) used .Net 4.6.1 and my project was using 4.5.2
i also faced same problem,
Reason: why i faced this error is,
rather then creating new partial view,
i have created class and then renamed its extension from ".cs" to ".cshtml".
Solution:
Just delete that rename view and re-create proper partial/full view. it will work fine after that.
Check your Web.Config and find namespace = . you can remove or if you need it you must create new
I had the same error when used cs file was located inside project folder, but did not referenced from .csproj of parent project.
Intellisence see this file inside project folder, but compiler does not see it because of missing reference in .csproj
I have resolved this problem by adding the reference to System.Web.
I also got this error due to a missing reference.
The reason I did not notice is because Resharper offers to add a using and a reference. Adding the using succeeds (but it's highlighted grey), syntax highlighting of missing classes works (sometimes), but adding the reference fails silently.
When manually adding the reference an error pops up, explaining why adding the reference fails (circular reference). Resharper did not pass this error on to the GUI.
I had the same issue when I clone my project from Git and directly build the solution first time. Instead of that go to the local repository in file explorer and double click the solution file (.sln) solved my issue.
I had a similar problem after first pulling and starting a new solution. It was fixed in visual studio by first cleaning the project. Then restoring the packages. When I built again, there were no more type or namespace errors.
Theoretically, if the the client framework is higher than the library framework client project builds successfully. So I suggest you check the Platform Target to make sure there is no conflicts.
right mouse button project > Properties > Build and uncheck Prefer 32-bit which is available for console project only. And check both projects target the same platform.
[
In my case, just "add refence" and browser the DLL file. it works for me.
I had this issue when I first cloned my project from Git to Visual Studio. I just had to update my NuGet packages, and then I was good to go!
Project > Manage NuGet Packages... >
Then update the packages. It notified me and there was a yellow bar with a button that I pushed and it downloaded the packages!