i´m looking for an fixing of this error:
System.NotSupportedException: "Assembly.LoadFile is not supported in AppX."
I´ve got an Xamarin-Project and i ´m trying to create an instance of a type of mine. all in all it looks like this:
var assembly = Assembly.LoadFile("MicroChatsTest.dll");
var type = typeof(IUpdate);
var mytypes = assembly.GetTypes().Where(p => type.IsAssignableFrom(p)).FirstOrDefault();
if (mytypes == null) throw new Exception("E1234");
var whatever = Activator.CreateInstance(mytypes);
the error comes in the first line, because AppX/Xmarin doesn´t support the Assembly.LoadFile, is there any possibillity to fix this? thanks a lot.
Unfortunately, you cannot load non-AOT compiled assemblies in Xamarin:
https://forums.xamarin.com/discussion/2294/assembly-load-is-it-possible
Related
I've tried every solution on adding an embed on a web hook but none work on my case or am I missing something?
I'm using Discord.Net v2.2.0
here's part of my code
var DCW = new DiscordWebhookClient(DCWebhook)
using (var client = DCW)
{
var eb = new EmbedBuilder();
eb.WithDescription("some text")
.Build();
await client.SendFileAsync(filePath: "file.txt", text: null, embeds: eb);
}
this code shows an error
cannot convert from 'Discord.Embed' to
System.Collections.Generic.IEnumerable<Discord.Embed>
I tried this code and had the error fixed
await client.SendFileAsync(filePath: "file.txt", text: null, embeds: (IEnumerable<Embed>)eb);
I built and ran the .exe file and an error occured on console
Unhandled Exception: System.InvalidCastException: Unable to cast
object of type 'Discord.EmbedBuilder' to type
System.Collections.Generic.IEnumerable 1[Discord.Embed].
references:
Send a Discord Embed via Webhook C#
Discord.net bot Embed Message
ModifyAsync Not Working
https://discord.foxbot.me/docs/api/Discord.EmbedBuilder.html
I know most solutions above work but not in my case.
I would really appreciate examples on how to solve this. thanks!
So from what I can see is, that you are trying to pass IEnumerable<Embed> to SendFileAsync. The thing is, that you can not cast EmbedBuilder to IEnumerable<Embed>. You need to pass it an IEnumerable<Embed> which you can get with something like an array (Embed[]).
// This creates the Embed builder
var eb = new EmbedBuilder();
eb.AddField("RandomField", "Hello, my name is random Field");
// Here you make an array with 1 entry, which is the embed ( from EmbedBuilder.Build() )
Embed[] embedArray = new Embed[] { eb.Build() };
// Now you pass it into the method like this: 'embeds: embedArray'
await DCW.SendFileAsync(filePath: "C:\RandomFile.txt", text: "Embed", embeds: embedArray);
public ISearchResponse<object> GetById(string id) {
var uri = new Uri("<myendpoint>");
var settings = new ConnectionSettings(uri).DefaultIndex("useraction-*").PrettyJson().DisableDirectStreaming(); //or try _all
var client = new ElasticClient(settings);
var search = new SearchRequest<object>
{
Query = new TermQuery
{
Field = "field",
Value = "example"
}
};
var response = client.Search<object>(search);
return response;
}
I'm having trouble getting NEST to work. When I try to call the query defined above, I get the following error:
System.Exception: If you use a custom contract resolver be sure to subclass from ElasticResolver
at Nest.JsonExtensions.GetConnectionSettings(JsonSerializer serializer) in C:\Users\russ\source\elasticsearch-net-master\src\Nest\CommonAbstractions\Extensions\JsonExtensions.cs
I've searched the internet for mention of this and can't seem to find anything other than the source code. I've pretty much followed the documentation exactly so I don't know what to change.
Does anyone out there know what this error is trying to tell me? I feel like it's an error behind the scenes that I don't have control over.
I'm happy to answer additional questions if people need more info.
Thanks.
Also I don't know where that path is coming from in the exception because I have no user "russ"
When I try to add a reference to an IronPython engine instance, the reference get's added to the references as expected. If I create another instance of the engine, the AddReference executes without an error, but the reference is not added to the references and import statements fail with "no module named ...".
var engine = Python.CreateEngine();
dynamic clr = engine.Runtime.GetClrModule();
clr.AddReference("IronPython.StdLib");
var references = (IEnumerable<Assembly>)clr.References;
Debug.Assert(references.Any(asm => asm.FullName.StartsWith("IronPython.StdLib"))); // ok
var source = "import pydoc\npydoc.plain(pydoc.render_doc(str))";
var result = engine.Execute<string>(source);
Debug.Assert(result.StartsWith("Python Library Documentation")); // ok
var engine2 = Python.CreateEngine();
dynamic clr2 = engine2.Runtime.GetClrModule();
clr2.AddReference("IronPython.StdLib");
var references2 = (IEnumerable<Assembly>)clr.References;
Debug.Assert(references2.Any(asm => asm.FullName.StartsWith("IronPython.StdLib"))); // fails
result = engine.Execute<string>(source); // throws ImportException "no module named pydoc"
Debug.Assert(result.StartsWith("Python Library Documentation"));
I tried with the binary release of IronPython 2.7.5 (installed to GAC) and C# 4.5, IronPython.StdLib is a precompiled DLL of the Python standard lib with pyc.
I also tried with self compiled IronPython 2.7.5 and 2.7.6 from github, but there the first engine.execute already fails with "no module named pydoc" although the reference gets added.
Am I doing something wrong or is it just a bug?
A colleague found out the reason for the failure. I post it here, in case someone else stumbles across this issue.
You need to load the assembly after adding the reference:
var engine = Python.CreateEngine();
dynamic clr = engine.Runtime.GetClrModule();
clr.AddReference("IronPython.StdLib");
// load assembly into engine
var assembly = Assembly.LoadFrom("IronPython.StdLib.dll");
engine.Runtime.LoadAssembly(assembly);
var references = (IEnumerable<Assembly>)clr.References;
Debug.Assert(references.Any(asm => asm.FullName.StartsWith("IronPython.StdLib"))); // ok
var source = "import pydoc\npydoc.plain(pydoc.render_doc(str))";
var result = engine.Execute<string>(source);
Debug.Assert(result.StartsWith("Python Library Documentation")); // ok
var engine2 = Python.CreateEngine();
dynamic clr2 = engine2.Runtime.GetClrModule();
clr2.AddReference("IronPython.StdLib");
// load assembly into engine2
engine2.Runtime.LoadAssembly(assembly);
var references2 = (IEnumerable<Assembly>)clr.References;
Debug.Assert(references2.Any(asm => asm.FullName.StartsWith("IronPython.StdLib"))); // does not fail
result = engine.Execute<string>(source); // does not throw any more
Debug.Assert(result.StartsWith("Python Library Documentation"));
I have attempted to access an existing custom DbContext from my solution, using LinqPad 5, and use that test\develop queries and code. (I had achieved the same 2 years ago in a similar project)
I am able to create the connection, and it tests successfully but when I try to access it in a query I consistently receive the following error.
configuration system failed to initialize
inner exception: SerializationException
Type 'EMTPassportDomain.Supermodel.Persistance.EMTPassportDbContext' in assembly 'EMTPassportDomain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable
Due to our use of an in house framework I have to set several things up but this is what a query looks like (at least based on my earlier successful attempt with a similar project)
void Main()
{
var serializerSettings = GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings;
var contractResolver = (DefaultContractResolver)serializerSettings.ContractResolver;
contractResolver.IgnoreSerializableAttribute = true;
SupermodelInitialization.Init<EMTPassportDbContext>(new CustomRepoFactory(), webApiAuthFilter: new EMTPassportBasicHttpAuthenticateAttribue());
// InitializerManager.InitPerConfig(new List<IDatabaseInitializer<EMTPassportDbContext>>
// {
// new EMTPassportCreateDatabaseIfNotExists(),
// new EMTPassportDropCreateDatabaseIfModelChanges(),
// new EMTPassportDropCreateDatabaseAlways()
// });
using (new EMTPassportUnitOfWork(ReadOnly.Yes)) //EMTPassportUnitOfWorkIfNoAmbientContext
{
var userRepo = (EMTUserRepo)RepoFactory.Create<EMTUser>();
var test = userRepo.Items;//.Where(u => u.GovEmail == GovEmail && u.Id != Id);
test.Take(1).ToList().Dump();
};
}
I've included most names spaces, copied the dll.config file over into LinqPad.query.config I'm just not sure how to proceed....
I did get this working a couple of years ago after some futsing but I just don't know how to move forward and I miss my LinqPad.
Sorry if this isn't clear, this is my first stackoverflow question ever...
and thanks in advance.
Hello I have been having issues with MonoGame when building I get the glbind... error in the opengl32.dll so I was suggested to find my GUID and it sounds like a simple task but i have looked in the project folder files and cant find it I found one which is
<ProjectGuid>{325BCA73-8459-49AF-9C31-D4A268BF8A1A}</ProjectGuid>
but im looking for one like this
<ProjectTypeGuids>{9B831FEF-F496-498F-9FE8-180DA5CB4258};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
here is a image of my file folder and the main "collisions".csproj file where I found the one GUID. I have done some research but i cant seem to find an answer as to where to look.
HERE
More accuretly im looking for the Projecttypeguids so I can delete one of them to see if that solves my problem as suggested here....I recognized what i worded at the top is kind of vague sorry
Here
The first example you gave is the GUID of your project. Hence ProjectGuid.
The second is a list of the GUIDs of the project types of your project. Hence ProjectTypeGuids.
If you are looking for the GUID of your project, the first example is giving you the correct answer.
The screenshot you linked to shows a project that does not have any type GUIDs listed. If present, the value is mostly used by development tools (e.g. VS uses it to figure out what items to include in the context menus for adding new items.) If there is no project type GUID your project will still "work" for the most part, but you will likely encounter odd behavior in your IDE of choice.
The project type GUID values in your question are correct for a project that is a C# application that uses the MonoGame plugin. If your project file is missing that tag, just add it yourself with whichever GUIDs you want your project to have.
(The list of well-known GUIDs can be found here, though the MonoGame one I had to look up on Google.)
First you didn't mentioned what you're using winforms or wpf.
OK whatever.The ProjectTypeGuids is not supported in winforms you can find them if you're using wpf.
If you're using wpf you can use this code:
public string GetProjectTypeGuids(EnvDTE.Project proj)
{
string projectTypeGuids = "";
object service = null;
Microsoft.VisualStudio.Shell.Interop.IVsSolution solution = null;
Microsoft.VisualStudio.Shell.Interop.IVsHierarchy hierarchy = null;
Microsoft.VisualStudio.Shell.Interop.IVsAggregatableProject aggregatableProject = null;
int result = 0;
service = GetService(proj.DTE, typeof(Microsoft.VisualStudio.Shell.Interop.IVsSolution));
solution = (Microsoft.VisualStudio.Shell.Interop.IVsSolution)service;
result = solution.GetProjectOfUniqueName(proj.UniqueName, hierarchy);
if (result == 0)
{
aggregatableProject = (Microsoft.VisualStudio.Shell.Interop.IVsAggregatableProject) hierarchy;
result = aggregatableProject.GetAggregateProjectTypeGuids(projectTypeGuids);
}
return projectTypeGuids;
}
public object GetService(object serviceProvider, System.Type type)
{
return GetService(serviceProvider, type.GUID);
}
public object GetService(object serviceProviderObject, System.Guid guid)
{
object service = null;
Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider = null;
IntPtr serviceIntPtr;
int hr = 0;
Guid SIDGuid;
Guid IIDGuid;
SIDGuid = guid;
IIDGuid = SIDGuid;
serviceProvider = (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)serviceProviderObject;
hr = serviceProvider.QueryService(SIDGuid, IIDGuid, serviceIntPtr);
if (hr != 0)
{
System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(hr);
}
else if (!serviceIntPtr.Equals(IntPtr.Zero))
{
service = System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(serviceIntPtr);
System.Runtime.InteropServices.Marshal.Release(serviceIntPtr);
}
return service;
}
it's from here