UnmanagedExports .net Standard 2.0 package in .net 7.0 not loading Runtime - .net-7.0

I am using the UnmanagedExports.Repack https://github.com/kevingosse/UnmanagedExports.Repack in a .net framework project. It is being upgraded to .net 7.0. However, in 7.0 it always returns "Could not load file or assembly 'System.Runtime, Version=7.0.0.0" whenever an application tries to connect to the DLL.
I got it to work if my dll project is also a .net Standard 2.0. However, I need it in a .net 7.0 project.
I pulled the source code for UnmanagedExports.Repack and upgraded to .net 7.0 (had to add AsssemblyInfo.cs as it was missing). Added references to the projects in my soulution and still give the same error, but the exact code works fine if it is a .net Standard project.
Any ideas on how why I get the "Could not load file or assembly 'System.Runtime, Version=7.0.0.0" error.
*To Reproduce
create a .net standard 2.0 library project and add the DllExample and nuget package UnmanagedExports.Repack. (Make sure the project is set to X64 not any)
add a console application project (I used .net 7.0) add the "Calling Code" classes below.
Run and you get correct results.
remove the .net standard 2.0 library project
Add a .net 7.0 library project, add the DllExample and nuget package UnmanagedExports.Repack (Make sure the project is set to X64 not any)
run in command line and you get the error.*
Dll Exmple:
using System;
using RGiesecke.DllExport;
using System.Runtime.InteropServices;
namespace NewDLLTest2
{
public class DLLCalls
{
[DllExport("TestGetJSON", CallingConvention = CallingConvention.StdCall)]
static public string TestGetJSON()
{
string ret = "{\"Message\":\"Hello\"}";
return ret;
}
}
}
Calling Code:
NativeMethods.cs
using System;
using System.Runtime.InteropServices;
namespace ConsoleApp1
{
class NativeMethods
{
const string _dllLocation = "NewDLLTest2.dll";
[DllImport(_dllLocation, CallingConvention = CallingConvention.StdCall)]
public static extern string TestGetJSON();
}
}
Program.cs
using System;
using System.IO;
namespace ConsoleApp1
{
class Program
{
[STAThread]
static void Main(string[] args)
{
string ret = NativeMethods.TestGetJSON();
Console.WriteLine(ret);
}
}
}

Related

AddJsonFormatters() missing after migration from .NET Core 2.2 to 3.0

I have a Net Core 2.2 Web Api that I protect with the integration of IdentityServer4. So I started from the tutorial of IDS4 to write the code and there I found the AddJsonFormatters().
I'm triyng to migrate it from .NET Core 2.2 to .NET Core 3.0.
At the moment I have a problem at compile time in the ConfigureServices().
I don't find the AddJsonFormatters() and if I correctly understand, I have to use the AddMvcOptions() to get the same result.
Is this correct? In this case, what is the equivalent configuration?
// .NET Core 2.2
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore()
.AddAuthorization()
.AddJsonFormatters();
// Other code...
}
// .NET Core 3.0
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore()
.AddAuthorization()
// Something like this...
.AddMvcOptions(options =>
{
//options.OutputFormatters.Add(new SomeKindOf_IOutputFormatter());
//options.InputFormatters.Add(new SomeKindOf_IInputFormatter(options));
});
// Other code...
}
You can use Microsoft.AspNetCore.Mvc.NewtonsoftJson NuGet package, and configure it in the Startup.cs:
services.AddMvcCore()
.AddNewtonsoftJson(o =>
{
o.SerializerSettings.Converters.Add(new StringEnumConverter());
o.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
})
I just found out that IdentityServer4 are slowly updating their samples for .NET Core 3.0. Attached is the link to their newer version of the code for the part you are asking about, hope it helps.
https://github.com/IdentityServer/IdentityServer4/blob/master/samples/Quickstarts/1_ClientCredentials/src/Api/Startup.cs

Unable to use costura fody with asp.net

I have problems using costura fody with the latest build and standard small web services ( both asmx and wcf )
To test this. I build a simple asp.net project (hello world). I am using 2 simple class libraries as references.
[WebMethod] public string HelloWorld()
{
Class1 c1 = new Class1();
Class2 c2 = new Class2();
return c1.GetData() + c2.GetData();
}
This is working fine without Costura/Fody
Adding latest version of Costura/Fody from github:
When I run it now I get compile errors saying DotNetCompilerPlatform missing :
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
The DotNetCompilerPlatform dll is part of the embedded dll's.
Why is this ?
Trying the same with a WCF service I encounter a simular problem.
Regards

Nancy Empty Self Hosting - System.AccessViolationException

I am using Visual Studio 2015 Community Edition in Administrator mode. I installed SideWaffle Template Pack v1.21.400. I created a new Nancy Empty Self Host Project. The below is the Source Code:
using System;
using Nancy.Hosting.Self;
namespace NancyEmptySelfHost
{
class Program
{
static void Main(string[] args)
{
var uri =
new Uri("http://localhost:3579");
using (var host = new NancyHost(uri))
{
host.Start();
Console.WriteLine("Your application is running on " + uri);
Console.WriteLine("Press any [Enter] to close the host.");
Console.ReadLine();
}
}
}
}
On execution, I am getting System.AccessViolationException in the line host.Start(); with the below message:
Attempted to read or write protected memory. This is often an
indication that other memory is corrupt.
I get the same exception, when I create Projects with other Nancy Templates. If I create a Console application (without using Nancy template) and refer Nancy dlls, it's working fine. How should this be fixed?

How to build shader effect (.fx) in csproj

I'm trying to build pixel shader in a C# class library.
I have added fx file to the project. Since I can't find any suitable build action I tried to manually edit csproj:
<FxCompile Include="MyEffect.fx">
<ShaderType>Pixel</ShaderType>
</FxCompile>
but when I try to locate the ps file, I get System.IO.IOException: Cannot locate resource 'MyEffect.ps'
here is the code that throws error:
public class MyEffect : ShaderEffect
{
public MyEffect(){
this.PixesShader = new Uri("pack://application:,,,/WpfControlLibrary1;component/MyEffect.ps");
}
}
How to setup my project so that I can locate the compiled shader?
All the tutorials I have found are for C++ projects or deals with old tools like custom build task, but I think that is not required since VS2012.
EDIT:
Visual Studio does compile .fx files only in C++ projects. In C# projects it does not work. It is mentioneded here: http://blogs.msdn.com/b/chuckw/archive/2012/05/07/hlsl-fxc-and-d3dcompile.aspx
You can set a Postbuild option to compile your fx files with fxc:
fxc /O0 /Fc /Zi /T fx_5_0 /Fo myShader.fxo myShader.fx
But I compile all my shaders at runtime when developing.
I'm not sure what C# library you are using but you can do this in both SharpDX and SlimDX:
ShaderBytecode.CompileFromFile(effectFile, "fx_5_0", ShaderFlags.None, EffectFlags.None);

activate task view programmatically windows 10

Is there a way to activate task view programmatically in windows 10?
There was a way to activate Flip3D programmatically in win7 using the following copied from VBScript SendKeys CTRL+LWIN+TAB?
CreateObject("WScript.Shell").Run "rundll32 DwmApi #105"
I just want to make a .vbs or .bat file that activates windows 10 Task View.
OK Found a way to do it with C#
Install Visual studio
Install NuGet http://docs.nuget.org/consume/installing-nuget
File > New Project
Name it taskview
Visual C# > Console application
File > Save All
Tools > NuGet Package Manager > Package Manager Console
Type "Install-Package InputSimulator" in Package Manager console
window
Paste Following text in taskview.cs window
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WindowsInput.Native;// Importante
namespace taskview
{
class Program
{
static void Main(string[] args)
{
WindowsInput.InputSimulator kb = new WindowsInput.InputSimulator();
kb.Keyboard.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.TAB);
Console.Read();// Keep console window open
}
}
}
Change Dropdown with Debug in it to Release
Build > Build Solution
Build > Build taskview
It should be in: My Documents\Visual Studio 2015\Projects\taskview\taskview\bin\Release\taskview.exe
You can use the function having the ordinal 105 within dwmapi.dll. You can use rundll32.exe to execute that function. This is how the command line looks like:
start rundll32.exe dwmapi.dll #105
It will trigger the Flip 3D functionality on Windows Vista and later, if Aero is enabled.

Resources