Why do I get this error in a WebServices project? - c#

I have a ClickOnce app that accesses a bunch of web services. On the client, I have one project that wraps all the web services.
In the Properties for that project, if Build/Generate Serialization Assembly is Auto (which is the default), then everything works fine. I set the option to On, it compiles fine, then during runtime I get this error:
Line 786: [WebMethod]
Line 787: public CC.DTO.AdvertiserAssignmentRevenueDTO[] SearchAdvertiserAssignmentRevenue(byte[] AdvAssgnRevenueSearchFilter)
Line 788: {
Line 789: try
The Detailed Compiler Output is basically "CS0234: The type or namespace name 'DTO' does not exist in the namespace 'CC' (are you missing an assembly reference?)"
Why is this happening?
Just FYI, this is a .NET 2.0 project running in VS2008.

I had a very similar error message with the same symptoms. For me it would even run locally but not on a different server. It turned out I was missing a data contract declaration on one of my methods.
[DataContract (Namespace = ...)]
Double check your methods on the service and client to ensure they have all the needed attributes and declarations.

Related

Blazor application generates wrong MvcApplicationPartsAssemblyInfo.cs

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.

Compiler error referencing Service Fabric Actor class from ASP.NET Core service

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.

The type 'StringPro.IMyString' is defined in an assembly that is not referenced

I receive this error when trying to run the client.
The type 'StringPro.IMyString' is defined in an assembly that is not referenced.
This error comes from, StringProClient from file Program.cs and underlines in blue the following first line of code:
StringProProxy.StringProProxy proxy = new StringProProxy.StringProProxy();
The solution has 4 projects inside:
StringPro - Class Library that contains the service's interface(IMyString.cs) and the implementation class(MyString.cs)
StringProHost - Console Application that has Program.cs inside which defines Uri, ServiceHost, Endpoint, ServiceMetadataBehaviour, HttpGetEnabled, host.Description.Behaviours, calls host.Open() and displays in console information about when the service was started
StringProProxy - I believe it's a Class Library project since it has only StringProProxy.cs which defines the service's proxy
StringProClient - Console Application which instantiates the service's proxy inside, call the service's functions and displays results.
EDIT: The service host launches fine. It's the client that won't build and run because of the mentioned error.
If a project is using a type that was declared in other assembly, this assembly must be referenced - this is basically what your error is telling you.
In your case, I'm guessing that StringProClient is referecing StringProProxy, but it is also using types declared in StringPro project (to be exact: IMyString interface/class), without referencing it. You should make sure, that StringProClient references both, StringProProxy and StringPro.
Such problem mostly arises with the issues like namespace only. Kindly check your references as well as namespaces again.

nettiers data class library not recognized

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"

VS2010 Reference Resolves in Windows Application but not in Class Library

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.

Categories