1

I am trying to publish the component using core service, to do this, I just created a console application, and executed from the server. I am getting the below error message.

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Tridion.ContentManager.CoreService.Client, Version=6.1.0.996, Culture=neutral, PublicKeyToken=ddfc895746e5ee6b' or one of its dependencies. The system cannot find the file specified.

The below is my code, can anyone faced this issue?

static void Main(string[] args)
{

    try
    {
        string compid = "tcm:56-935";

        var client = new SessionAwareCoreServiceClient();
        var readoption = new ReadOptions();
        var component = (ComponentData)client.Read(compid, readoption);
        var ItemToPublish = new List<string>();
        ItemToPublish.Add(component.Id);
        var instruction = new PublishInstructionData();
        var pubtarget = (PublicationTargetData)client.Read(
                                               "tcm:0-21-65537", readoption);
        List<string> target = new List<string>();
        target.Add(pubtarget.Id);
        client.Publish(ItemToPublish.ToArray(), instruction, target.ToArray(), 
                       PublishPriority.Normal, readoption);
        Console.WriteLine("component published");
        Console.WriteLine(component.Title);
        Console.WriteLine(pubtarget.Title);
        Console.ReadLine();

    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
        Console.ReadLine();
    }
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Jey
  • 2,137
  • 4
  • 22
  • 40

2 Answers2

4

The error is clear, it says that you don't have dependency in place. You must place Tridion.ContentManager.CoreService.Client.dll into the same directory where your executable is (alternatively, you can place in GAC). Usually there is an option in Visual Studio on referenced assembly on your project "Copy Local", you can try to to set it to true and try to execute your code again.

Igor Paniushkin
  • 396
  • 1
  • 4
  • I have tried to cope the client.dll inthe same location, but am getting the belwo error. "Could not find default endpoint element that references contract 'Tridion.contentManager.CoreService.Client.IsessionAswarecoreService' in the ServiceModel client configuration section. This might be becuase no configuration file was found for your application, or becuase no endpoint element matching this contract could be found inthe Client element". – Jey Jul 09 '12 at 09:47
  • Once you get that error, Jeremy is right: you are missing a config file. Did you follow step 3 in this help topic (login required)? (http://sdllivecontent.sdl.com/LiveContent/content/en-US/SDL_Tridion_2011_SPONE/task_B49EC308F06D48E19230A2EC6070E14E) – Frank van Puffelen Jul 09 '12 at 11:04
  • @Frank: I have copied the mentioned configuration file from the mentioned directory and created new app.config file in to my solution. and changed the code var client = new CoreServiceClient(); instead of var client = new SessionAwareCoreServiceClient(); now am getting the error "The requested service 'http://localhost/webservices/CoreService2011.svc/basicHttp' could not be activated. – Jey Jul 09 '12 at 11:17
  • That typically means that there is an additional error in the Windows event viewer about the reason the activation failed. In addition, check what happens when you simply open http://localhost/webservices/CoreService2011.svc in a browser on the same machine where you're running your program. – Frank van Puffelen Jul 09 '12 at 12:38
  • Server Error in '/webservices' Application. Could not find a base address that matches scheme https for the endpoint with binding WSHttpBinding. Registered base address schemes are [http]. – Jey Jul 09 '12 at 12:48
  • It sounds like your client and server config are mismatched: one uses HTTPS, the other HTTP most likely. Check them and use Google as your friend. – Frank van Puffelen Jul 09 '12 at 18:04
3

Looks like (based on your comment to Igor's answer) you're missing some config. Check out Frank's wiki post on the Tridion Practice site - https://code.google.com/p/tridion-practice/wiki/GetCoreServiceClientWithoutConfigFile

Jeremy Grand-Scrutton
  • 2,802
  • 14
  • 20
  • Is that mandatory to have that class in my console application? do i need to do anything in the config or assemblyinfo.cs? – Jey Jul 09 '12 at 10:52
  • It's **your** choice to either use an app.config file for the configuration or to specify the necessary values in code as in the page Jeremy links to. But given the problems that you have, I'd for now stick to what you are trying already and simply use an app.config – Frank van Puffelen Jul 09 '12 at 11:03