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();
}
}
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.
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
Related
I'm trying to dynamically load assemblies at runtime in .NET Core by essentially looking in an external folder and loading assemblies from there. Loading seems to work fine, however, i can't seem to instantiate the now loaded types in a .NET Core application.
I'm using the the following loading code (very basic for feasibility testing at this point):
private void LoadPrivateBinAssemblies()
{
var binPath = Path.Combine(WebRoot, "PrivateBin");
if (Directory.Exists(binPath))
{
var files = Directory.GetFiles(binPath);
foreach (var file in files)
{
if (!file.EndsWith(".dll", StringComparison.CurrentCultureIgnoreCase) &&
!file.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase))
continue;
try
{
var asm = AssemblyLoadContext.Default.LoadFromAssemblyPath(file);
//var asm = Assembly.LoadFrom(file);
Console.WriteLine("Additional Assembly: " + file);
}
catch (Exception ex)
{
Console.WriteLine("Failed to load private assembly: " + file);
Console.WriteLine(" " + ex.Message);
}
}
}
}
Note - I am using AssemblyLoadContext.Default to load into the .NET Core default context, from which I would presumably be creating a new type.
Then - for testing I now explicitly try to instantiate a type like this at the bottom of the Configure() startup sequence:
LoadPrivateBinAssemblies();
// this has my loaded assemblies in it
var list = AssemblyLoadContext.Default.Assemblies;
try
{
// this works
var t = Type.GetType(typeof(Startup).FullName);
// fails - Markdig is loaded and has no dependencies
var t2 = Type.GetType("Markdig.Markdown", true); // fails
// fails
var md = Type.GetType("Westwind.AspNetCore.Markdown.Markdown", true);
// never get here
md.InvokeMember("Parse", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static, null, null, new object[] { "**asdasd**", false, false, false });
}
catch (Exception ex)
{
Console.Log($"{ex.message}");
}
I've verified that the types exist in the assemblies and that the names are correct, but it fails on several custom loaded assemblies.
The figure shows the list of loaded assemblies (here from AppDomain.GetAssemblies(), but I get the same list from AssemblyLoadContext.Default.Assemblies). The assemblies are loaded, but I can't get a type reference to the types contained within it.
Any ideas what I'm missing here?
You need to use the assembly qualified name so, Type.GetType("Namespace.TypeName, AssemblyName").
I use fileUpload control and i can save the image but when i try to delete it gives a security error like this :
Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
it works in my localhost but not in web.
I tried to add many kind of stuff to web config file but it didnt work i dont know why.
Why i can save file but cant delete. It might be about System.Security.Permissions.FileIOPermission maybe... here is my code :
protected void btnDelete_Click(object sender, EventArgs e)
{
try
{
if (!String.IsNullOrEmpty(imgLogo.ImageUrl))
{
int index = imgLogo.ImageUrl.LastIndexOf('.');
string fileExt = imgLogo.ImageUrl.Substring(index);
string defPath = Business.DefinitionsData.getDefaultLogoPath();
string entId = ((xOrgProject.DataAccess.EnterpriseUserTable)Session["Enterprise"]).EnterpriseUserId.ToString();
string FullPath = Server.MapPath(defPath) + entId + fileExt;
FileInfo file = new FileInfo(FullPath);
if (file.Exists)
{
file.GetAccessControl();
file.Delete();
Business.DefinitionsData.UpdateEntLogoPath(int.Parse(entId), null);
imgLogo.ImageUrl = null;
imgLogo.Visible = false;
btnDelete.Visible = false;
btnUpload.Visible = true;
Fu1.Enabled = true;
StatusLabel.Text = "Kaldırıldı.";
}
}
}
catch (Exception ex)
{ StatusLabel.Text = ex.Message; }
}
As it runs fine locally the issue is most likely due to the configuration on the web server. Or in my experience this has often been the case.
Have you tried modifying the trust level in the machine.config file on the web server?
Also what authentication are you using on the web server?
Running it locaally you will have access to your machine but if you are using impersonation on the web server that anonymous account ID may not have the relevant server permissions to delete files which will throw a security exception.
thank you for your answer, i got my solution. I have wrote this code in uploading button click event then its solved. I wasnt disposing before. but now its good. thanks again.
System.Drawing.Image img = System.Drawing.Image.FromFile(save);
img.Dispose();
I have implemented a custom test type for Visual Studio. The custom test type reads its test elements from dlls. My ITip implementation is working like a charm. The test elements are loaded and are displayed on the Test View tool window.
When I select the test elements and run them they end up in a Not Executed status. While debugging this issue I found out that a FileNotFoundException is thrown from QTAgent32.exe. It tells me that it cannot find the dll that defines the test cases. Also, it fails before my TestAdapter.Initialize method is called. I copied my test dll to the PrivateAssemblies directory of Visual studio. When I do that my test elements pass. I can also debug the code in my custom test adapter. So, the meaning of all of this is that QTAgent32.exe cannot find my test dll in its original directory.
My question is what should I do to make QTAgent32 find my test dll in the original directory? For completenes I add my Tip Load method code:
public override ICollection Load(string location, ProjectData projectData, IWarningHandler warningHandler)
{
Trace.WriteLine("Started RegexTestTip Load.");
if (string.IsNullOrEmpty(location))
{
throw new ArgumentException("File location was not specified!", "location");
}
var fileInfo = new FileInfo(location);
if (!fileInfo.Exists)
{
throw new ErrorReadingStorageException(
string.Format("Could not find a file on the specified location: {0}", location));
}
var result = new List<ITestElement>();
var extension = fileInfo.Extension.ToLower();
if (extension != ".dll")
{
return result;
}
Assembly testAssembly = Assembly.LoadFrom(location);
var testClasses = testAssembly.GetTypes().
Where(t => Attribute.IsDefined(t, typeof(RegexTestClassAttribute)));
foreach (Type testClass in testClasses)
{
PropertyInfo property = testClass.GetProperties().
SingleOrDefault(p => Attribute.IsDefined(p, typeof(TestedRegexAttribute)));
if (property == null || !TestedRegexAttribute.Validate(property))
{
throw new InvalidDataInStorageException("A Regex test must define a Tested Regex property with type Regex");
}
var testCases = testClass.GetProperties().
Where(p => Attribute.IsDefined(p, typeof(RegexTestCaseAttribute)));
foreach (PropertyInfo testCase in testCases)
{
if (!RegexTestCaseAttribute.Validate(testCase))
{
throw new InvalidDataInStorageException("A test case property must return a String value.");
}
var testElement = new RegexTestElement(property, testCase);
testElement.Storage = location;
testElement.Name = testCase.Name;
testElement.Description = "A simple description";
testElement.ProjectData = projectData;
result.Add(testElement);
}
}
Trace.WriteLine("Finished RegexTestTip Load.");
return result;
}
Have you tried just putting the dll in the same directory as the executable? Forgive the obviousness of that, but sometimes its the really simple things that bite us. But it's in the GAC right?
I use VS2010, C#, ASP.NET to read outlook email. I've setup outlook express 6 with my gmail (IMAP), I get a strange exception at the first line, where my COM object is being created, here is my code:
Microsoft.Office.Interop.Outlook.Application app = null;
Microsoft.Office.Interop.Outlook._NameSpace ns = null;
Microsoft.Office.Interop.Outlook.PostItem item = null;
Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = null;
Microsoft.Office.Interop.Outlook.MAPIFolder subFolder = null;
try
{
app = new Microsoft.Office.Interop.Outlook.Application();
ns = app.GetNamespace("MAPI");
ns.Logon("gmail_id", "gmail_pass", false, true);
inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
subFolder = inboxFolder.Folders["MySubFolderName"]; //folder.Folders[1]; also works
Console.WriteLine("Folder Name: {0}, EntryId: {1}", subFolder.Name, subFolder.EntryID);
Console.WriteLine("Num Items: {0}", subFolder.Items.Count.ToString());
for (int i = 1; i <= subFolder.Items.Count; i++)
{
item = (Microsoft.Office.Interop.Outlook.PostItem)subFolder.Items[i];
Console.WriteLine("Item: {0}", i.ToString());
Console.WriteLine("Subject: {0}", item.Subject);
Console.WriteLine("Sent: {0} {1}", item.SentOn.ToLongDateString(), item.SentOn.ToLongTimeString());
Console.WriteLine("Categories: {0}", item.Categories);
Console.WriteLine("Body: {0}", item.Body);
Console.WriteLine("HTMLBody: {0}", item.HTMLBody);
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
}
finally
{
ns = null;
app = null;
inboxFolder = null;
}
it is my exception:
Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
this exception is create at the first line:
app = new Microsoft.Office.Interop.Outlook.Application();
I've used Microsoft.Office.Interop.Outlook.dll file as my interop reference, what is going wrong here? I can read my Gmail inbox in outlook express 6, but I have no luck in my ASP.NET web app
Try configuring the appropriate COM Activation permissions for Office apps to run under ASP.NET.
Firstly, you should not ever use any Office app (Outlook included) in a service (such as IIS). No exceptions, it is simply not supported.
Secondly, if you are using the Outlook Object Model (not in a service), you need to have Outlook (the real one) intalled. OE has nothing in common witt Outlook 2010/2007/2003/etc., except for the word "Outlook" in the name.
I uploaded nopcommerce solution to appharbor (using this method Can't build notcommerce project under appharbor) and solution succesfully builded, but I receiving 403 error - Forbidden: Access is denied when trying to open page(Allow write-access to file system is set to true).
Thanks and hope for your help
The problem is that the standard NopCommerce solution contains two Web Projects. AppHarbor only deploys one web project per application, and in this case, we happen to deploy Nop.Admin which is not what you want.
To resolve this, you should take advantage of the AppHarbor solution file convention and create an AppHarbor.sln solution file that only references the Nop.Web project.
We use a wrapper in our base controller to ensure that all of our code is oblivious to appharbor port changing.
First, fix in Webhelper.cs:75
public virtual string GetThisPageUrl(bool includeQueryString, bool useSsl)
{
string url = string.Empty;
if (_httpContext == null)
return url;
if (includeQueryString)
{
string storeHost = GetStoreHost(useSsl);
if (storeHost.EndsWith("/"))
storeHost = storeHost.Substring(0, storeHost.Length - 1);
url = storeHost + _httpContext.Request.RawUrl;
}
else
{
#if DEBUG
var uri = _httpContext.Request.Url;
#else
//Since appharbor changes port number due to multiple servers, we need to ensure port = 80 as in AppHarborRequesWrapper.cs
var uri = new UriBuilder
{
Scheme = _httpContext.Request.Url.Scheme,
Host = _httpContext.Request.Url.Host,
Port = 80,
Path = _httpContext.Request.Url.AbsolutePath,
Fragment = _httpContext.Request.Url.Fragment,
Query = _httpContext.Request.Url.Query.Replace("?", "")
}.Uri;
#endif
url = uri.GetLeftPart(UriPartial.Path);
}
url = url.ToLowerInvariant();
return url;
}
So what we did is simply add files from https://gist.github.com/1158264 into Nop.Core\AppHarbor
and modified base controllers:
nopcommerce\Presentation\Nop.Web\Controllers\BaseNopController.cs
public class BaseNopController : Controller
{
protected override void Initialize(RequestContext requestContext)
{
//Source: https://gist.github.com/1158264
base.Initialize(new RequestContext(new AppHarborHttpContextWrapper(System.Web.HttpContext.Current),
requestContext.RouteData));
}
//Same file from here downwards...
}
nopcommerce\Presentation\Nop.Web.Admin\Controllers\BaseNopController.cs
public class BaseNopController : Controller
{
protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
//set work context to admin mode
EngineContext.Current.Resolve<IWorkContext>().IsAdmin = true;
//Source: https://gist.github.com/1158264
base.Initialize(new RequestContext(new AppHarborHttpContextWrapper(System.Web.HttpContext.Current), requestContext.RouteData));
//base.Initialize(requestContext);
}
//Same file from here downwards...
}
Enable the Directory Browsing feature in IIS Express
Note This method is for the web developers who experience the issue when they use IIS Express.
To do this, follow these steps:
Open a command prompt, and then go to the IIS Express folder on your computer. For example, go to the following folder in a command prompt:
C:\Program Files\IIS Express
Type the following command, and then press Enter:
appcmd set config /section:directoryBrowse /enabled:true
refrence :https://support.microsoft.com/en-us/kb/942062