bandit's picture

.Net 4.0 compatibility

Project:The Open Toolkit library
Version:1.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:confirmed
Description

I'm using VS2010 RC und win7 x64 and newest SVN version of OpenTK. I also have the bug which was already discussed befor. OpenTK.Examples and OpenTK.Compatibility which decline to reference to OpenTK.dll.

MethodAccesException breaks on this line in API.cs
Debug.Print("Initializing threaded X11: {0}.", Functions.XInitThreads().ToString());

It really depends on settings of target framework, cause the following line throws DisplayDevice exception:

        public TestClass()
            : base(640, 480, GraphicsMode.Default, "Test") //this will help us track down bugs
        { }

I already tried different ways of assigning privileges to the project, changing target framework and x86/x64 target architecture. Does anyone already stumbled upon this issues and found a solution?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

#11

Prebuild has a bug that could result in incorrect solution paths and cause conversion to fail in some cases. OpenTK 1.0 rc1 contains a workaround for this issue - worth a try.

Most of the issues seem to stem from the new security model in .Net 4.0. As a temporary workaround, you can try adding:

[assembly: SecurityRules(SecurityRuleSet.Level1)]

to the OpenTK project (e.g. in AssemblyInfo.cs) and see if that allows the code to work.

c2woody's picture

#12

I'm using the current 1.0 branch from the svn repository.

Replacing the existing security rule for OpenTK with [assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)] makes the examples indeed working, thanks.

c2woody's picture

#13

Reading through the issue-posting at MS connect that bandit posted, the problem with the conversion to a full .NET 4.0 project comes from OpenTK originally targetting the v2.0 tools (vs2005 presumably), which vs2010 does not automatically convert. To fix this, the OpenTK build process would have to target v3.5 of the framework tools (and of .NET I guess), which may not be wanted, or a separate vs2010 profile for the building tools (this seems to lack support from the Prebuild side currently, right?).

What's the general idea about targetting .NET versions along with visual studio versions, like should all profiles target v2.0 (the current vs2008 build does that)? I could not get vs2010/rc to compile OpenTK targetting .NET 2.0, anybody succeeded with that?

the Fiddler's picture

#14

Status:open» confirmed

I have installed VS2010 and tested OpenTK with that. It works after applying the correct SecurityRulesAttribute. SVN r2679 now contains this attribute, which is conditionally compiled if "NET40" is #defined.

The first step towards a complete solution would be to add a 4.0 target to Build.exe (I'll post a new issue report for that). For a complete solution we should try to see if it is possible to make OpenTK work with the new Level2 SecurityRuleSet.

the Fiddler's picture

#15

Title:MethodAccessException and sometimes OpenTK.DisplayDevice TypeInitializationException» .Net 4.0 compatibility
protandeous's picture

#16

Was any of this ever truly resolved? I am on old C++ programmer and have used OpenGL for years. I am now stepping into C# for the first time and have successfully used OpenTK for a stand-alone full-window app.

However, I really want to integrate my 3D window with an established C# app with does database queries (which I am trying to visualize). At that point I realized I needed to use a GLControl instead of GameWindow and have tried to follow that tutorial. But I am now facing this compiletime error:

c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3253: The referenced assembly "Microsoft.Data.Services, Version=5.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" could not be resolved because it has a dependency on "System.ServiceModel.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project.
 
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3253: The referenced assembly "Microsoft.Data.Services, Version=5.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" could not be resolved because it has a dependency on "System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project.
 
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3253: The referenced assembly "Microsoft.Data.Services, Version=5.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project.

So I rebuilt the OpenTK project for .NET4, but I still cannot get it to work. This error seems to be fundamentally related to adding any reference to OpenTK to the original C# project at all (and not using GLControl instead of GameWindow)

Help?

winterhell's picture

#17

Have you tried targeting .NET 2.0 ? I know its old but I'm using it and its great with compatibility if you dont mind the lack of contemporary features.

protandeous's picture

#18

Thanks for the suggestion, but I'm trying to integrate my previously working app as a second window within a pre-existing one using .NET40 The fundamental problem I'm having is not seeing the GLControl listed in my toolbox! Should that UserControl be there or should I spawn it some other way? Is this a VS2010 issue?

I browsed to the DLLs and see GLControl on the .NET Framework tab after importing, but there is no control for me to drag to my WPF form. I have tried new-ing one up in code and adding it as a child control but it never shows (and never fires events). I then tried a "Template with Code-Behind" technique but that won't even compile because I think the GLControl wasn't made for that.

I'm new to C# but trying to read as much as I can to rule-out my incompetence. I'm stuck! Any ideas?

protandeous's picture

#19

Success! See here: http://www.opentk.com/node/3344