Using Mono.Cecil
if (MethodDefinition.ReturnType == AssemblyDefinition.MainModule.Import(typeof(string)))
Is failing because the assembly I reading is .net 2 but my program is .net 4. So it is trying to compare string v2 and string v4 so it will never be equal. How can I get the string from v2 without building my program with .net 2?
Your question is similar to this one
In short, you should be able to get the string type with this :
AssemblyDefinition.MainModule.TypeSystem.String
Related
I have a c# app with .net framework 4.7 working. I read that .net Framework will be replaced with .net Core, .net Standard so I wanted to move it to .net core 3.1
Surprisingly, to get emails from exchange online the example that one can find everywhere
"foreach (EmailMessage email in exchange.FindItems(WellKnownFolderName.Inbox, new ItemView(100))"
does not work, returning VS CS1579 error
"foreach statement cannot operate on variables of type 'type1' because 'type2' does not contain a public definition for 'identifier'"
Of course, exchange.FindItems type is "(awaitable) System.Threading.Tasks.Task<FindItemsResults>"
Looking at dozens of examples, I always find the same examples not using Tasks, so I do not find an example to make this works,
is this new return type "Task" correct because of net core ?
how can I implement this new type ?
Thanks
Olivier
When I use float.IsFinite(float f) in a C# shell, I have no problems. However, when I use it in the context of Unity, I get an error alleging that it is not defined:
Here is the relevent code:
public static bool IsFinite(Unit u) => float.IsFinite(u.blocks);
Unit is a struct in which I wrote the above line.
My question is: why does this error appear and how can I fix it?
float.IsFinite exists in .NET 5, .NET Standard 2.1 and .NET Core 2.1. However Unity supports neither of those frameworks, just .NET Standard 2.0. This is why you cannot use the function here.
However it´s easy to create a workaround for the lack of that function:
public static bool IsFinite(Unit u) => !float.IsInfinity(u.blocks)
There´s an angoing discussion at Unitity support forum about .NET 5
I am using Apache ignite version 2.7.5. and using .net core as server and thin client.
Cache configuration with key as string and value as Model class for example Employee.And this model class having properties including dictionary data type fields.
I am performing get and put record into cache from application which having target platform is .net framework.
In my .net core(v2.2.103) client Load() method returning result but in caller application getting the following exception.
{"No matching type found for object [typeId=596790889,
typeName=System.Collections.Generic.NonRandomizedStringEqualityComparer].
This usually indicates that assembly with specified type is not loaded
on a node. When using Apache.Ignite.exe, make sure to load assemblies
with -assembly parameter. Alternatively, set
IgniteConfiguration.PeerAssemblyLoadingEnabled to true."}
Any one can you give suggestion,how to solve this exception.
I think you have mismatch of .Net versions - one uses NonRandomizedStringEqualityComparer as comparer for its dictionaries, which other one does not have this type.
Please see this related .Net core bug: https://github.com/dotnet/corefx/issues/26033
It is possible that Ignite handles such dictionaries incorrectly on its own, but I'm not sure what are steps to reproduce. Right now the recommendation is to make sure you're using exactly the same verison of .Net runtime everywhere.
I want to pass class object to web service which built in .NEt 4.0 structure but i need to call that in .NET 2.0 framework.
So please let me know how can we convert class object into json based string.
I don't want to use json converter which provided by json.net.
I want to use without that DLL.
You can use the JavaScriptSerializer but that is .Net 3.5 on. I'm not aware of anything made before then that is included within the framework.
If your completely unwilling to use a third party DLL I think your going to have to "Roll your own".
Is there a preferred way to identify core .net framework assemblies ? i.e. asm which are part of the framework ?
This is for a an application auto updater which
1) takes in an assembly using ASP.NET upload
2) checks it's assembly references
3) ensures they're available for deployment too
4) they're pulled as needed based on auth/authorization etc. etc
Part #3 is where it'd be good to check if they're part of the core framework
Assemblies have attributes that you can examine with reflection:
object[] attribs = assembly.GetCustomAttributes();
You could take a look at the objects returned by that call in the debugger, and see if any are common across the assemblies you want to categorise.
Edit: And - what a surprise! - Jon Skeet has already posted an answer to a similar-but-not-identical question using this technique. Should work for you as well.
You can check the property Assembly.GlobalAssemblyCache to see if it's in the GAC, but I think that's the closest you can get without parsing Microsoft's name from the assembly company.
Here is a list based on the ECMA standard:
http://en.wikipedia.org/wiki/Base_Class_Library