Does not contain a definition for ToGridModel - c#

I can't seem to resolve the following error that states:
"System.Linq.IQueryable' does not contain a definition for
'ToGridModel' and no extension method 'ToGridModel' accepting a first argument of type
'System.Linq.IQueryable'could be found (are you missing a using directive or an assembly reference?)"
Any ideas about how I can resolve this issue?
Am I missing a "using" statement at the top of my file somewhere, or do I need to modify
ToGridModel to some other kind of command?
I'm using Telerik UI for ASP.NET Mvc, Kendo UI,
and Telerik Data Access extensions by the way.
I'm also receiving similar errors for the Viewbag as well in my Controller files.
I'm not too sure how to fix that major issue either.
Any help would be greatly appreciated. Thanks
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.IO;
using System.Text;
using System.Collections;
using Kendo.Mvc;
using KendoGridBinder;
using NPOI.HSSF.UserModel;
namespace AssetMgr_TeleMVC.Controllers
{
public class SharedController : Controller
{
// GET: Shared
// Exports the whole selected grid to csv in comma separated format
public ActionResult ExportCsv(int page, string orderBy, string filter)
{
// IEnumerable orders = GetOrders().AsQueryable().ToGridModel(page, 10, orderBy, string.Empty, filter).Data;
using (Model_OpenAccess_AssetMgr.ctx_OpenAccess_AssetMgr dbContext = new Model_OpenAccess_AssetMgr.ctx_OpenAccess_AssetMgr())
{ IEnumerable TableRows = dbContext.Assets.AsQueryable().ToGridModel(page, 10, orderBy, string.Empty, filter).Data;
MemoryStream output = new MemoryStream();
StreamWriter writer = new StreamWriter(output, Encoding.UTF8);
writer.Write("HSC TAG,");
writer.Write("Asset Name,");

The equivalent method in UI for ASP.NET MVC is ToDataSourceResult. You need to import the Kendo.Mvc.Extensions namespace.

Just add Telerik.Web.Mvc.Extensions to your 'using' section. that's all

Related

Ambiguous reference between 'Microsoft.Azure.Devices.Client.Message' and 'Microsoft.Azure.Devices.Message

I am new to c# and was using some references to code. I added a few methods that use Microsoft.Azure.Devices.Client while some methods use Microsoft.Azure.Devices. Now the message class ambiguous references and I need both the using statements. What can I do now?
the error message is:
"'Message' is an ambiguous reference between 'Microsoft.Azure.Devices.Client.Message' and 'Microsoft.Azure.Devices.Message'"
The code is:
using System;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.Devices.Client;
using Microsoft.Azure.Devices;
using Microsoft.Azure.Devices.Shared;
using Microsoft.Azure.Devices.Provisioning.Client;
using Microsoft.Azure.Devices.Common.Exceptions;
using Microsoft.Azure.Devices.Provisioning.Client.Transport;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
the message class is used as shown here:
var message = new Message(Encoding.ASCII.GetBytes(messageString));
I tried using Client.Message, but it does not work. I use python and am new to c# and am not sure how it works.
Can somebody explain in some detail, the solution?
"'Message' is an ambiguous reference between 'Microsoft.Azure.Devices.Client.Message' and 'Microsoft.Azure.Devices.Message'"
It means that both Microsoft.Azure.Devices.Client and Microsoft.Azure.Devices have a class called Message; you've imported both namespaces so C# is no longer certain what you mean when you say Message
Either remove one of the namespaces, or fully qualify Message by adding the full namespace before the name, depending on which Message class you intend to use (I can't tell either, because both of them have constructors that take a byte)
var cmessage = new Microsoft.Azure.Devices.Client.Message(...);
var dmessage = new Microsoft.Azure.Devices.Message(...);
If you'll be typing either of them a lot, you can use an alias for one or the other (if you stop importing one namespace because all you needed out of it is the message class) or both (if you carry on importing both namespaces):
using ClientMessage = Microsoft.Azure.Devices.Client.Message;
using DeviceMessage = Microsoft.Azure.Devices.Message;
Then you can say:
var cmessage = new ClientMessage(...);
var dmessage = new DeviceMessage(...);

Assimp.Net GetTextureCoords missing from Assimp.Mesh

I'm facing a very strange error in my VS2010 project that uses c# + OpenTK + Assimp.net (The packages of the last 2 are from NuGet, so I suppose them updated to their latest version)
When I try to iterate the vector3 of the UV coordinates using:
model.Meshes[n].GetTextureCoords(0)[i]
I get the following error:
error CS1061: 'Assimp.Mesh' does not contain a definition for
'GetTextureCoords' and no extension method 'GetTextureCoords'
accepting a first argument of type 'Assimp.Mesh' could be found (are
you missing a using directive or an assembly reference?)
I don't understand why! Can someone please help me?
AssimpNet is correctly referenced (I'm able to load and visualize any 3D model correctly if I comment the UV part)
And in the using part:
using System;
using System.Collections.Generic;
using System.IO; //Required by Assimp-net
using System.Reflection; //Required by Assimp-net
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTK.Platform;
using Assimp; //Required by Assimp-net
using Assimp.Configs; //Required by Assimp-net
EDIT: I also tried to change the order of the "using"s... or to remove some of them to see if there was some sort of namespace clashing but without any success
It's simply Mesh.TextureCoordinateChannels[0][i]. GetTextureCoords() does not exist. If you saw it anywhere in a tutorial, let me know where.

How to change State/Status in CRM 2013 using c#

How do I change State and/or Status of an entity in CRM 2013 using C#?
Neither CRM 2011's SetStateRequest nor the earlier SetStateDynamicEntityRequest are being recognized.
Searching online didn't seem to help either... Am I missing a namespace or something?
Thanks in advance
Namespaces:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Discovery;
using Microsoft.Xrm.Sdk.Messages;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Web.Services.Protocols;
The function:
private void changeUserStatus(Guid userId, IOrganizationService service, int state)
{
SetStateRequest setStateRequest = new SetStateRequest
{
EntityMoniker = new EntityReference("systemuser", userId),
State = new OptionSetValue(state),
Status = new OptionSetValue(-1),
};
service.Execute(setStateRequest);
}
IMPORTANT: My SetStateRequest is NOT recognized by visual studio 2012, so unlike the above example it's not highlighted and actually red underlined with the "the type or namespace not found" message displayed when hovering
Edit: I see the question got downvoted and I'm sorry if I'm missing something but I really have no more information to provide apart from the fact that I've spent 4 hours yesterday looking for this online (including stackoverflow) without any avail. I may be using the wrong search criteria or looking in the wrong places, but if that's the case could anyone at least point me in the right direction? I'm a beginner on all of this (both stackoverflow and crm2013) and I'm kind of stuck on this. Thanks again
You are not referencing microsoft.crm.sdk.proxy.dll and its namespace Microsoft.Crm.Sdk.Messages
so the code will be
using Microsoft.Crm.Sdk.Messages;
Another thing, be sure that the int values for State and Status are valid for the entity (in your case systemuser)

Problems converting VB.NET to C#

I am trying to convert some vb.net to C#, but I keep getting errors. At the moment, I am getting the following error:
The name 'Strings' does not exist in the current context
The problem line is:
strUser = Strings.LCase(Strings.Trim(strUserInitials[strUserInitials.GetUpperBound(0)])).ToString();
Anyone know why this is happening?
I have the following namespaces set:
using System;
using System.Web;
using System.Web.Services;
using System.Web.Script;
using System.Web.Script.Services;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
I am working on a webservice (asmx file).
The Strings utility class is in the Microsoft.VisualBasic namespace.
You can add a reference to the library and use it from your C# code, or rewrite the calls:
strUser = strUserInitials[strUserInitials.GetUpperBound(0)].ToString().Trim().ToLower();
In c# there is no Strings class in System namespace. and in the string change LCase to ToLower, So:
strUser = string.ToLower(string.Trim(strUserInitials[strUserInitials.GetUpperBound(0)]));

'namespace used like a type' error when converting XAML to HTML

Coders, I am trying to convert a XAML string to HTML using a library I found here , but I have a problem with creating a new instance of the object that would let me use the library. I already added a reference to the library in my Asp.net project and I would like to use it in a WCF file.
The problem is that whenever I try to instantiate a new object with the new keyword, I get an error that says:
'MarkupConverter' is a 'namespace' but is used like a 'type'.
Here is my code, notice that I am creating a new object just like the example shown in the library link above, please help:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Web.Services;
using System.Net.Mail;
using System.ServiceModel.Activation;
using System.Data.SqlClient;
using MarkupConverter;
namespace AspPersonalWebsite
{
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1 //: IService1
{
private string connectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
private IMarkupConverter markupConverter;
[OperationContract]
public string convertXAMLToHTML(string XAMLtext)
{
string htmlText = "";
markupConverter = new MarkupConverter(); /*PROBLEM IS HERE*/
htmlText = markupConverter.ConvertXamlToHtml(XAMLtext);
return htmlText;
}
}
}
Confusion is arising because the actual type is MarkupConverter.MarkupConverter, the compiler seems to think your new MarkupConverter is an attempt to use a namespace as a type, rather than an attempt to instantiate a type inside your using namespace.
Simply change your problem line to:
markupConverter = new MarkupConverter.MarkupConverter(); /*SOLUTION HERE!*/
..and you should be fine.
In your case, you have a namespace MarkupConverter and a class with the same name (MarkupConverter again).
In the line markupConverter = new MarkupConverter(); /*PROBLEM IS HERE*/ the compiler is unable to tell that you intent to use the class. Since a namespace with the same name is present, the compiler picks it instead, because namespaces are linked with higher priority by the compiler.
You can resolve this by using the complete name of the class:
// supposedly MarkupConverter is the namespace of the MarkupConverter class
markupConverter = new MarkupConverter.MarkupConverter();
An alternative way to providing the fully-qualified name of the class is to use an alias, which takes the form of using {ALIAS} = {Fully qualified name of Type| Namespace}. Note that the {ALIAS} part can be any valid identifier.
The alias you can place either in your usings:
using System.Net.Mail;
using System.ServiceModel.Activation;
using System.Data.SqlClient;
using MarkupConverter;
using MarkupConverter = MarkupConverter.MarkupConverter; // this is aliasing
or after the namespace declaration:
using System.Data.SqlClient;
using MarkupConverter;
namespace AspPersonalWebsite
{
using MarkupConverter = MarkupConverter.MarkupConverter;
....
and you're good to go! At this point, if aliases are present, the line
markupConverter = new MarkupConverter()
will correctly pick the MarkupConverter class, because explicit aliasing has higher priority than the automatic binding done by the compiler.
That is pretty much self explanatory,
MarkupConverter is a namespace ,so shouldn't be used as a class to create an object
Can you show the MarkupConverter class you use please? The error is maybe in its declaration. In Where namespace is it? What is your file structure?
Maybe you have created a MarkupConverter namespace?
You should add a "using MarkupConverter" statement in the usings section. That will import all classes from that namespace.

Categories