I needed to make a console application using nettiers class libraries. I created a new Console Application project, added references to all the libraries from NetTiers and created an app.config file with all the necessary configurations. I get intellisense and no errors and everything when I am doing the coding, but when I go to compile the application, I'm getting an error that PPGEDI.Data doesn't exist.
I only have 1 line in the program.cs Main method:
PPGEDI.Entities.VansEntity van
= DataRepository.VansEntityProvider.GetById(16);
I'm getting the following error:
Error 93
The type or namespace name 'Data'
does not exist in the namespace 'PPGEDI'
(are you missing an assembly reference?)
It's frustrating, because I know I've added the assembly reference:
I'm using Visual Studio 2010, with C# and .NET 4.0. Can anyone give me an idea as to what I need to do to get this to work.
As a note, this works if I use the same statement in a method on an ASPX page in the web application generated by nettiers.
#BrokenGlass, you were absolutely correct. I double checked and it was
set to ".NET Framework Client Profile", I changed it to .NET 4 and
it's working now, can you put that as an answer?
You are using the .NET client profile in your console app which is a "minified" version that doesn’t contain all assemblies.
The problem is that when your app adds a reference to a class library that is targeting the full framework, references to the "full" framework assembly will not resolve. This results in the rather non-forthcoming error message that you see. Switching to the the full .NET 4 as target framework will resolve the issue.
For a more in depth overview of the problem and the .NET 4 Client Profile in general also see "What’s new in .NET Framework 4 Client Profile RTM"
Related
My Blazor standalone application .Net 5.0 generates a wrong MvcApplicationPartsAssemblyInfo.cs with the following content if I add a project reference to it:
[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartAttribute("Wur.GroupTool.Core")]
Giving the following error (note the double 'AttributeAttribute'):
Error CS0234 The type or namespace name 'ApplicationPartAttributeAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Mvc.ApplicationParts' (are you missing an assembly reference?) Wur.GroupTool.Blazor C:\Projects\FB-IT\grouptool\sources\Wur.GroupTool\Wur.GroupTool.Blazor\obj\Debug\net5.0\Wur.GroupTool.Blazor.MvcApplicationPartsAssemblyInfo.cs 14 Active
My guess is that the attribute shoule be:
[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPart("Wur.GroupTool.Core")]
but since it is generated I have no clue how to handle this problem. Tried changing the code of course but on compilation it is regenerated again and hence the error again.
== EDIT ==
Just started from scratch again using this command:
dotnet --dry-run new blazorwasm -au SingleOrg --framework:net5.0
Changed the library to insert to starget net5.0. Issue stays the same. It could be a bug in the compiler. When 'Attribute' is added it should use that name but instead it adds 'Attribute' to the name resulting to 'AttributeAttribute'.
The answer here is as follows. In the Library I wanted to add some MVC libraries were present. Blazor does not like loading MVC libraries, they don't mix well. The error was misleading. But after removing all code that uses MVC from the library (which should not have been in there in the first place) the reference was accepted just fine.
This has been bugging me all day and I have yet to figure out why this is happening.
Basic scenario
Created a new Service Fabric Application with an ASP.NET Core service and added support for returning MVC views so that it can act as the UI for my SF App.
Added an Actor service for users to the solution which created the UserActor and UserActor.Interfaces projects and ensured that the Interfaces library targets x64 as required by SF.
Defined a Task<UserProfile> GetProfileData() method on the UserActor where the UserProfile type is a concrete class defined in the Interfaces project with the [DataContract] and [DataMember] attributes so that it can be serialized (all members are primitives).
Added a project reference to the UserActor.Interfaces from the ASP.NET Core project so I could create the actor proxy and invoke the method.
Added the code in the ASP.NET Core Controller class to connect to the actor instance and invoke the GetProfileData method
At this point, I receive the following compiler error:
error CS0246: The type or namespace name 'UserProfile' could not be found (are you missing a using directive or an assembly reference?)
The relevant lines of code are as follows:
using UserActor.Interfaces;
var user = ActorProxy.Create<IUserActor>( new ActorId( model.email ), FabricAppUrl );
UserProfile profile = user.GetProfileData().Result; // compiler error here
If I hover over the UserProfile type on the last line, Visual Studio shows me it sees the type as UserActor.Interfaces.UserProfile and doesn't show any errors in the editor. It's only when I compile that this error shows up.
I didn't receive this error when trying to return a primitive type and it had no problem resolving the IUserActor interface for the Actor Proxy either.
Does this have something to do with the fact the the Actor projects are standard .NET projects and the ASP.NET Core project is compiled using dotnet build (set to .NETFramework,Version=v4.5.2; not dotnet core).
I also noticed in the build output that the ASP.NET Core project is building as 'Debug Any CPU' while all of the other projects are set to 'Debug x64'. If this were the issue I would expect to receive an error about mis-matched architecture types, but I'm not getting that either.
How can I resolve this? Should I be returning the data from the Actor in a different manner (such as json serializing it before returning it as a string primitive)?
Edit 1:
The code sample above was too simplistic. The 2 compiler errors I am seeing are around the type being passed to a helper method in the same controller as follows:
private bool TryGetUserProfile( LoginModel model, out UserProfile profile )
{
var user = ActorProxy.Create<IUserActor>(new ActorId(model.Email), FarbicAppUrl);
var profile = user.GetProfileData().Result;
return !string.IsNullOrEmpty(profile.Name);
}
OK, after starting the whole scenario out on a different machine I found what the problem is and believe it to be a Microsoft tooling issue. Here are the steps to reproduce the problem along with what needs to be done to correct it.
Create a new Service Fabric project and select ASP.NET Core as the service. If prompted, select the Web Application Template (but I think this would be an issue if you selected the Empty or Web API templates as well). If you debug this, it will work just fine (provided you have a local cluster setup).
Add a new Actor Service to the solution. This will create the UserActor and UserActor.Interfaces projects for you. If you try to compile at this point, you will receive the following error message:
C:\Program Files (x86)\MSBuild\bin\Microsoft.Common.CurrentVersion.targets(724,5): error : The OutputPath property is not set for project 'UserActor.Interfaces.csproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Debug' Platform='AnyCPU'. This error may also appear if some other project is trying to follow a project-to-project reference to this project, this project has been unloaded or is not included in the solution, and the referencing project does not build using the same or an equivalent Configuration or Platform.
Checking the Configuration Manager shows that there is only an 'x64' target defined for the project. To get around this, use the Configuration Manager and add a new 'AnyCPU' target and copy it from the 'x64' target. Ensure that the target platform is still set to 'x64' for the interfaces project before closing the Configuration Manager since Service Fabric requires x64 assemblies.
Now when you compile, you will receive the following error message:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets(262,5): error : C:\...\Web error CS0006: Metadata file 'C:\...\UserActor.Interfaces\bin\Debug\UserActor.Interfaces.dll' could not be found.
The clue here is that the web project is looking in the OutputPath location defined for the 'AnyCPU' target and not the location defined for the 'x64' target (bin\x64\Debug). If you manually edit the interfaces project file and set the OutputPath for the 'AnyCPU' target to the same path as the 'x64' target, everything will compile properly.
You can also deploy the project and everything will work as it should. I'm not sure which target file from Microsoft has the problem in it, but it could be both. I'll look into reporting this as a bug with Microsoft in the hopes of getting it resolved (still present with the latest SDK released on 2/3/2017).
The reason the UserProfile type couldn't be found for me was because I had previously built the solution with the wrong OutputPath set before I added the UserProfile class to the project so the compiled DLL that MSBuild was looking at didn't contain the type. If I had removed the bin & obj folders from the solution, it would have become obvious where the problem was right away.
I am trying to make an asynchronous client for Windows Phone using this code http://msdn.microsoft.com/en-us/library/bew39x2a.aspx in Visual Studio 2010 but I get 22 errors for using things like IPHostEntry and BeginConnect although I copied the code exactly. Any ideas?
Thanks
Edit
The three different types of errors I'm getting are below. most of them are the third one with sockets.socket
Error 1 The type or namespace name 'IPHostEntry' could not be found (are you missing a using directive or an assembly reference?)
Error 2 The name 'Dns' does not exist in the current context
Error 3 System.Net.Sockets.Socket' does not contain a definition for 'BeginConnect' and no extension method 'BeginConnect' accepting a first argument of type 'System.Net.Sockets.Socket' could be found (are you missing a using directive or an assembly reference?)
You may be missing a reference. Verify that the appropriate DLLs have been identified as project references.
You should check to see if your project is using the correct version of .Net. In .net 4.0 there is both a "client" and "full" version. Typically when you create a new .Net project in Visual Studio the project is created and referencing the "client profile" .net. Honestly, this gets me every time.
You can change this by doing the following (Visual Studio 2010):
Right click the project in Visual Studio Solution Explorer and select "Properties"
Make sure the "Application" tab is selected
View / Change the "Target Framework:" from ".NET Framework _ Client Profile" to ".NET Framework _"
rebuild your project :-)
Here's a good link explaining the difference between the client profile and the full profile: Differences between Microsoft .NET 4.0 full Framework and Client Profile
The code is missing a namespace before it is declaring classes.
namespace YourNamespace
{
// State object for receiving data from remote device.
public class StateObject { ...
Also you may be missing namespaces for stuff the code is using. Click on the classes that are highlighted with red squigglies and press ctrl + . and it should give suggestions for namespaces.
I encountered the same issue today. I think it's because VS2010 Express WP created my project using 2.0 .NET framework, I don't know why, I want to use 7.8, but I have only choice between 7.0 and 7.1. I can't change .Net framework version for use the 4.0/4.5, I have only one choice and it's windows phone 7.1, I can't choose the version of the framework separately...
I've created a Class Library project called Core. The default namespace is XXX.Tasker.Core.
I've created another Console project which references Core. In my Main() I've got some calls to stuff inside the Core but I'm getting an error:
The type or namespace name 'Core' does
not exist in the namespace
'XXXX.Tasker' (are you missing an
assembly reference?)
The only thing I can think of is that the fact my assembly name is Core might be confusing it.. but that really doesn't make much sense.
Any other suggestions?
The problem turned out to be that Core was compiled as .Net Framework 4 and the Console was .Net Framework 4 Client Profile. Apparently you'll just get really weird errors instead of a proper notification when this occurs.. thanks MS! ;)
I have a class library project that references another class library. The project fails to build and I get the error 'The type or namespace name 'ReportLibrary' does not exist in the namespace 'MSF' (are you missing an assembly reference?)'
The weird part is that I have other projects referencing the same class library that build fine. The only difference is that they are Windows Application projects. If I change the project type to a Windows Application and add a Program.cs with a [STAThread] and it builds.
So WTF? Anybody know what I'm doing wrong?
Edit (More Details): All projects in the solution are set to the same Target Framework: .NET Framework 3.5
EDIT (Unobfuscated the error message per Hans)
Is the class library (with the error) targeting the Client Profile, and the applications (as well as the reference library) targeting the full framework? If so, this could cause the reference to be invalid, and cause that message.