failed to initialize DTE object - envdte

I am following a code sample in this link.
I hit a snag right on the second line:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//using EnvDTE;
namespace TwinCAT_Automation_Interface
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
//Creating TwinCAT Projects via templates (Recommended)
Type myType = System.Type .GetTypeFromProgID ("VisualStudio.DTE.12.0");
dynamic myDTE = System.Activator.CreateInstance (myType); //error right here
}
}
The error says:
Error 1 A field initializer cannot reference the non-static field,
method, or property 'TwinCAT_Automation_Interface.Main.myType'
What exactly am I doing wrong? It's the same code snippet; I just modify it a bit. Please help!!!!
OK, I got it fixed by changing it to the following:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//using EnvDTE;
namespace TwinCAT_Automation_Interface
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
public void myMethod()
{
//Creating TwinCAT Projects via templates (Recommended)
Type myType = System.Type .GetTypeFromProgID ("VisualStudio.DTE.12.0");
dynamic myDTE = System.Activator.CreateInstance (myType); // dynamic linking for DTE-object
}
}
}
The explanation is in this link. It is a compiler error.

It is a compiler error. See question for link to the answer.

Related

The type or namespace name 'Func<,>' could not be found (are you missing a using directive or an assembly reference?

Below is the sample I found from online Tutorial to host the website suing OWIN, however when I try to run on my machine, I got this error
CS0246 The type or namespace name 'Func<,>' could not be found (are you missing a using directive or an assembly reference?)
I think for using 'Func<,>' I have using System, and for IDictionary, I have using System.Collections.Generic; so I don't understand why it still can't work.
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
using AppFunc = Func<IDictionary<string, object>, Task>;
public class Startup
{
public void Configuration(IAppBuilder app)
{
var middleware = new Func<AppFunc, AppFunc>(MyMiddleWare);
app.Use(middleware);
app.Use<OtherMiddleware>();
}
public AppFunc MyMiddleWare(AppFunc next)
{
AppFunc appFunc = async (IDictionary<string, object> environment) =>
{
var response = environment["owin.ResponseBody"] as Stream;
byte[] str = Encoding.UTF8.GetBytes("My First Middleware");
await response.WriteAsync(str, 0, str.Length);
await next.Invoke(environment);
};
return appFunc;
}
public class OtherMiddleware : OwinMiddleware
{
public OtherMiddleware(OwinMiddleware next) : base(next) { }
public override async Task Invoke(IOwinContext context)
{
byte[] str = Encoding.UTF8.GetBytes(" Other middleware");
context.Response.Body.Write(str, 0, str.Length);
await this.Next.Invoke(context);
}
}
}
You need to put the AppFunc in the class so it can use the using,
Or you can use full namespace for Func, IDictionary and Task
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
// Use this
using AppFunc = System.Func<System.Collections.Generic.IDictionary<string, object>, System.Threading.Tasks.Task>;
public class Startup
{
// Or this
using AppFunc = Func<IDictionary<string, object>, Task>;
...
}
For me it was low .NET Target Framework version 2.0 of application. Changed to 4.7 (it seems minimal is 3.5).
You need to make sure you added the reference System.Runtime.CompileServices to your project as you see in here: https://msdn.microsoft.com/en-us/library/bb549151(v=vs.110).aspx the delegate is part of mscorlib assembly.

What is causing my Grid custom renderer for Xamarin.Android to throw this exception?

The exception is:
System.MissingMethodException
Constructor on type 'MyApp.Droid.MyGridRenderer' not found
The custom renderer:
using System;
using Android.Content;
using Android.Graphics;
using Android.Text;
using Android.Util;
using MyApp;
using MyApp.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(Grid), typeof(MyGridRenderer))]
namespace MyApp.Droid
{
public class MyGridRenderer : ViewRenderer<Grid, Android.Views.View>
{
protected MyGridRenderer(Context context) : base(context)
{
}
}
}
I have Visual Studio Community for Mac version 7.3.2
Just in case, this is the custom renderer for iOS, which is working ok without any constructors:
using System;
using CoreGraphics;
using CoreText;
using Foundation;
using MyApp;
using MyApp.iOS;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(Grid), typeof(MyGridRenderer))]
namespace MyApp.iOS
{
public class MyGridRenderer : ViewRenderer<Grid, UIView>
{
}
}
The signature of the constructor for Android custom renderers changed in the latest version (2.5.0) of Xamarin forms to require the context to be passed.
You can see that here in the release notes.
This is not something that is required for iOS.
Try changing protected to public.

signalr server hub error

I'm trying to create a server and a asp.net client (2 projects in one solution..).
In the server in the class where the hub is defined i get an error ...
I use visual studio 2013.
this is the startup:
using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(TestServer.Startup))]
namespace TestServer
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
// Any connection or hub wire up and configuration should go here
app.MapSignalR();
}
}
}
the hub:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
namespace TestServer
{
[HubName("ServerHub")]
class ServerHub : Hub
{
public void Send(string message)
{
Clients.All.AddMessage(message);
}
}
}
it marks Clients.All.AddMessage(message) as an error : "One or more types required to compile a dynamic expression cannot be found. Are you missing a reference?" I can't understand what reference is missing.
You need to include the Microsoft.CSharp library.
It's easy to do, under the Add Reference dialog go to the Assemblies -> Framework tab. You'll see Microsoft.CSharp listed, add it.
Hope this helps!

'newwcf.Client' does not contain a definition for 'Where'

hi i have the following code:
but i m getting an error
'newwcf.Client' does not contain a definition for 'Where'
please help..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Data;
namespace newwcf
{
public class myservice : Imyservice
{
public List<ClientDetails> getClient()
{
List<ClientDetails> client = new List<ClientDetails>();
var sql = Client.Where(cn => cn.ClientName).ToList(); //getting the error here
return sql;
}
}
}
c# is case sensitive...should you try
var sql = client.Where(cn => cn.ClientName).ToList();

BasicAuthentication not invoking my OnActionExecuting in Auth.cs - what may I have missed?

I have my controller decorated with: [BasicAuthentication] - however, putting in breakpoints, and stepping through the code, the [BasicAuthentication] never redirects to the Auth.cs (in the Filter folder):
Filter\Auth.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.Security;
namespace ebapi.Filter
{
public class BasicAuthenticationAttribute : System.Web.Http.Filters.ActionFilterAttribute
{
public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
{
So the override OnActionExecuting never executes - but I cannot see what I've missed. My controller, decorated with [BasicAuthentication] is shown below, but doesn't invoke my Auth.cs shown above:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using ebapi.Filter;
using ebapi.Models;
namespace ebapi.Controllers
{
public class GetBookingsController : ApiController
{
private GetBookingsContext db = new GetBookingsContext();
private ApiMembersContext dba = new ApiMembersContext();
// GET api/GetBookings/5
[BasicAuthentication]
public IEnumerable<GetBooking> GetBooking(long id)
{
Thanks for any help,
Mark
if this helps, I changed the
public class BasicAuthenticationAttribute name to: public class BasicAuthenticationV2Attribute
and changed the decoration to:
[BasicAuthenticationV2]
For whatever reason, this started the authentication again, and it fired with no problem.
I'm assuming there is some sort of caching going on, perhaps from the calling IP to the API - that means it remembers it's already authenticated someone, and doesn't need to again?
If anyone could confirm my thinking, I'd appreciate it.
Thank you,
Mark

Resources