Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WordPressSharp with ASP.Net Core 2.1 #93

Open
kombasltd opened this issue Aug 13, 2018 · 4 comments
Open

WordPressSharp with ASP.Net Core 2.1 #93

kombasltd opened this issue Aug 13, 2018 · 4 comments

Comments

@kombasltd
Copy link

kombasltd commented Aug 13, 2018

Hi,

as I mentioned in another issue, I am evaluating WordPressSharp to use it in a new application of mine (used Joe Blogs in WinForms app for now). Now I am developing a web app with ASP.Net Core 2.1 MVC and I am struggeling.

The following code works fine in a WinForm app but not in my MVC app:

using WordPressSharp.Models;
using WordPressSharp;

public bool WPPostTest()
{
	var post = new Post
	{
		PostType = "post", // "post" or "page"
		Title = "Using WordPressSharp",
		Content = "WordPressSharp is a C# utility for interfacing with the WordPress XML-RPC API",
		PublishDateTime = DateTime.Now,
		Status = "publish" // "draft" or "publish"
	};

	var client = new WordPressClient(new WordPressSiteConfig
	{
		BaseUrl = "https://wptest.kombas.de",
		BlogId = 1,
		Username = "USERNAME",
		Password = "PASSWORD"
	});

	using (client)
	{
		var id = client2.NewPost(post);
	}

	return true;
}

Exception is:

An unhandled exception occurred while processing the request.
MissingMethodException: Method not found: 'System.Reflection.Emit.AssemblyBuilder System.AppDomain.DefineDynamicAssembly(System.Reflection.AssemblyName, System.Reflection.Emit.AssemblyBuilderAccess)'.
CookComputing.XmlRpc.XmlRpcProxyGen.BuildAssembly(Type itf, string assemblyName, string moduleName, string typeName, AssemblyBuilderAccess access)

Stack Query Cookies Headers
MissingMethodException: Method not found: 'System.Reflection.Emit.AssemblyBuilder System.AppDomain.DefineDynamicAssembly(System.Reflection.AssemblyName, System.Reflection.Emit.AssemblyBuilderAccess)'.
CookComputing.XmlRpc.XmlRpcProxyGen.BuildAssembly(Type itf, string assemblyName, string moduleName, string typeName, AssemblyBuilderAccess access)
CookComputing.XmlRpc.XmlRpcProxyGen.Create(Type itf)
WordPressSharp.WordPressClient..ctor(WordPressSiteConfig siteConfig)
komBASSEOServices.Controllers.WordPressProjectsController.WPPostTest() in WordPressProjectsController.cs
+
var client2 = new WordPressClient(new WordPressSiteConfig
lambda_method(Closure , object , object[] )
Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(object target, object[] parameters)
Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor+SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Do you have any idea?

Thanks,
Kay

@abrudtkuhl
Copy link
Owner

abrudtkuhl commented Aug 14, 2018 via email

@kombasltd
Copy link
Author

kombasltd commented Aug 14, 2018

Oh my bad, sorry. I edited the source here. Of course it's "client" and not "client2".

I continued to try but there seems to be a general problem within an ASP.NET MVC app, even in the simplest form. The problem seems to be this one here:

MissingMethodException: Method not found: 'System.Reflection.Emit.AssemblyBuilder System.AppDomain.DefineDynamicAssembly(System.Reflection.AssemblyName, System.Reflection.Emit.AssemblyBuilderAccess)'.
CookComputing.XmlRpc.XmlRpcProxyGen.BuildAssembly(Type itf, string assemblyName, string moduleName, string typeName, AssemblyBuilderAccess access)

But at the moment I have no clue if the exception comes from xmp-rpc.net or WordPressSharp?

@kombasltd
Copy link
Author

I'll give it another try ;-)

Maybe you or someone else can confirm the following test:

  1. Clone repository here
  2. Create a new ASP.NET Core MVC App with .NET Core 2.1
  3. Reference the two assemblies (WordPressSharp.dll and CookComputing.XmlRpcV2.dll) from 1.
  4. Add the code below into the About method in HomeController (change blog Url and username and password)
  5. Run the project and call the about page
public IActionResult About()
{
	// create a new Post in WordPress
	var post = new Post
	{
		PostType = "post", // "post" or "page"
		Title = "Using WordPressSharp",
		Content = "WordPressSharp is a C# utility for interfacing with the WordPress XML-RPC API",
		PublishDateTime = DateTime.Now,
		Status = "publish" // "draft" or "publish"
	};      

	var client = new WordPressClient(new WordPressSiteConfig
	{
		BaseUrl = "http://yourwpblog",
		BlogId = 1,
		Username = "username",
		Password = "password"
	}
	);

	using (client)
	{
		var id = client.NewPost(post);
	}

	ViewData["Message"] = "Your application description page.";
	return View();
}

Which results here in a

MissingMethodException: Method not found: 'System.Reflection.Emit.AssemblyBuilder System.AppDomain.DefineDynamicAssembly(System.Reflection.AssemblyName, System.Reflection.Emit.AssemblyBuilderAccess)'.
CookComputing.XmlRpc.XmlRpcProxyGen.BuildAssembly(Type itf, string assemblyName, string moduleName, string typeName, AssemblyBuilderAccess access)
CookComputing.XmlRpc.XmlRpcProxyGen.Create(Type itf)
WordPressSharp.WordPressClient..ctor(WordPressSiteConfig siteConfig) in WordPressClient.cs
+
WordPressService = (IWordPressService)XmlRpcProxyGen.Create(typeof(IWordPressService));
WPSharpTest.Controllers.HomeController.About() in HomeController.cs
+
var client = new WordPressClient(new WordPressSiteConfig
lambda_method(Closure , object , object[] )
Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(object target, object[] parameters)
Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor+SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

It would be very kind when I could get a confirmation because I can stop to fiddle around with this.

Best regards,
Kay

@abrudtkuhl
Copy link
Owner

abrudtkuhl commented Aug 18, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants