I am maintaining a visual studio 2008 application (website project). There is no chance to upgrade to higher version of.net framework or upper version of entity framework. Like many IT shops, unless there are major issues, people are not going to allow me to do major upgrade on the system.
The .net framework is 3.5. and the EF version is 1.0
I need to change my program, so my select linq statement will work
Calling a SQL User-defined function in a LINQ query
As you can tell, I need to include stored function as a part of select statement
So I copied the statement.
I have struggled for hours, and I keep getting compilation.
//..various using statement
using System.Data.Objects.DataClasses;
using System.Data.Metadata.Edm;
//..other class
public static class EntityFunctions
{
[EdmFunction("FBLModel.Store", "SampleFunction")]
public static int SampleFunction(int param)
{
throw new NotSupportedException("Direct calls are not supported.");
}
}
I keep getting compilation errors
error CS0246: The type or namespace name 'EdmFunctionAttribute' could not be found (are you missing a using directive or an assembly reference?)
I have searched the whole internet include stackoverflow and MSDN blog, the namespace looks correct
Any suggestions? Thank you
The problem here is that you have a conflicting reference with your namespaces.
The System.Data.Metadata.Edm namespace contains a class called EdmFunction. The System.Data.Objects.DataClasses namespace contains a class called EdmFunctionattribute (which is the one you are trying to use).
For some reason your code is referencing the EdmFunction class. Try removing the namespace import for System.Data.Metadata.Edm, as you probably didn't want to import this in the first place.
Related
I am trying to go through this tutorial for on making sounds with waves using C#:
https://www.codeguru.com/dotnet/making-sounds-with-waves-using-c/
The first sample code it has you run is this, which is supposed to play a .wav file:
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.Devices;
namespace MyApp
{
class Program
{
static Audio myAudio = new Audio();
static void Main()
{
myAudio.Play("m:\\crooner2.wav",
AudioPlayMode.WaitToComplete);
}
}
}
In my code, the filepath and name of the .wav file was replaced with a different one, but otherwise the code is identical. However, I get an error regarding the second line of code: error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)
Without the Microsoft.VisualBasic.Devices call working, I have no way of running even the first exercise in the tutorial, and definitely no way of further progressing in using C# for sound manipulation.
I was expecting the code to run and play the .wav file. However, I got the error message instead.
As part of debugging, I came across this post on the Microsoft website:
https://learn.microsoft.com/en-us/dotnet/core/compatibility/visualbasic#types-in-microsoftvisualbasicdevices-namespace-not-available
I'm not sure what to make of it. It seems like it's saying it could be solved by upgrading to .Net 5 or higher, but I'm already using .Net 5. It also seems like it saying that Microsoft.VisualBasic.Devices was made obsolete with .Net Core 3.0, so I'm not sure how upgrading would make it easier to use something that was made obsolete.
It also says that certain functionality in Microsoft.VisualBasic.Devices has equivalent functionality that can be called by other means. It gives specific replacement calls for Microsoft.VisualBasic.Devices.Clock and Microsoft.VisualBasic.Devices.Ports, but nothing for Microsoft.VisualBasic.Devices.Audio, which is what I want to use in my code.
I have tried this in both Visual Studio and Visual Studio Code and get the same errors either way.
With .NET Core, you generally add references via NuGet packages. There is no NuGet package for Microsoft.VisualBasic.Forms.dll, which the documentation clearly states that type is declared in. To get that assembly reference, I believe that you need to replace this line in your project file:
<TargetFramework>net5.0</TargetFramework>
with these lines:
<TargetFramework>net5.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
After doing that, you should see Microsoft.WindowsDesktop.App.WindowsForms added under Dependencies -> Frameworks in the Solution Explorer and the relevant assembly is listed under that.
You have to use reference to "Microsoft.VisualBasic" in your project.
You have two way for do that :
1st way :
Right click on project references, select "Assemblys" => "Framework" and you can search (at top right) "basic" keyword, and select "Microsoft.VisualBasic" item.
After that you can compile your project and normally its works !
Screen for add references
2nd way :
Comment or delete "using Microsoft.VisualBasic.Devices;" instruction.
The class "Audio" should be underline to red, hover with your mouse and you have option by IDE which let you "using Microsoft.VisualBasic.Devices;".
References should be automatically added in project.
And now you can compile your project.
I have an older program running on .NET Core 1 and want to get it working with .NET 5. Instead of going through the tedious process of upgrading each version step by step I decided to just create a new solution and start from scratch. Doing this, I am able to copy most files from the older projects.
My issue is in the DbContext classes.
public partial class ClassName : DbContext
There are a number of errors throughout, but each give me the same (or similar) suggestion to resolve them, relating to a missing using reference.
The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?) Cannot resolve symbol 'DbContext'
Now, I know I am missing the using Microsoft.EntityFrameworkCore; reference. So when I add that package to the project, my file changes and I now get about 500 errors (about half the lines in the file).
Some examples of these new errors are as follows:
entity.HasKey(e => e.Id)
.HasName("PK");
entity.ToTable("TB");
In the above snippet, .HasName is throwing the error 'KeyBuilder' does not contain a definition for 'HasName' and no accessible extension method 'HasName' accepting a first argument of type 'KeyBuilder'.
As someone new to entity framework, am I missing something obvious or should I be re-scaffolding the database to re-create these context files?
No answer here yet so someone might miss that the comments actually holds an answer.
As #Kirk Larkin states in a comment to the question the solution is to add the Microsoft.EntityFrameworkCore.Relational package.
I just installed Visual Studio 2012 so I could take advantage of better ways to implement MVVM with Silverlight.
The first thing I wanted to do is start using the [CallerMemberName] attribute so I didn't have to hard-code property name strings.
I created a new Silverlight app, created a new class, included 'using System.Runtime.CompilerServices', and proceeded to type [CallerMemberName]. However, I get the error:
"The type or namespace name 'CallerMemberNameAttribute' could not be found (are you missing a using directive or an assembly reference?)"
However, I did include the using directive and there are no other assemblies that need to be referenced.
This is driving me up the wall since no Google search returned any information about why I might not be able to use it in VS2012/Silverlight. How do I fix this?
It looks like the version of Silverlight you're targetting doesn't include that attribute.
However, that's OK; you can simply define it yourself:
namespace System.Runtime.CompilerServices {
sealed class CallerMemberNameAttribute : Attribute { }
}
I have a class lib and I referenced it to another windows project. I added its namespace to my Form.cs (using SaglikNetClassLib;). they are seem unknown when I want to access to classes. I can see their properties and methods. But the complier says "Error 7 The type or namespace name 'SaglikNetClassLib' could not be found (are you missing a using directive or an assembly reference?), Do you have any suggestion?
KR,
Çağın
Are you targeting the .net Client Framework? Visual Studio let's you add references to incompatible assemblies, but then gives exactly that error.
Check your project settings to make sure you're targeting the full .net framework.
Also, check that the Ilalcar class is public and not internal (which is the default if it's only declared as class without any modifier)
You probably need an using statement to put the class into scope.
using SaglikNetClassLib;
C# won't auto suggest it if the project has not been rebuild. Also make sure the class library project has been build before using it in code.
Intellisense seems to lag behind a bit at times. Simply pressing f5 (run) sometimes rebuilds the project completely and simply runs or gives a better error message.
I'm getting this error
The type or namespace name 'DataVisualization' does not exist in the namespace 'System.Windows.Forms' (are you missing an assembly reference?)
Here is my using section of the class:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Forms.DataVisualization.Charting;
using System.Windows.Forms.DataVisualization.Charting.Borders3D;
using System.Windows.Forms.DataVisualization.Charting.ChartTypes;
using System.Windows.Forms.DataVisualization.Charting.Data;
using System.Windows.Forms.DataVisualization.Charting.Formulas;
using System.Windows.Forms.DataVisualization.Charting.Utilities;
namespace myNamespace {
public class myClass {
// Usual class stuff
}
}
The thing is that I am using the same DataVisualization includes in another class. The only thing that I can think that is different is that the classes that are giving this missing namespace error are Solution Items rather than specific to a project. The projects reference them by link. Anyone have thoughts on what the problem is? I've installed the chart component, .Net 3.5 SP1, and the Chart Add-in for Visual Studio 2008.
UPDATE: I moved the items from Solution Items to be regular members of my project and I'm still seeing the same behavior.
UPDATE 2: Removing the items from the Solution Items and placing them under my project worked. Another project was still referencing the files which is why I didn't think it worked previously. I'm still curious, though, why I couldn't use the namespace when the classes were Solution Items but moving them underneath a project (with no modifications, mind you) instantly made them recognizable. :\
You are very likely missing a reference to the DataVisualization DLL. Note that although they share the namespace of System.Windows.Forms.dll, they aren't actually contained within it.
Solution items aren't used by compiled assemblies.
http://msdn.microsoft.com/en-us/library/1ee8zw5t.aspx
"They can be referenced by projects, but are never included in solution or project builds"
As far as I know, solution folders/items are really just meant for organizing things.
Are you getting actual build errors or just squiggles? Try building and look at the output window, does it succeed or fail?
In VS 2008 SP1 C# introduced a top level error squiggling feature. It's possible that if you open the solution item version of the file it will squiggle because of a lack of default references. The solution should still build correctly though.
If this is not the case try adding the file directly to the project (no link). See if that eliminates the error. If so then we know it has to due with a linked file and it can help track down the problem.