Hi I have ben trying to load sharepoint assembly during runtime, But i am always getting the error
"Exception thrown: 'System.Reflection.ReflectionTypeLoadException' in mscorlib.dll
"
here i my code snippet
Assembly assembly = Assembly.LoadFile(extension);
Type type = assembly.GetType("Microsoft.SharePoint.Client.File");
var obj = Activator.CreateInstance(type);
Also if i wish to know all the method names then ho would i do it?
Please help!!!
You can get the exact contained types with Assembly.GetExportedTypes().
With Type.GetMethods() you can get all the methods of a type.
Related
I am creating nopCommerce plug-in for image compression using Magick.Net library, I make ImageOptimizer object and when calling LosslessCompress method it gives an error like unable to load dll Magick.NET-Q16-x64.Native.dll or one of its dependencies: The specified module could not be found.
I have found Magick.NET-Q16-x64.Native.dll and when I am trying to add a reference for that it gives an error like reference is invalid or unsupported
var file = new FileInfo(filepath);
var optimizer = new ImageOptimizer();
optimizer.LosslessCompress(file);
I expect no error occurs when LosslessCompress method runs and image is successfully compressed.
I am trying to compile a simple code in C# using Microsoft.CodeAnalysis.CSharp.
The problem is in trying to add the reference to mscorlib.dll.
As the CreateFromAssembly method of the MetadataReference class is deprecated I am trying to use the CreateFromFile method (as suggested):
var mscorlibAssembly = Assembly.Load(new AssemblyName("mscorlib.dll")).ManifestModule.Assembly;
var mscorlibref = MetadataReference.CreateFromFile(mscorlibAssembly.Location);
result.Add(mscorlibref);
The Location property of the assembly returns "mscorlib.dll" and not the full path causing the error: System.IO.FileNotFoundException: Could not find file "/mscorlib.dll"
How can I load the correct MSCorLib reference to be able to use CSharpCompilation?
http://pastebin.com/n6G1jTHQ
My code creates a new assembly and module, and then emits a class SWT(within a new assembly) that should be exactly the same as SWTTFieldsclass.
Line 137, saves the assembly/module into a .dll, myAsmBuilder.Save("ModuleOne.dll"); throws the exception:
An unhandled exception of type 'System.NotSupportedException' occurred
in mscorlib.dll Additional information: Type 'SWT' was not completed.
Why I am getting this error ? What is missing in my emitted class ?
You have to call the TypeBuilder.CreateType Method for each TypeBuilder before saving the File.
As you can tell by the title, I'm trying to load a plugin into a new AppDomain. I want to call the constructor when that happens.
Normally this wouldn't be a problem but the constructor takes a parameter. In this case, it's a class that uses a bunch of other classes too.
AppDomain domain = AppDomain.CreateDomain("Plugins");
object inst = Activator.CreateInstance(domain, "ircplugin", "eIRCBot.Plugin", false, BindingFlags.Default, null, new object[] { ircinstance }, null, null);
If I do this, it gives me the following exception:
An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll
Additional information: Type 'IRCLib.IrcInstance' in assembly 'IRCLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
How do I solve this? I can't go and make all of the classes serializable because it also uses some of .net's classes like tcpclient. Am I missing something here?
I have a project named "Test.LiveModel" (Test.LiveModel.dll) and its version is 8.0.7.0 in my solution which contains 25 projects. I can see the information of Test.LiveModel in AssemblyInfo.cs. I have two category of objects named 'base class category' and 'user-defined class category' which are displaying in my application UI. I am displaying this through a property which is of class Type
Now I am considering one base class category object named "Server" and one user-defined class category object RoundedTree. When I set value as "Server" in Property in Grid after saving it when I restart my application I can see the saved value, but for "RoundedTree" which is not happening due to type becomes null. So I did a thorough analysis and came to know that issue is in ToType() method shown below
This is ToType() metho
For base class Server xmlSerializableType.Name, I am getting as Test.LiveModel.Server and AssemblyName I am getting as Test.LiveModel, Version=8.0.7.0, Culture=neutral, PublicKeyToken=23bd062a94e26d58 and type I am getting by using Type.GetType as type = {Name = "Server" FullName = "Test.LiveModel.Server"}
But for user defined class xmlSerializableType.Name I am getting as _Rounded_Tree. 'type' I am getting as null by using Type.GetType. AssemblyName I am getting as _Rounded_TreeTest-Machine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null, but even assembly.GetType I am getting as null. What is the reason behind it? Why am I getting assembly version 0.0.0.0? I mean full assembly _Rounded_TreeTest-Machine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null.
This is the method CreateType() which will create assembly and type as myTypeBuilder for userdefined class:
public Type CreateType()
{
// Create the assembly name by appending the machine name to the typename.
myAsmName.Name = this.TypeName + Environment.MachineName;
// Define assembly that can be executed but not saved
this.UserClassAssemblyBuilder = myDomain.DefineDynamicAssembly(myAsmName, AssemblyBuilderAccess.Run);
// Create dynamic module with symbol information
this.UserClassModuleBuilder = this.UserClassAssemblyBuilder.DefineDynamicModule("userdefinedmodule", true);
So here is my question: if real Dll has some version number, and user defined class assembly has version 0.0.0.0, is that the reason why I am getting type as null after using Type.GetType and assembly.GetType method?
Here are some suggestions which may solve the problems.
Define a assembly version
new AssemblyName(this.TypeName + Environment.MachineName)
{
Version = new Version("1.0.0.0")
};
Use full qualified names for the serialization
myObject.GetType().FullName