SharpDX.DXGI - DXGI_ERROR_INVALID_CALL - exception

I've searched for the solution a lot, but i can't find it.
Here is my code:
namespace MySharpDXGame
{
public class Game
{
public static void Main()
{
Game game = new Game();
game.InitializeGraphics();
RenderLoop.Run(game.MainForm, game.RenderCallback);
}
private RenderForm MainForm;
private const int Width = 1280;
private const int Height = 720;
private D11.Device device;
private D11.DeviceContext context;
private SwapChain chain;
private D11.RenderTargetView rendtargview;
public Game()
{
MainForm = new RenderForm("Simple Render")
{
ClientSize = new System.Drawing.Size(Width, Height),
AllowUserResizing = true
};
}
private void RenderCallback()
{
Draw();
}
public void InitializeGraphics()
{
ModeDescription modesc = new ModeDescription(Width, Height, new Rational(60, 1), Format.R8G8B8A8_UNorm);
SwapChainDescription chaindesk = new SwapChainDescription()
{
ModeDescription = modesc,
SampleDescription = new SampleDescription(1, 0),
Usage = Usage.RenderTargetOutput,
BufferCount = 1,
OutputHandle = MainForm.Handle,
IsWindowed = true
};
D11.Device.CreateWithSwapChain(DriverType.Hardware, D11.DeviceCreationFlags.None, chaindesk, out device, out chain);
context = device.ImmediateContext;
rendtargview = new D11.RenderTargetView(device, chain.GetBackBuffer<D11.Texture2D>(0));
System.Windows.Forms.MessageBox.Show("created!");
}
private void Draw()
{
context.OutputMerger.SetRenderTargets(rendtargview);
context.ClearRenderTargetView(rendtargview, new Scolor(32, 103, 178, 255));
}
}
}
The exception is thrown at line
D11.Device.CreateWithSwapChain(DriverType.Hardware, D11.DeviceCreationFlags.None, chaindesk, out device, out chain);
I've installed DirectX SDK June 2010. My computer runs on Windows 7 SP1. I am doing this project in Visual Studio Community 2017. SharpDX libraries was downloaded from NuGet.
Here is the full log of exception:
SharpDX.SharpDXException: "HRESULT: [0x887A0001], Module: [SharpDX.DXGI], ApiCode: [DXGI_ERROR_INVALID_CALL/InvalidCall], Message: Unknown"

Try to use the Debug DeviceCreationFlags. This should help you to locate the problem. Also i can only recommend the sharpdx tutorials from robydx:
Tutorials

Related

I want to create highchart widget by Eclipse RAP and i follow "RAP/Custom Widgets FAQ",but there is error?

i want to create some highchart widget by Eclipse RAP ,and i follow the official guide like this
handlejs:
var CKEDITOR_BASEPATH = "rwt-resources/";
(function(){
'use strict';
rap.registerTypeHandler( "rap.sunline.HighCharts", {
factory : function( properties ) {
var parent = rap.getObject( properties.parent );
// var element = document.createElement( "div" );
// parent.append( element );
// $(element).html("askldfjaskljdk");
return {};
}
});
}());
widget.java:
public class HightChartComposite extends Composite {
private static final String RESOURCES_PATH = "resources/";
private static final String REGISTER_PATH = "hightcharts/";
private static final String[] RESOURCE_FILES = { "jquery-2.1.0.min.js", "highcharts.js","ChartPaintListener.js" };
private static final String REMOTE_TYPE = "rap.sunline.HightCharts";
private final RemoteObject remoteObject;
private final OperationHandler operationHandler = new AbstractOperationHandler() {
#Override
public void handleSet(JsonObject properties) {
// JsonValue textValue = properties.get("text");
// if (textValue != null) {
// text = textValue.asString();
// }
}
};
public HightChartComposite(Composite parent, int style) {
super(parent, style);
registerResources();
loadJavaScript();
Connection connection = RWT.getUISession().getConnection();
remoteObject = connection.createRemoteObject(REMOTE_TYPE);
remoteObject.setHandler(operationHandler);
remoteObject.set("parent", WidgetUtil.getId(this));
}
private void registerResources() {
ResourceManager resourceManager = RWT.getResourceManager();
boolean isRegistered = resourceManager.isRegistered(REGISTER_PATH + RESOURCE_FILES[0]);
if (!isRegistered) {
try {
for (String fileName : RESOURCE_FILES) {
register(resourceManager, fileName);
}
} catch (IOException ioe) {
throw new IllegalArgumentException("Failed to load resources", ioe);
}
}
}
private void loadJavaScript() {
JavaScriptLoader jsLoader = RWT.getClient().getService(JavaScriptLoader.class);
ResourceManager resourceManager = RWT.getResourceManager();
jsLoader.require(resourceManager.getLocation(REGISTER_PATH + "jquery-2.1.0.min.js"));
jsLoader.require(resourceManager.getLocation(REGISTER_PATH + "highcharts.js"));
jsLoader.require(resourceManager.getLocation(REGISTER_PATH + "ChartPaintListener.js"));
}
private void register(ResourceManager resourceManager, String fileName) throws IOException {
ClassLoader classLoader = HightChartComposite.class.getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream(RESOURCES_PATH + fileName);
try {
resourceManager.register(REGISTER_PATH + fileName, inputStream);
} finally {
inputStream.close();
}
}
// //////////////////
// overwrite methods
#Override
public void setLayout(Layout layout) {
throw new UnsupportedOperationException("Cannot change internal layout of CkEditor");
}
}
the error is occur:
Uncaught Error: Operation "create" on target "r6" of type "null" failed:
No Handler for type rap.sunline.HightCharts
Properties:
parent = w5
and i have a question about this , what differents from extends Canvas and Composite;
You forget to implement setters in your javascript code.
The created object is stored by the framework under its object id. This object has to implement setter methods that match the properties defined in the handler, which will then be called when the server sends a set operation for a given property.

How can I erase specyfic pixels of image in windows phone by finger touching the screen

I'm new to Windows Phone programming, I'm having problems, and I've been looking over the internet for the past two days and found nothing.
I'm writing and app where I've got two images one over the other, and I need to "erase" the top one by finger, a bit like using a rubber, so I can see the picture underneath. I've done drawing in general but it's not what I need right now. I found an example of something similar but it doesn't work on the phone probably because of library differences. Can anyone please help me find something that I can use? Or maybe show anything?
I found something like this, and it would be awesome if I could do something like this in windows phone 8
Note, I'm using Microsoft Visual Studio Express 2012
After few days of work, i managed to get the erasable layer.
//Created by Kamil SokoĊ‚owski on 01.11.14
//Windows Phone 7.1 Build on Microsoft Visual Studio Express 2012 for Windows Phone
public partial class MainPage : PhoneApplicationPage
{
public BitmapImage mainImage;
private WriteableBitmap writeableBitmap;
private bool isRubbing;
private SolidColorBrush brush;
private Point currentPoint;
private Point oldPoint;
private bool touchedFirst;
// Constructor
public MainPage()
{
InitializeComponent();
Canvas mainCanwas = new Canvas();
drawBackgroundLayer(new Uri("main.png", UriKind.RelativeOrAbsolute));
drawImageLayer(new Uri("para.png", UriKind.RelativeOrAbsolute));
touchedFirst = true;
}
public void drawBackgroundLayer(Uri uri)
{
BitmapImage bgi = new BitmapImage();
bgi.UriSource = uri;
BackGroundImage.Source = bgi;
}
public void drawImageLayer(Uri uri)
{
mainImage = new BitmapImage();
mainImage.UriSource = uri;
MyImage.Source = mainImage;
}
private void Tap_leftButtonDown(object sender, System.Windows.Input.MouseEventArgs e)
{
if (touchedFirst)
{
WriteableBitmap wb = new WriteableBitmap(mainImage);
Color color = new Color();
color.A = 0;
color.R = 33;
color.G = 34;
color.B = 255;
brush = new SolidColorBrush();
brush.Color = color;
touchedFirst = false;
writeableBitmap = wb;
}
isRubbing = true;
oldPoint = currentPoint;
currentPoint = e.GetPosition(MyImage);
}
private void Mouse_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
if (isRubbing)
{
oldPoint = currentPoint;
currentPoint = e.GetPosition(MyImage);
for (int i = 0; i < 40; i++)
{
for (int a = 0; a < 40; a++)
{
writeableBitmap.DrawLine((int)currentPoint.X + i, (int)currentPoint.Y + a, (int)oldPoint.X + i, (int)oldPoint.Y + a, brush.Color);
}
}
MyImage.Source = writeableBitmap;
}
}
private void ButtonLetGo(object sender, MouseButtonEventArgs e)
{
isRubbing = false;
MyImage.Source = writeableBitmap;
}
}
}
// To get this to work You need to download the WiritableBitmapEx form NuGet

Windows phone 8 AdMob ReceiveAd not working

I have made unity application, and I have exported it to visual studio so I can add Google AdMob. I just want to show interstitial ad when ad loads. I am using latest Google.dll file ver:6.5.13.0. Here is my code:
//Google AdMob begin
private InterstitialAd interstitialAd;
AdRequest adRequest;
Boolean interstitialApploaded = false;
int test = 0;
//Google AdMob end
// Constructor
public MainPage()
{
var bridge = new UnityBridge();
UnityApp.SetBridge(bridge);
InitializeComponent();
bridge.Control = DrawingSurfaceBackground;
interstitialAd = new InterstitialAd("my interstitial ID");
interstitialAd.ReceivedAd += OnAdReceived;
interstitialAd.FailedToReceiveAd += OnFailedToReceiveAd;
interstitialAd.DismissingOverlay += OnDismissingOverlay;
adRequest = new AdRequest();
adRequest.ForceTesting = true;
interstitialAd.LoadAd(adRequest);
}
//Google AdMob BEGIN
private void OnDismissingOverlay(object sender, AdEventArgs e)
{
Debug.WriteLine("Ad dismissed.");
interstitialAd.LoadAd(adRequest);
}
private void OnFailedToReceiveAd(object sender, AdErrorEventArgs e)
{
Debug.WriteLine("Ad failed to load!!!!");
interstitialApploaded = false;
test = 1;
}
private void OnAdReceived(object sender, AdEventArgs e)
{
Debug.WriteLine("Ad loaded. Have fun!");
interstitialApploaded = true;
test = 2;
interstitialAd.ShowAd();
}
Now, the problem is that I am not getting any of the Debug.Writeline messages. So I guess ReceiveAd is not working.
Any thoughts?
Thank you.
Your code seems to be Right, check your internet connection and Capabilities that are needed for Ad-loading and try after removing adRequest.ForceTesting = true; that is for test Ad Interstitial.
You have to add the advertise through Unity with its advertisers there will be always an exception if you try to change the exported .sln file from Unity

ssisPackage.Execute (false, null, executionParameter) times out

I am trying to execute a package programmatically. The SSIS packages were deployed using the Project deployment model. I used the following as the example:
http://microsoft-ssis.blogspot.com/2013/01/call-ssis-2012-package-within-net.html
// Connection to the database server where the packages are located
SqlConnection ssisConnection = new SqlConnection
(#"Data Source=SSIS_SERVER;Initial Catalog=master;
Integrated Security=SSPI;");
// SSIS server object with connection
IntegrationServices ssisServer = new IntegrationServices(ssisConnection);
// The reference to the package which you want to execute
// (Note: formatted for ease of reading)
PackageInfo ssisPackage = ssisServer
.Catalogs["SSISDB"]
.Folders["DEV_FOLDER"]
.Projects["TestParentChildDeployment"]
.Packages["Child.dtsx"];
// Add execution parameter to override the default asynchronized execution.
//If you leave this out the package is executed asynchronized
//Collection<PackageInfo.ExecutionValueParameterSet> executionParameter
// = new Collection<PackageInfo.ExecutionValueParameterSet>();
var executionParameter = new Collection<PackageInfo
.ExecutionValueParameterSet>();
executionParameter.Add
(new PackageInfo.ExecutionValueParameterSet
{
ObjectType = 50
, ParameterName = "SYNCHRONIZED"
, ParameterValue = 1
}
);
// Get the identifier of the execution to get the log
long executionIdentifier = ssisPackage.Execute (false, null, executionParameter); // Times out here <<<<
Here is the error: Message=Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
It runs successfully once in a while, but more often than not, it fails. Any ideas?
Here is my solution. Instead of calling the package synchronously, call is asynchronously and use a ManualResetEvent in the calling code to block the main thread until the package completes.
namespace Anthony.Staging.Integration.Tests
{
using System;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using Microsoft.SqlServer.Management.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
//Add references via %WINDIR%\assembly\GAC_MSIL\:
/* Microsoft.SqlServer.ConnectionInfo
* Microsoft.SqlServer.Management.InterationServices
* Microsoft.SqlServer.Management.Sdk.Sfc
* Microsoft.SqlServer.Smo
*/
using Microsoft.SqlServer.Management.IntegrationServices;
[TestClass]
public class ConnectionTests
{
private const string connectionString = #"Data Source=Anthony\MSSQL11;Initial Catalog=SSISDB;Integrated Security=SSPI;";
private static SqlConnection connection;
private static ServerConnection conn;
private static IntegrationServices ssis;
private static string catalog = "SSISDB";
private static string folder = "Anthony.Integration";
[TestInitialize]
public void MyTestInitialize()
{
connection = new SqlConnection(connectionString);
ssis = new IntegrationServices(connection);
}
[TestMethod]
public void CanConnect()
{
Assert.IsNotNull(connection);
Assert.IsTrue(connection.State == ConnectionState.Open);
}
[TestMethod]
public void CanGetKnownPackage()
{
try
{
var package = this.GetPackage(catalog, folder, "Anthony.Staging", "_Extract_Full.dtsx");
Assert.IsNotNull(package);
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
}
[TestMethod]
public void CanExecuteKnownPackage()
{
const int MAX_RETRIES = 20;
const int RETRY_INTERVAL_SECONDS = 10;
const int OPERATION_TIMEOUT_MINUTES = 10;
// get the package from the SSISCatalog and start it asynchronously
// because starting it synchronously will time out after 30 seconds.
var package = this.GetPackage(catalog, folder, "Anthony.Staging", "_Extract_Full.dtsx");
var executionIdentifier = package.Execute(false, null);
// block the main thread and kick off a timer immediately which checks execution status for an ssis execution identifier.
var mre = new ManualResetEvent(false);
var statusChecker = new StatusChecker(executionIdentifier, MAX_RETRIES);
var timer = new Timer(statusChecker.CheckStatus, new StatusCheckerState(mre), new TimeSpan(0, 0, 0), new TimeSpan(0, 0, RETRY_INTERVAL_SECONDS));
WaitHandle.WaitAny(new WaitHandle[] { mre }, (int)new TimeSpan(0, OPERATION_TIMEOUT_MINUTES, 0).TotalMilliseconds, false);
mre.Dispose();
timer.Dispose();
// get the results
var execution = ssis.Catalogs.Single(x => x.Name.Equals(catalog)).Executions.Single(x => x.Id.Equals(executionIdentifier));
var errors = execution.Messages.Where(m => m.MessageType == 120).Select(m => m.Message);
var warnings = execution.Messages.Where(m => m.MessageType == 110).Select(m => m.Message);
Assert.AreEqual(0, errors.Count());
Assert.AreEqual(Operation.ServerOperationStatus.Success, execution.Status);
}
class StatusCheckerState
{
public StatusCheckerState(ManualResetEvent waitHandle)
{
this.WaitHandle = waitHandle;
}
public ManualResetEvent WaitHandle { get; private set; }
}
class StatusChecker
{
private readonly long executionIdentifier;
private int invokeCount;
private ManualResetEvent waitHandle;
private readonly int maximumCount;
public StatusChecker(long executionIdentifier, int maxCount)
{
this.executionIdentifier = executionIdentifier;
invokeCount = 0;
maximumCount = maxCount;
}
// This method is called by the timer delegate.
public void CheckStatus(object state)
{
var localState = ((StatusCheckerState)state);
this.waitHandle = localState.WaitHandle;
if (invokeCount > 0)
{
Debug.WriteLine("Retry attempt: {0}", invokeCount);
}
invokeCount++;
if (invokeCount == maximumCount)
{
// Reset the counter and signal Main.
invokeCount = 0;
waitHandle.Set();
}
var execution = new IntegrationServices(connection).Catalogs.Single(x => x.Name.Equals(catalog)).Executions.Single(x => x.Id.Equals(executionIdentifier));
Debug.WriteLine("Status of execution " + executionIdentifier + " is " + execution.Status);
if (execution.Status == Operation.ServerOperationStatus.Success)
{
// Reset the counter and signal Main.
invokeCount = 0;
waitHandle.Set();
}
}
}
[TestCleanup]
public void MyTestCleanup()
{
if(connection.State == ConnectionState.Open)
connection.Close();
ssis = null;
}
private PackageInfo GetPackage(string catalog, string folder, string project, string package)
{
if (ssis.Catalogs.Contains(catalog))
{
var cat = ssis.Catalogs[catalog];
if (cat.Folders.Contains(folder))
{
var fold = cat.Folders[folder];
if (fold.Projects.Contains(project))
{
var proj = fold.Projects[project];
if (proj.Packages.Contains(package))
{
var pkg = proj.Packages[package];
return pkg;
}
}
}
}
throw new Exception("Cannot find package!");
}
}
}
Here is some code to solve the timeout... it's a bit dirty, but works great:
// Get the identifier of the execution to get the log
long executionIdentifier = ssisPackage.Execute(false, null, executionParameter);
/****
* This is a shameful workaround to not having a timeout override
* for PackageInfo.Execute.
****/
ExecutionOperation executionOperation = ssisServer.Catalogs["SSISDB"].Executions[executionIdentifier];
while (!(executionOperation.Completed))
{
executionOperation.Refresh();
System.Threading.Thread.Sleep(5000);
}
Source:
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/7f0967af-fdeb-4040-9c57-2fe14f2291b5/timeout-after-30-seconds-when-executing-package-via-net?forum=sqlintegrationservices

StructureMap DBServiceRegistry and MVC-mini-profiler?

If I use this code in each Repository class then I get SQL profiling to work but I want to move that code from each class into the class where StructureMap handles the DB.
Example of a Repository class:
public DB CreateNewContext()
{
var sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
var profiledConnection = ProfiledDbConnection.Get(sqlConnection);
return DataContextUtils.CreateDataContext<DB>(profiledConnection);
}
public SqlRecipeRepository(DB dataContext)
{
_db = CreateNewContext();
}
Now I want the dataContext variable to be the profiled version and so come from my DBServiceRegistry class.
Here is the DBServiceRegistry class:
public class DBServiceRegistry : Registry
{
public DBServiceRegistry()
{
var sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["GetMeCooking.Data.Properties.Settings.server"].ConnectionString);
var profiledConnection = ProfiledDbConnection.Get(sqlConnection);
For<DB>().HybridHttpOrThreadLocalScoped().Use(() => DataContextUtils.CreateDataContext<DB>(profiledConnection));
//Original method just had this:
//For<DB>().HybridHttpOrThreadLocalScoped().Use(() => new DB());
}
}
This code does not cause any errors but I don't get the SQL profiling, what am I doing wrong?
The comment is correct, by creating the sql connection outwith the For line, you are overriding the scope command.
Far better to encapsulate the whole lot into an anonymous delegate
using System.Configuration;
using System.Data.SqlClient;
using System.Threading.Tasks;
using StructureMap;
using StructureMap.Configuration.DSL;
using Xunit;
public class DBServiceRegistry : Registry
{
private string connString = ConfigurationManager.ConnectionStrings["GetMeCooking.Data.Properties.Settings.server"].ConnectionString;
public DBServiceRegistry()
{
For<DB>().HybridHttpOrThreadLocalScoped().Use(
() =>
{
var sqlConnection = new SqlConnection(connString);
var profiledConnection = new StackExchange.Profiling.Data.ProfiledDbConnection(sqlConnection, MiniProfiler.Current);
return DataContextUtils.CreateDataContext<DB>(profiledConnection);
});
}
}
You can use unit tests to verify that the scope is correct (test syntax is xunit.net)
public class DBRegistryTests : IDisposable
{
private Container container;
public DBRegistryTests()
{
// Arrange (or test setup)
container = new Container(new DBServiceRegistry());
}
[Fact]
public void ConnectionsAreSameInThread()
{
// Create two connections on same thread
var conn1 = container.GetInstance<DB>();
var conn2 = container.GetInstance<DB>();
// Assert should be equal because hybrid thread is scope
// and test executes on same thread
Assert.Equal(conn1, conn2);
// Other assertions that connection is profiled
}
[Fact]
public void ConnectionAreNotSameInDifferentThreads()
{
var conn1 = container.GetInstance<DB>();
// Request second connection from a different thread
// (for < c# 4.0 use Thread instead of task)
var conn2 = new Task<DB>(() => this.container.GetInstance<DB>());
conn2.Start();
conn2.Wait();
// Assert that request from two different threads
// are not the same
Assert.NotEqual(conn1, conn2.Result);
}
public void Dispose()
{
// Test teardown
container.Dispose();
}
}