I got a runtime error in PodioApi C# System.IO.FileNotFoundException - c#

Code
using System;
using PodioAPI;
namespace TestPodio
{
class Program
{
static void Main(string[] args)
{
string clientId = clientIdValue;
string clientSecret = clientSecretValue;
int appId = appIdValue;
string appSecret = appSecretValue;
var podio = new Podio(clientId, clientSecret);
podio.AuthenticateWithApp(appId, appSecret);
var items = podio.ItemService.FilterItems(appId);
Console.WriteLine("My app has " + items.Total + " items");
//Console.WriteLine("Hello World!");
}
}
}
clientIdValue and clientSecretValue are the client id and client secret i'm using
appIdValue and appSecretValueare the respective app id and its secret
Runtime error:
System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'System.Security.Permissions, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Den angivne fil blev ikke fundet.
Source=Newtonsoft.Json
StackTrace:
at Newtonsoft.Json.Serialization.JsonTypeReflector.get_DynamicCodeGeneration()
at Newtonsoft.Json.Serialization.JsonTypeReflector.get_ReflectionDelegateFactory()
at Newtonsoft.Json.Serialization.DefaultContractResolver.GetDefaultCreator(Type createdType)
at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract(JsonContract contract)
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType)
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonConverter[] converters)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at PodioAPI.Podio.Request[T](RequestMethod requestMethod, String url, Object requestData, Object options)
at System.Dynamic.UpdateDelegates.UpdateAndExecute5[T0,T1,T2,T3,T4,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
at PodioAPI.Podio.Post[T](String url, Object requestData, Object options)
at PodioAPI.Podio.Authenticate(String grantType, Dictionary`2 attributes)
at PodioAPI.Podio.AuthenticateWithApp(Int32 appId, String appToken)
at TestPodio.Program.Main(String[] args) in C:\Users\HHM\Documents\Visual Studio 2017\Projects\TestPodio\TestPodio\Program.cs:line 16
Error list:
Severity Code Description Project File Line Suppression State
Warning NU1701 Package 'Newtonsoft.Json 5.0.8' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.1'. This package may not be fully compatible with your project. TestPodio C:\Users\HHM\Documents\Visual Studio 2017\Projects\TestPodio\TestPodio\TestPodio.csproj 1
Warning NU1701 Package 'Podio 1.5.9' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.1'. This package may not be fully compatible with your project. TestPodio C:\Users\HHM\Documents\Visual Studio 2017\Projects\TestPodio\TestPodio\TestPodio.csproj 1
How do I solve these errors?

The problem is you've created a dotnet core project, but podio is a dotnet framework project. Try recreating your project as a dotnet framework project instead. Instead of Console App (.NET Core) choose Console App (.NET Framework) when you create new project.

Related

Failed to load plugin dependency using AssemblyLoadContext in .NET Core 3.0

I have a plugin with failing dependencies though I tried to follow as much MS recommendation on .NET Core 3.0. Been trying to figure out whats the problem for 2 days already :/. Appreciate an input or where to look. Thanks!
Details:
Entry point is a CLI app published by .NET Core 3.0 self-contained app
//publishes as EXE file
dotnet publish -c release -r win-x64 /p:publishsinglefile=true /p:publishtrimmed=true
Testing on Win-x64 and Linux-x64
.NET Core 3.0 assemblies
Plugin DLLs are published with this command
//publishes as DLL files
dotnet publish -c release -r linux-x64 /p:publishtrimmed=true -o ./app
The logs shows that file is there, it exists but the dependency resolver failed to load it and throws a FileNotFoundException. Strange.
C:\play\yuniql\yuniql-cli\bin\release\netcoreapp3.0\win-x64\publish>yuniql.exe run --plugins-path C:\temp\aztools\yuniql\0.0.0\x64\.plugins -p C:\play\yuniql\yuniql-plugins\postgresql\samples -c "Host=localhost;Port=5432;Username=xxx;Password=xxx;Database=yuniqldb" --platform postgresql -a 1 --debug
...
DBG platformLowerCased: postgresql
DBG pluginsPathParameter: C:\temp\aztools\yuniql\0.0.0\x64\.plugins
DBG defaultAssemblyBasePath: C:\temp\aztools\yuniql\0.0.0\x64\.plugins\postgresql
...
DBG Found plugin dir: C:\temp\aztools\yuniql\0.0.0\x64\.plugins\postgresql
DBG Found plugin file: C:\temp\aztools\yuniql\0.0.0\x64\.plugins\postgresql\Npgsql.dll. ProductVersion: 4.1.1, FileVersion: 4.1.1.0
DBG Found plugin file: C:\temp\aztools\yuniql\0.0.0\x64\.plugins\postgresql\Yuniql.Extensibility.dll. ProductVersion: 0.302.0, FileVersion: 0.302.0.0
DBG Found plugin file: C:\temp\aztools\yuniql\0.0.0\x64\.plugins\postgresql\Yuniql.PostgreSql.deps.json. ProductVersion: , FileVersion:
DBG Found plugin file: C:\temp\aztools\yuniql\0.0.0\x64\.plugins\postgresql\Yuniql.PostgreSql.dll. ProductVersion: 0.305.0, FileVersion: 0.305.0.0
DBG Found plugin file: C:\temp\aztools\yuniql\0.0.0\x64\.plugins\postgresql\Yuniql.PostgreSql.pdb. ProductVersion: , FileVersion:
DBG pluginAssemblyFilePath: C:\temp\aztools\yuniql\0.0.0\x64\.plugins\postgresql\Yuniql.PostgreSql.dll
DBG loadedAssembly: Yuniql.PostgreSql, Version=0.305.0.0, Culture=neutral, PublicKeyToken=null
DBG retryResolving: Npgsql, Version=4.1.1.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7
DBG failedAssemblyFileExists: True
DBG attempting to reload Npgsql, Version=4.1.1.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7 via streaming from C:\temp\aztools\yuniql\0.0.0\x64\.plugins\postgresql\Npgsql.dll
ERR Failed to execute run function. Target database will be rolled back to its previous state.
System.IO.FileNotFoundException: Could not load file or assembly 'Npgsql, Version=4.1.1.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7'. The system cannot find the file specified.
File name: 'Npgsql, Version=4.1.1.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7'
at Yuniql.PostgreSql.PostgreSqlDataService.GetConnectionInfo()
at Yuniql.Core.MigrationService.Run(String workingPath, String targetVersion, Boolean autoCreateDatabase, List`1 tokenKeyPairs, Boolean verifyOnly, String delimeter)
at Yuniql.CLI.CommandLineService.RunMigration(RunOption opts)
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Npgsql, Version=4.1.1.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7'. The system cannot find the file specified.
File name: 'Npgsql, Version=4.1.1.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7'
at Yuniql.PostgreSql.PostgreSqlDataService.GetConnectionInfo()
at Yuniql.Core.MigrationService.Run(String workingPath, String targetVersion, Boolean autoCreateDatabase, List`1 tokenKeyPairs, Boolean verifyOnly, String delimeter)
at Yuniql.CLI.CommandLineService.RunMigration(RunOption opts)
at Yuniql.Program.<>c__DisplayClass0_0.<Main>b__1(RunOption opts)
at CommandLine.ParserResultExtensions.MapResult[T1,T2,T3,T4,T5,T6,T7,T8,TResult](ParserResult`1 result, Func`2 parsedFunc1, Func`2 parsedFunc2, Func`2 parsedFunc3, Func`2 parsedFunc4, Func`2 parsedFunc5, Func`2 parsedFunc6, Func`2 parsedFunc7, Func`2 parsedFunc8, Func`2 notParsedFunc)
at Yuniql.Program.Main(String[] args)
C:\play\yuniql\yuniql-cli\bin\release\netcoreapp3.0\win-x64\publish>
PluginAssemblyLoadContext
https://github.com/rdagumampan/yuniql/blob/master/yuniql-core/PluginAssemblyLoadContext.cs
class PluginAssemblyLoadContext : AssemblyLoadContext
{
private AssemblyDependencyResolver _resolver;
public PluginAssemblyLoadContext(string pluginPath) : base(isCollectible: true)
{
_resolver = new AssemblyDependencyResolver(pluginPath);
}
protected override Assembly Load(AssemblyName name)
{
string assemblyPath = _resolver.ResolveAssemblyToPath(name);
if (assemblyPath != null)
{
Console.WriteLine($"Loading assembly {assemblyPath} into the HostAssemblyLoadContext");
return LoadFromAssemblyPath(assemblyPath);
}
return null;
}
}
Load plugin from /app/.plugins/PostgreSql
https://github.com/rdagumampan/yuniql/blob/master/yuniql-core/MigrationServiceFactory.cs
// create the unloadable HostAssemblyLoadContext
var pluginAssemblyLoadContext = new PluginAssemblyLoadContext(pluginAssemblyBasePath);
//the plugin assembly into the HostAssemblyLoadContext.
//the assemblyPath must be an absolute path.
var assembly = pluginAssemblyLoadContext.LoadFromAssemblyPath(pluginAssemblyFilePath);
pluginAssemblyLoadContext.Assemblies
.ToList()
.ForEach(a =>
{
_traceService.Debug($"loadedAssembly: {a.FullName}");
});
pluginAssemblyLoadContext.Resolving += AssemblyContext_Resolving;
pluginAssemblyLoadContext.Unloading += AssemblyContext_Unloading;
var sqlDataService = assembly.GetTypes()
.Where(t => t.Name.ToLower().Contains($"{platformLowerCased.ToLower()}dataservice"))
.Select(t => Activator.CreateInstance(t, _traceService))
.Cast<IDataService>()
.First();
var bulkImportService = assembly.GetTypes()
.Where(t => t.Name.ToLower().Contains($"{platformLowerCased.ToLower()}bulkimportservice"))
.Select(t => Activator.CreateInstance(t, _traceService))
.Cast<IBulkImportService>()
.First();
var tokenReplacementService = new TokenReplacementService(_traceService);
var migrationService = new MigrationService(sqlDataService, bulkImportService, tokenReplacementService, directoryService, fileService, _traceService);
return migrationService;
Attempt to force resolve
private System.Reflection.Assembly AssemblyContext_Resolving(System.Runtime.Loader.AssemblyLoadContext assemblyContext, System.Reflection.AssemblyName failedAssembly)
{
var pluginAssemblyLoadContext = assemblyContext as PluginAssemblyLoadContext;
_traceService.Debug($"retryResolving: {failedAssembly.FullName}");
var assemblyFilePath = Path.Combine(pluginAssemblyLoadContext.PluginPath, failedAssembly.Name + ".dll");
_traceService.Debug($"failedAssemblyFileExists: {File.Exists(assemblyFilePath)}");
using (var file = File.Open(assemblyFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
_traceService.Debug($"attempting to reload {failedAssembly.FullName} via streaming from {assemblyFilePath}");
pluginAssemblyLoadContext.LoadFromStream(file);
}
//assemblyContext.LoadFromAssemblyPath(assemblyFilePath);
//assemblyContext.LoadFromAssemblyName(new System.Reflection.AssemblyName(failedAssembly.Name));
return null;
}
UPDATE 12/26/2019: I thought it was an issue only to linux but I was able to reproduce in Windows. Interestingly, when I run my platform tests which calls the Factory class directly but still the factory uses the AssemblyLoadContext, it works OK!.
The difference, it fails when called by CLI (a .NET Core 3.0 selfcontained EXE app) but OK when called from VSTestRunner (MSTEST).

extent reports not generating reports

I am using extentent reports to generate report but the test excution fails on extent.flush() method. I am using
extentreports 3.1.3
Specflow.xunit 2.2.1
This code use to work previously but not working anymore. Error returned :
System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
Source=RazorEngine
StackTrace:
at RazorEngine.Compilation.CSharp.CSharpDirectCompilerService..ctor(Boolean strictMode, Func1 markupParserFactory)
at RazorEngine.Compilation.DefaultCompilerServiceFactory.CreateCompilerService(Language language)
at RazorEngine.Templating.RazorEngineCore.CreateTemplateType(ITemplateSource razorTemplate, Type modelType)
at RazorEngine.Templating.RazorEngineCore.Compile(ITemplateKey key, Type modelType)
at RazorEngine.Templating.RazorEngineService.CompileAndCacheInternal(ITemplateKey key, Type modelType)
at RazorEngine.Templating.RazorEngineService.GetCompiledTemplate(ITemplateKey key, Type modelType, Boolean compileOnCacheMiss)
at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action1 withWriter)
at AventStack.ExtentReports.Reporter.ExtentHtmlReporter.Flush()
at AventStack.ExtentReports.Model.Report.<>c.b__29_1(IExtentReporter x)
at System.Collections.Generic.List1.ForEach(Action1 action)
at AventStack.ExtentReports.Model.Report.NotifyReporters()
at AventStack.ExtentReports.Model.Report.Flush()
at AventStack.ExtentReports.ExtentReports.Flush()
at XUnitTestProject5.UnitTest1.Test1() in C:\Users\kotar\source\repos\XUnitTestProject5\XUnitTestProject5\UnitTest1.cs:line 25
var HTMLReporter = new ExtentHtmlReporter(#"C:\test\TestReport.html");
HTMLReporter.Configuration().Theme = AventStack.ExtentReports.Reporter.Configuration.Theme.Dark;
var extent = new ExtentReports();
extent.AttachReporter(HTMLReporter);
var featurename = extent.CreateTest<Feature>("login feature");
var scenario= featurename.CreateNode<Scenario>("Login as a user ");
scenario.CreateNode<Given>("user has access to the methos ");
extent.Flush();
If you are using .net core, you have to use "ExtentReports.Core" NuGet package instead of "ExtentReports" and initialize your extent object like this :
public AventStack.ExtentReports.ExtentReports _extent = new
AventStack.ExtentReports.ExtentReports();

How do I compile an XNA project from C# with MSBuild 14?

I have an XNA project I have that compiles perfectly fine in Visual Studio 2015, that makes use of C# 6 features.
Previously, I had some tools coded in C# that would auto-compile the project when it was using C# 5 under VS 2013, but the change to C# 6 has broken things somehow.
To reproduce this I created a new console application, referenced Microsoft.Build, Microsoft.Build.Framework, and Microsoft.Build.Utilities.Core assemblies from C:\Program Files (x86)\MSBuild\14.0\Bin.
I then created my C# compiler project with the following code:
namespace CompileXna
{
class Program
{
static void Main(string[] args)
{
const string solutionPath = #"D:\Code\My Projects\FrbTest\FrbTest.sln";
var properties = new Dictionary<string, string>()
{
{"Configuration", "Debug"},
{"Platform", "x86" }
};
var parameters = new BuildParameters
{
Loggers = new ILogger[] {new BuildLogger()}
};
var request = new BuildRequestData(solutionPath, properties, null, new string[] {"Build"}, null);
var manager = BuildManager.DefaultBuildManager.Build(parameters, request);
Console.WriteLine("Done");
Console.ReadLine();
}
}
class BuildLogger : Logger
{
public override void Initialize(IEventSource eventSource)
{
eventSource.ErrorRaised += (sender, args) =>
Console.WriteLine($"Error: File {args.File} line {args.LineNumber} message {args.Message}");
eventSource.WarningRaised += (sender, args) =>
Console.WriteLine($"Warning: File {args.File} line {args.LineNumber} message {args.Message}");
}
}
}
Unfortunately, when this runs I get the following error:
Error: File C:\Program Files (x86)\MSBuild\Microsoft\XNA Game Studio\v4.0\Microsoft.Xna.GameStudio.ContentPipeline.targets line 78 message The "BuildContent" task could not be instantiated from the assembly "Microsoft.Xna.Framework.Content.Pipeline, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553". Please verify the task assembly has been built using the same version of the Microsoft.Build.Framework assembly as the one installed on your computer and that your host application is not missing a binding redirect for Microsoft.Build.Framework. Unable to cast object of type 'Microsoft.Xna.Framework.Content.Pipeline.Tasks.BuildContent' to type 'Microsoft.Build.Framework.ITask'.
I tried looking in the details of the build output in Visual Studio 2015 when it successfully compiles my XNA project, but even with Detailed logging all I could find (seemingly) relevant was:
1>Using "BuildContent" task from assembly "Microsoft.Xna.Framework.Content.Pipeline, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553".
1>Task "BuildContent"
1>Done executing task "BuildContent".
Anyone have any success on this?

IronPython Sandboxing with CAS

I am trying to integrate IronPython into a C# application for scripting purposes. I would also like the scripts to run under a set of security policies that restrict their access to the file system/network/sensitive system resources.
Research indicates that the most popular approach is to use CAS. This works very well and it does not allow the user to use sockets, access the file system, etc. However, when I try to inject variables for the scrip to interact with, I get a security exception every time I access certain parameters. This only happens with variables I define in my assembly. If I use a standard .NET type (like Dictionary) it works just fine.
My Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Security.Policy;
using System.Security.Permissions;
using System.Security;
using System.IO;
using Microsoft.Scripting.Hosting;
using IronPython.Hosting;
using System.Runtime.Remoting;
using System.Net;
namespace python_in_appdomain
{
[Serializable]
public class Whatever
{
public int i;
public Whatever(int i)
{
this.i = i;
}
}
class Program
{
static void Main(string[] args)
{
Remoting();
}
public static void Remoting()
{
AppDomainSetup setup = new AppDomainSetup();
Assembly thisAssembly = Assembly.GetExecutingAssembly();
setup.ApplicationBase = Path.GetDirectoryName(thisAssembly.Location);
AssemblyName name = typeof(Program).Assembly.GetName();
StrongName sn = new StrongName(
new StrongNamePublicKeyBlob(name.GetPublicKey()),
name.Name,
name.Version
);
PermissionSet pset = new PermissionSet(PermissionState.None);
pset.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
pset.AddPermission(new ReflectionPermission(PermissionState.Unrestricted));
setup.PartialTrustVisibleAssemblies = new[] { sn.Name + ", PublicKey=" + sn.PublicKey.ToString() };
AppDomain domain = AppDomain.CreateDomain("Sandbox", AppDomain.CurrentDomain.Evidence, setup, pset, sn);
String script = #"
d.Add('hello', 1)
w.i = 5
";
Whatever w = new Whatever(4);
Dictionary<string, int> d = new Dictionary<string,int>();
ScriptRuntime py = Python.CreateRuntime(domain);
ScriptEngine engine = py.GetEngine("py");
ScriptScope scope = engine.CreateScope();
scope.SetVariable("w", w);
scope.SetVariable("d", d);
int result;
Console.WriteLine(w.i);
d.TryGetValue("hello", out result);
Console.WriteLine(result);
Console.WriteLine("-----");
try
{
engine.Execute(script, scope);
}
catch (Exception exc)
{
Console.WriteLine(exc.ToString());
}
w = scope.GetVariable<Whatever>("w");
d = scope.GetVariable<Dictionary<string,int>>("d");
Console.WriteLine("-----");
Console.WriteLine(w.i);
d.TryGetValue("hello", out result);
Console.WriteLine(result);
}
}
}
Commenting out the "w.i=5" on line 55 causes the program to execute normally under restricted security settings. Setting the PermissionState to Unrestricted on line 47 allows both lines of the script to execute normally. The following is the error message I receive:
System.Security.SecurityException: Request failed.
at System.Runtime.CompilerServices.RuntimeHelpers._CompileMethod(IRuntimeMethodInfo method)
at System.Reflection.Emit.DynamicMethod.CreateDelegate(Type delegateType, Object target)
at System.Dynamic.Utils.TypeExtensions.CreateDelegate(MethodInfo methodInfo, Type delegateType, Object target)
at System.Linq.Expressions.Compiler.LambdaCompiler.CreateDelegate()
at System.Linq.Expressions.Compiler.LambdaCompiler.Compile(LambdaExpression lambda, DebugInfoGenerator debugInfoGenerator)
at System.Linq.Expressions.Expression`1.Compile()
at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T](CallSite`1 site, Object[] args)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at Microsoft.Scripting.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at IronPython.Compiler.PythonScriptCode.Run(Scope scope)
at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)
at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)
at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
at Microsoft.Scripting.Hosting.ScriptEngine.Execute(String expression, ScriptScope scope)
at Microsoft.Scripting.Hosting.ScriptEngine.Execute(String expression, ScriptScope scope)
at python_in_appdomain.Program.Remoting() in C:\Users\dave\Documents\Visual Studio 2010\Projects\IronPythonTest\IronPythonTest\Program.cs:line 7
6
The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.PermissionSet
The demand was for:
<PermissionSet class="System.Security.PermissionSet"
version="1"
Unrestricted="true"/>
The granted set of the failing assembly was:
<PermissionSet class="System.Security.PermissionSet"
version="1">
<IPermission class="System.Security.Permissions.ReflectionPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Unrestricted="true"/>
<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Flags="Execution"/>
</PermissionSet>
The assembly or AppDomain that failed was:
Microsoft.Dynamic, Version=1.1.0.20, Culture=neutral, PublicKeyToken=7f709c5b713576e1
The method that caused the failure was:
Int32 Run(Microsoft.Scripting.Interpreter.InterpretedFrame)
The Zone of the assembly that failed was:
Internet
The Url of the assembly that failed was:
file:///C:/Users/dave/Documents/Visual Studio 2010/Projects/IronPythonTest/IronPythonTest/bin/Debug/Microsoft.Dynamic.DLL
Unhandled Exception: System.Security.SecurityException: Request failed.
at System.Delegate.BindToMethodInfo(Object target, IRuntimeMethodInfo method, RuntimeType methodType, DelegateBindingFlags flags)
at System.Delegate.CreateDelegate(Type type, MethodInfo method, Boolean throwOnBindFailure)
at System.Dynamic.Utils.TypeExtensions.CreateDelegate(MethodInfo methodInfo, Type delegateType)
at System.Runtime.CompilerServices.CallSite`1.MakeUpdateDelegate()
at System.Runtime.CompilerServices.CallSite`1.GetUpdateDelegate(T& addr)
at System.Runtime.CompilerServices.CallSite`1.GetUpdateDelegate()
at System.Runtime.CompilerServices.CallSite`1.Create(CallSiteBinder binder)
at System.Func`2.Invoke(T arg)
at Microsoft.Scripting.Runtime.DynamicOperations.GetOrCreateSite[T](CallSiteBinder siteBinder, Func`2 factory)
at Microsoft.Scripting.Runtime.DynamicOperations.GetOrCreateSite[T1,TResult](CallSiteBinder siteBinder)
at Microsoft.Scripting.Runtime.DynamicOperations.ConvertTo[T](Object obj)
at IronPython.Runtime.PythonContext.ScopeGetVariable[T](Scope scope, String name)
at Microsoft.Scripting.Hosting.ScriptScope.GetVariable[T](String name)
at Microsoft.Scripting.Hosting.ScriptScope.GetVariable[T](String name)
at python_in_appdomain.Program.Remoting() in C:\Users\dave\Documents\Visual Studio 2010\Projects\IronPythonTest\IronPythonTest\Program.cs:line 8
3
at python_in_appdomain.Program.Main(String[] args) in C:\Users\dave\Documents\Visual Studio 2010\Projects\IronPythonTest\IronPythonTest\Program.
cs:line 31
The error is shockingly straight forward. It says that it is expecting to have totally unrestricted access for this kind of action. Is there any way around this? Why does the dictionary work but my variable does not? Is there a way for me to make IronPython treat my variable like the Dictionary? Am I missing something very obvious?
Thank you very much for you help.
Update 12/21/2012
I kept messing around and came up with a solution that worked. Creating the AppDomain like this (with the same permission object) allows everything to work.
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationBase = System.Environment.CurrentDirectory;
AppDomain domain = AppDomain.CreateDomain("IPyEngine", new Evidence(), setup, pset);
I can't say I totally understand why, though I can see that I'm not providing my assembly's Evidence nor am I adding any Assemblies to the trust list. I don't want to mark this as the answer until I know for certain I'm not doing anything monumentally stupid.
This is suspicious:
The Zone of the assembly that failed was:
Internet
The Url of the assembly that failed was:
file:///C:/Users/dave/Documents/Visual Studio 2010/Projects/IronPythonTest/IronPythonTest/bin/Debug/Microsoft.Dynamic.DLL
I wonder if the file has a zone identifier. Can you check the file properties, and Unblock it if necessary?

MonoDevelop Addin for NaCl using 'ProjectServiceExtension'

Hi all i'm trying to make a MonoDevelop addin that I can use to compile out Mono for NaCl projects... but i'm getting a null ref error and can't find enough information to figure out whats going wrong.
The null ref happens when I try to create a project from my Addin in MonoDevelop.
All resources are set to build as 'EmbeddedResource'.
Builder.cs:
using System;
using MonoDevelop.Projects;
using MonoDevelop.Core;
namespace MonoDevelop.MonoNaCl
{
public class Builder : ProjectServiceExtension
{
protected override BuildResult Build (IProgressMonitor monitor, SolutionEntityItem item, ConfigurationSelector configuration)
{
Console.WriteLine("Yahoo Build");
return base.Build (monitor, item, configuration);
}
protected override void Execute (IProgressMonitor monitor, SolutionEntityItem item, ExecutionContext context, ConfigurationSelector configuration)
{
Console.WriteLine("Yahoo Execute");
base.Execute (monitor, item, context, configuration);
}
}
}
MonoDevelop.MonoNaCl.addin.xml:
NOTE: I'm really not clear on the 'Extension's I should use and think the issue is in there.
<Addin namespace = "MonoDevelop"
id = "MonoNaCl"
name = "Mono for NaCl"
author = "Andrew Witte"
copyright = "BSD"
url = "http://www.URL.com"
description = "Support for developing MonoNaCl applications."
category = "NaCl Development"
version = "1.0">
<Dependencies>
<Addin id="Ide" version="3.0" />
<Addin id="Core" version="3.0" />
</Dependencies>
<Extension path = "/MonoDevelop/Ide/ProjectTemplates">
<ProjectTemplate id = "MonoNaClProject" resource = "MonoNaCl.xpt.xml"/>
</Extension>
<Extension path = "/MonoDevelop/ProjectModel/ProjectServiceExtensions">
<Class class = "MonoDevelop.MonoNaCl.Builder"/>
</Extension>
<!--<Extension path = "/MonoDevelop/ProjectModel/MSBuildItemTypes">
<SolutionItem type="MonoDevelop.MonoNaCl.Builder" extension="csproj" guid="{49DFC40D-C27A-4230-A637-8D9669269586}"/>
</Extension>-->
<Extension path="/MonoDevelop/ProjectModel/SerializableClasses">
<DataType class="MonoDevelop.MonoNaCl.Builde" />
</Extension>
</Addin>
MonoNaCl.xpt.xml:
<?xml version="1.0"?>
<Template originator = "Andrew Witte">
<TemplateConfiguration>
<_Name>MonoNaCl Project</_Name>
<_Category>C#/MonoNaCl</_Category>
<LanguageName>C#</LanguageName>
<_Description>Creates a MonoNaCl project.</_Description>
</TemplateConfiguration>
<Combine name = "${ProjectName}" directory = ".">
<Options>
<StartupProject>${ProjectName}</StartupProject>
</Options>
<Project name = "${ProjectName}" directory = "." type = "MonoNaCl">
<Options/>
</Project>
</Combine>
</Template>
And here is the Error after trying to create a project:
System.NullReferenceException: Object reference not set to an instance of an object
at MonoDevelop.Projects.SolutionFolderItemCollection.OnItemAdded (MonoDevelop.Projects.SolutionItem item) [0x0000b] in /Users/builder/data/lanes/monodevelop-mac-3.0.1/6642975f/source/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/SolutionFolderItemCollection.cs:59
at MonoDevelop.Projects.ItemCollection`1[MonoDevelop.Projects.SolutionItem].InsertItem (Int32 index, MonoDevelop.Projects.SolutionItem item) [0x00008] in /Users/builder/data/lanes/monodevelop-mac-3.0.1/6642975f/source/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ItemCollection.cs:39
at System.Collections.ObjectModel.Collection`1[MonoDevelop.Projects.SolutionItem].Add (MonoDevelop.Projects.SolutionItem item) [0x00000] in <filename unknown>:0
at MonoDevelop.Ide.Templates.SolutionDescriptor.CreateEntry (MonoDevelop.Projects.ProjectCreateInformation projectCreateInformation, System.String defaultLanguage) [0x0026c] in /Users/builder/data/lanes/monodevelop-mac-3.0.1/6642975f/source/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/SolutionDescriptor.cs:162
at MonoDevelop.Ide.Templates.ProjectTemplate.CreateWorkspaceItem (MonoDevelop.Projects.ProjectCreateInformation cInfo) [0x00000] in /Users/builder/data/lanes/monodevelop-mac-3.0.1/6642975f/source/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplate.cs:232
at MonoDevelop.Ide.Projects.NewProjectDialog.CreateProject () [0x001ef] in /Users/builder/data/lanes/monodevelop-mac-3.0.1/6642975f/source/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/NewProjectDialog.cs:432
Remove the type="MonoNaCl" attribute definition in the Project element.
You don't have to set the project type, unless you are defining your own Project subclass.

Categories

Resources